middag
final class middag
Main Facade for the Middag plugin.
This class acts as a Static Proxy (Facade) to the underlying Kernel architecture. It provides a simplified, clean API for the rest of the Moodle ecosystem to interact with the plugin's Services, Routes, and Environment configuration.
Design goals:
- Keep the "public" API small and stable (other code calls this class).
- Keep the internal architecture flexible behind kernel/router/container.
- Offer a single entry-point to bootstrap, handle requests, and resolve services.
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
Singleton Accessor (Factory Method).
Initialize the application kernel.
Shutdown the kernel and reset the singleton.
Handle the current HTTP request and dispatch it to the appropriate controller.
Retrieve a service from the DI container.
Access the Route Manager directly.
Generate a Moodle URL from a Symfony route name and parameters.
Generate a webhook URL (helper for callbacks).
Register a new route manually.
Register routes from PHP 8 Attributes (#[Route]) in a class.
Get the component name.
Get the documentation URL.
Get the main site URL.
Get the support portal URL.
Get the Middag Plugins overview URL.
Check if running in PHPUnit test environment.
Check if running in development environment.
Check if running in production environment.
Details
at line 90
static middag
get_instance()
Singleton Accessor (Factory Method).
Used by the Container to register 'middag' as a service. This allows the facade to be injected (when desired) while remaining static-friendly.
at line 104
static void
init()
Initialize the application kernel.
Idempotent: safe to call multiple times.
at line 114
static void
shutdown()
Shutdown the kernel and reset the singleton.
Useful for testing isolation.
at line 129
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.).
at line 146
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.
at line 162
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
at line 179
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.
at line 200
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
at line 218
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.
at line 240
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.
at line 250
static string
get_component_name()
Get the component name.
at line 260
static string
get_docs_url()
Get the documentation URL.
at line 270
static string
get_site_url()
Get the main site URL.
at line 280
static string
get_support_url()
Get the support portal URL.
at line 290
static string
get_middagplugins_overview_url()
Get the Middag Plugins overview URL.
at line 300
static bool
is_testing()
Check if running in PHPUnit test environment.
at line 310
static bool
is_development()
Check if running in development environment.
at line 320
static bool
is_production()
Check if running in production environment.