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
Tags
Table of Contents
Constants
- COMPONENT_NAME = \local_middag\middag_metadata::COMPONENT_NAME
- Component name used for cache definitions, logs, and file storage.
- DOCS_URL = \local_middag\middag_metadata::DOCS_URL
- External resource URL: documentation site.
- MIDDAGPLUGINS_OVERVIEW_URL = \local_middag\middag_metadata::MIDDAGPLUGINS_OVERVIEW_URL
- External resource URL: plugins overview on docs.
- SITE_URL = \local_middag\middag_metadata::SITE_URL
- External resource URL: main company website.
- SUPPORT_URL = \local_middag\middag_metadata::SUPPORT_URL
- External resource URL: support portal.
Methods
- get() : object|T
- Retrieve a service from the DI container.
- get_component_name() : string
- Get the component name.
- get_docs_url() : string
- Get the documentation URL.
- get_middagplugins_overview_url() : string
- Get the Middag Plugins overview URL.
- get_site_url() : string
- Get the main site URL.
- get_support_url() : string
- Get the support portal URL.
- handle() : void
- Handle the current HTTP request and dispatch it to the appropriate controller.
- init() : void
- Initialize the application kernel.
- is_development() : bool
- Check if running in development environment.
- is_production() : bool
- Check if running in production environment.
- is_testing() : bool
- Check if running in PHPUnit test environment.
- register_route() : void
- Register a new route manually.
- register_routes_from_annotations() : void
- Register routes from PHP 8 Attributes (#[Route]) in a class.
- routing() : router_interface
- Access the Route Manager directly.
- shutdown() : void
- Shutdown the kernel.
- url_generator() : moodle_url
- Generate a Moodle URL from a Symfony route name and parameters.
- webhook_url_generator() : moodle_url
- Generate a webhook URL (helper for callbacks).
- __clone() : mixed
- Prevent cloning of the instance.
- __construct() : mixed
- Private constructor to prevent instantiation.
Constants
COMPONENT_NAME
Component name used for cache definitions, logs, and file storage.
public
mixed
COMPONENT_NAME
= \local_middag\middag_metadata::COMPONENT_NAME
DOCS_URL
External resource URL: documentation site.
public
mixed
DOCS_URL
= \local_middag\middag_metadata::DOCS_URL
MIDDAGPLUGINS_OVERVIEW_URL
External resource URL: plugins overview on docs.
public
mixed
MIDDAGPLUGINS_OVERVIEW_URL
= \local_middag\middag_metadata::MIDDAGPLUGINS_OVERVIEW_URL
SITE_URL
External resource URL: main company website.
public
mixed
SITE_URL
= \local_middag\middag_metadata::SITE_URL
SUPPORT_URL
External resource URL: support portal.
public
mixed
SUPPORT_URL
= \local_middag\middag_metadata::SUPPORT_URL
Methods
get()
Retrieve a service from the DI container.
public
static get(T>|string $id) : object|T
This is the primary escape hatch for the outside world to interact with your DI-managed services without coupling to the container directly.
Parameters
- $id : T>|string
-
Service ID or Class Name
Return values
object|Tget_component_name()
Get the component name.
public
static get_component_name() : string
Return values
stringget_docs_url()
Get the documentation URL.
public
static get_docs_url() : string
Return values
stringget_middagplugins_overview_url()
Get the Middag Plugins overview URL.
public
static get_middagplugins_overview_url() : string
Return values
stringget_site_url()
Get the main site URL.
public
static get_site_url() : string
Return values
stringget_support_url()
Get the support portal URL.
public
static get_support_url() : string
Return values
stringhandle()
Handle the current HTTP request and dispatch it to the appropriate controller.
public
static handle() : void
In practice, this delegates to the router/controller pipeline inside the kernel. Typical call site: entrypoints (index.php, webhook.php, etc.).
init()
Initialize the application kernel.
public
static init() : void
Idempotent: safe to call multiple times.
is_development()
Check if running in development environment.
public
static is_development() : bool
Return values
boolis_production()
Check if running in production environment.
public
static is_production() : bool
Return values
boolis_testing()
Check if running in PHPUnit test environment.
public
static is_testing() : bool
Return values
boolregister_route()
Register a new route manually.
public
static register_route(string $name, string $path, string $controller_class, string $method[, array<string|int, mixed> $requirements = [] ]) : void
This is useful when you want to define routes procedurally (e.g. in bootstrap), instead of attribute scanning.
Parameters
- $name : string
-
Route name (e.g., 'my_route').
- $path : string
-
URL path (e.g., '/my/path/{id}').
- $controller_class : string
-
FQCN of the controller
- $method : string
-
method name
- $requirements : array<string|int, mixed> = []
-
regex requirements for parameters
register_routes_from_annotations()
Register routes from PHP 8 Attributes (#[Route]) in a class.
public
static register_routes_from_annotations(string $class_name) : void
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
- $class_name : string
-
the class to scan
Tags
routing()
Access the Route Manager directly.
public
static routing() : router_interface
Exposes the router to allow:
- manual route registration
- attribute/annotation scanning (before compilation)
- URL generation through router abstraction
Return values
router_interfaceshutdown()
Shutdown the kernel.
public
static shutdown() : void
Useful for testing isolation.
url_generator()
Generate a Moodle URL from a Symfony route name and parameters.
public
static url_generator(string $route[, array<string|int, mixed> $parameters = [] ][, int $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH ]) : moodle_url
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
- $route : string
-
The route name
- $parameters : array<string|int, mixed> = []
-
Route parameters
- $reference_type : int = UrlGeneratorInterface::ABSOLUTE_PATH
-
URL generation type (Absolute/Relative)
Return values
moodle_urlwebhook_url_generator()
Generate a webhook URL (helper for callbacks).
public
static webhook_url_generator(string $route[, array<string|int, mixed> $parameters = [] ][, int $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH ]) : moodle_url
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
- $route : string
- $parameters : array<string|int, mixed> = []
- $reference_type : int = UrlGeneratorInterface::ABSOLUTE_PATH
Tags
Return values
moodle_url__clone()
Prevent cloning of the instance.
private
__clone() : mixed
__construct()
Private constructor to prevent instantiation.
private
__construct() : mixed