Support

Documentation

Using handler files

[Note]Note

This feature is for expert users with a modicum of PHP software development experience.

UNiTE 5 and later support handler files. These are PHP files which return a callable (typically an anonymous invokable class object) which is executed at the end of the restoration process.

A typical handler file looks like this:

<?php

return new class {
    public function __invoke(
        \Joomla\Application\AbstractApplication         $app,
        \Symfony\Component\Console\Input\InputInterface $input
    ): void
    {
       // Your handler code goes here
    }
}

The sample file above returns an anonymous invokable class object. The code to run is inside the __invoke method.

The method is passed two objects from UNiTE:

  • $app. This is the UNiTE application object. Please note that this is NOT a Joomla CMS application; we are simply using our own copy of the Joomla Framework which is separate to the Joomla CMS.

  • $input. This is a Symfony Console input object. It gives you access to the arguments and options passed to UNiTE in the command line which executed it.

The application object has the $app->container property which returns the Dependency Injection Container of the UNiTE application. You can use it to get access to UNiTE's PSR-3 logger object through it:

$logger = $app->container->get(LoggerInterface::class);
$logger->info('Hello from the custom hander!');

Everything you send to the logger is, of course, written to the log file. Depending on your use of the --verbose and --quiet options in the command line some or all of that information will be printed in UNiTE's output.

Moreover, you can get the current UNiTE job configuration (a representation of your configuration file) using $app->get('job') which returns an object of the \Akeeba\UNiTE\DataShape\JobDefinition type. This allows you to get access to all the information in the configuration file. You could, for example, get the path where the restored site is by doing $app->get('job')->siteInfo->absolutepath.

You can understand more what is possible by studying the classes under the DataShape directory of UNiTE's PHAR package. You can very easily find instructions on extracting PHAR archives online.