Breaking Changes in v1.12.00
Customizing and migrating to v1.12.00 will require some new changes.
Configuration
To be determined.
Functions
The most significant function differences will be highlighted.
Namespace
All functions, classes, and constants exist in the \XMB namespace since the previous version. See Breaking Changes in v1.10.00 for details.
Services no longer have individual locator functions. These were removed to create a more flexible architecture.
To that end, XMB offers a service container in the \XMB\Services namespace. The service container is retrieved by calling \XMB\Services\container(). The shared core service is returned by calling \XMB\Services\container()->get('core'). Note the service alias IDs are all lowercase unlike the class names. Here is the suggested style:
namespace XMB;
require './header.php';
$services = Services\container();
$core = $services->get('core');
$core->nav('Add me to the navbar.');
When the service container is needed from outside the XMB namespace, it looks best to import the Services namespace to stay consistent with our code style. Otherwise, it will need to be referenced by its full name like \XMB\Services\container().
namespace MyProject;
use XMB\Services;
require './header.php';
$services = Services\container();
$core = $services->get('core');
$core->nav('Add me to the navbar.');
It is now possible to register a new service without modifying any of the container code. For example, you want to monetize parts of your website and make the payment logic available through the container. The first step is to create a factory for your new service. This is required because the factory will be registered to the container. We do not create an instance of the service here, and instead provide the logic for how to do so. Let's create a file named custom/service-factories.php and assume the custom Payments service will depend on the XMB db service:
namespace MyProject;
use XMB\Services\Container;
function register_services(Container $services)
{
// Parameter 1 informs the container of the full name and namespace of your new service.
// Parameter 2 uses "first-class callable syntax" to pass your factory to the container.
// Parameter 3 adds a simple alias 'my_payments' for the new service.
$services->set(Payments::class, payments_factory(...), ['my_payments']);
}
function payments_factory(callable $getService): Payments
{
return new Payments(
$getService('db'),
);
}
Then in header.php before the "Extra Security" comment, you can load the custom files and register the new service:
require ROOT . 'custom/Payments.php'; require ROOT . 'custom/service-factories.php'; \MyProject\register_services($services);
Critical Functions
Core::assertPasswordPolicy() has moved to Password::assertPasswordPolicy().