final class middag_helper

Middag Helper.

Centralizes Middag framework entry operations (kernel, routing, env, URL helpers). This class exists to:

  • keep the public entrypoint (local_middag\middag) minimal
  • reduce cross-layer coupling to the entrypoint
  • provide a single internal place for bootstrapping and URL helpers

Constants

COMPONENT_NAME

Component name used for cache definitions, logs, and file storage.

DOCS_URL

External resource URL: documentation site.

SITE_URL

External resource URL: main company website.

SUPPORT_URL

External resource URL: support portal.

MIDDAGPLUGINS_OVERVIEW_URL

External resource URL: plugins overview on docs.

Methods

static middag_helper
get_instance()

Return the singleton instance used by the DI container.

static void
init()

Initialize the application kernel.

static void
shutdown()

Shutdown the kernel.

static void
handle()

Handle the current HTTP request and dispatch it to the appropriate controller.

static object
get(string $id)

Retrieve a service from the DI container.

routing()

Access the Route Manager directly.

static moodle_url
url_generator(string $route, array $parameters = [], int $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)

Generate a Moodle URL from a Symfony route name and parameters.

static moodle_url
webhook_url_generator(string $route, array $parameters = [], int $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)

Generate a webhook URL (helper for callbacks).

static void
register_route(string $name, string $path, string $controller_class, string $method, array $requirements = [])

Register a new route manually.

static void
register_routes_from_annotations(string $class_name)

Register routes from PHP 8 Attributes (#[Route]) in a class.

static object
dispatch(object $event)

Dispatch an event or signal through the framework's event dispatcher.

static void
add_filter(string $tag, callable $callback, int $priority = 10, int $args = 1)

Register a synchronous MIDDAG filter hook.

static mixed
apply_filters(string $tag, mixed $value, mixed ...$args)

Apply synchronous MIDDAG filter hooks.

static void
add_action(string $tag, callable $callback, int $priority = 10, int $args = 1)

Register a synchronous MIDDAG action hook.

static void
do_action(string $tag, mixed ...$args)

Execute synchronous MIDDAG action hooks.

static string
get_component_name()

Get the component name.

static string
get_docs_url()

Get the documentation URL.

static string
get_site_url()

Get the main site URL.

static string
get_support_url()

Get the support portal URL.

static string
get_middagplugins_overview_url()

Get the Middag Plugins overview URL.

static bool
is_testing()

Check if running in PHPUnit test environment.

static bool
is_development()

Check if running in development environment.

static bool
is_production()

Check if running in production environment.

Details

at line 74
static middag_helper get_instance()

Return the singleton instance used by the DI container.

Return Value

middag_helper

at line 87
static void init()

Initialize the application kernel.

Idempotent: safe to call multiple times.

Return Value

void

at line 97
static void shutdown()

Shutdown the kernel.

Useful for testing isolation.

Return Value

void

at line 110
static void handle()

Handle the current HTTP request and dispatch it to the appropriate controller.

In practice, this delegates to the router/controller pipeline inside the kernel. Typical call site: entrypoints (index.php, webhook.php, etc.).

Return Value

void

at line 127
static object get(string $id)

Retrieve a service from the DI container.

This is the primary escape hatch for the outside world to interact with your DI-managed services without coupling to the container directly.

Parameters

string $id

Service ID or Class Name

Return Value

object

at line 143
static router_interface routing()

Access the Route Manager directly.

Exposes the router to allow:

  • manual route registration
  • attribute/annotation scanning (before compilation)
  • URL generation through router abstraction

Return Value

router_interface

at line 160
static moodle_url url_generator(string $route, array $parameters = [], int $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)

Generate a Moodle URL from a Symfony route name and parameters.

This method bridges your Symfony-style routing (route name + params) to Moodle's moodle_url, keeping the rest of your codebase free from direct moodle_url construction logic.

Parameters

string $route

The route name

array $parameters

Route parameters

int $reference_type

URL generation type (Absolute/Relative)

Return Value

moodle_url

at line 185
static moodle_url webhook_url_generator(string $route, array $parameters = [], int $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)

Generate a webhook URL (helper for callbacks).

This is a specialized helper that:

  • generates the base route URL (usually pointing to index.php)
  • rewrites it to point to webhook.php
  • returns a moodle_url for consistent handling inside Moodle

Parameters

string $route
array $parameters
int $reference_type

Return Value

moodle_url

Exceptions

moodle_exception

at line 209
static void register_route(string $name, string $path, string $controller_class, string $method, array $requirements = [])

Register a new route manually.

This is useful when you want to define routes procedurally (e.g. in bootstrap), instead of attribute scanning.

Parameters

string $name

Route name (e.g., 'my_route').

string $path

URL path (e.g., '/my/path/{id}').

string $controller_class

FQCN of the controller

string $method

method name

array $requirements

regex requirements for parameters

Return Value

void

at line 233
static void register_routes_from_annotations(string $class_name)

Register routes from PHP 8 Attributes (#[Route]) in a class.

Note: This must be called BEFORE the container is compiled (usually in bootstrap.php).

Why the container constraint matters:

  • In "build" time, ContainerBuilder is mutable, so services/routes can be added.
  • After compilation, the container becomes immutable for performance.

Parameters

string $class_name

the class to scan

Return Value

void

at line 261
static object dispatch(object $event)

Dispatch an event or signal through the framework's event dispatcher.

Parameters

object $event

Return Value

object

at line 269
static void add_filter(string $tag, callable $callback, int $priority = 10, int $args = 1)

Register a synchronous MIDDAG filter hook.

Parameters

string $tag
callable $callback
int $priority
int $args

Return Value

void

at line 277
static mixed apply_filters(string $tag, mixed $value, mixed ...$args)

Apply synchronous MIDDAG filter hooks.

Parameters

string $tag
mixed $value
mixed ...$args

Return Value

mixed

at line 285
static void add_action(string $tag, callable $callback, int $priority = 10, int $args = 1)

Register a synchronous MIDDAG action hook.

Parameters

string $tag
callable $callback
int $priority
int $args

Return Value

void

at line 293
static void do_action(string $tag, mixed ...$args)

Execute synchronous MIDDAG action hooks.

Parameters

string $tag
mixed ...$args

Return Value

void

at line 303
static string get_component_name()

Get the component name.

Return Value

string

at line 313
static string get_docs_url()

Get the documentation URL.

Return Value

string

at line 323
static string get_site_url()

Get the main site URL.

Return Value

string

at line 333
static string get_support_url()

Get the support portal URL.

Return Value

string

at line 343
static string get_middagplugins_overview_url()

Get the Middag Plugins overview URL.

Return Value

string

at line 353
static bool is_testing()

Check if running in PHPUnit test environment.

Return Value

bool

at line 363
static bool is_development()

Check if running in development environment.

Return Value

bool

at line 373
static bool is_production()

Check if running in production environment.

Return Value

bool