MIDDAG for Moodle

middag

FinalYes

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.
Tags
final

This class should not be extended.

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.

Properties

$instance  : null|self
Singleton instance holder.

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_instance()  : self
Singleton Accessor (Factory Method).
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 and reset the singleton.
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

Properties

$instance

Singleton instance holder.

private static null|self $instance = null

This is used when you want to register "middag" as a service in the container, but still keep the class itself "static-first" for most calls in Moodle.

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|T

get_component_name()

Get the component name.

public static get_component_name() : string
Return values
string

get_docs_url()

Get the documentation URL.

public static get_docs_url() : string
Return values
string

get_instance()

Singleton Accessor (Factory Method).

public static get_instance() : self

Used by the Container to register 'middag' as a service. This allows the facade to be injected (when desired) while remaining static-friendly.

Return values
self

get_middagplugins_overview_url()

Get the Middag Plugins overview URL.

public static get_middagplugins_overview_url() : string
Return values
string

get_site_url()

Get the main site URL.

public static get_site_url() : string
Return values
string

get_support_url()

Get the support portal URL.

public static get_support_url() : string
Return values
string

handle()

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
bool

is_production()

Check if running in production environment.

public static is_production() : bool
Return values
bool

is_testing()

Check if running in PHPUnit test environment.

public static is_testing() : bool
Return values
bool

register_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

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_interface

shutdown()

Shutdown the kernel and reset the singleton.

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_url

webhook_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
throws
moodle_exception
Return values
moodle_url

__clone()

Prevent cloning of the instance.

private __clone() : mixed

Avoids bypassing singleton semantics accidentally.

__construct()

Private constructor to prevent instantiation.

private __construct() : mixed

This class is intended to be consumed as a facade through static methods. The only supported instance is via get_instance().


        
On this page

Search results