Back to ConsoleApplication class

Method __construct

public
__construct
(\Joomla\Registry\Registry $config, \Joomla\Event\DispatcherInterface $dispatcher, \Joomla\DI\Container $container, \Joomla\CMS\Language\Language $language, ?\Symfony\Component\Console\Input\InputInterface $input = null, ?\Symfony\Component\Console\Output\OutputInterface $output = null)
Class constructor.
Parameters
  • \Joomla\Registry\Registry $config An optional argument to provide dependency injection for the application's config object. If the argument is a Registry object that object will become the application's config object, otherwise a default config object is created.
  • \Joomla\Event\DispatcherInterface $dispatcher An optional argument to provide dependency injection for the application's event dispatcher. If the argument is a DispatcherInterface object that object will become the application's event dispatcher, if it is null then the default event dispatcher will be created based on the application's loadDispatcher() method.
  • \Joomla\DI\Container $container Dependency injection container.
  • \Joomla\CMS\Language\Language $language The language object provisioned for the application.
  • \Symfony\Component\Console\Input\InputInterface|null $input An optional argument to provide dependency injection for the application's input object. If the argument is an InputInterface object that object will become the application's input object, otherwise a default input object is created.
  • \Symfony\Component\Console\Output\OutputInterface|null $output An optional argument to provide dependency injection for the application's output object. If the argument is an OutputInterface object that object will become the application's output object, otherwise a default output object is created.
Since
  • 4.0.0

Method __construct - Source code

/**
 * Class constructor.
 *
 * @param   Registry              $config      An optional argument to provide dependency injection for the application's config object. If the
 *                                             argument is a Registry object that object will become the application's config object,
 *                                             otherwise a default config object is created.
 * @param   DispatcherInterface   $dispatcher  An optional argument to provide dependency injection for the application's event dispatcher. If the
 *                                             argument is a DispatcherInterface object that object will become the application's event dispatcher,
 *                                             if it is null then the default event dispatcher will be created based on the application's
 *                                             loadDispatcher() method.
 * @param   Container             $container   Dependency injection container.
 * @param   Language              $language    The language object provisioned for the application.
 * @param   InputInterface|null   $input       An optional argument to provide dependency injection for the application's input object. If the
 *                                             argument is an InputInterface object that object will become the application's input object,
 *                                             otherwise a default input object is created.
 * @param   OutputInterface|null  $output      An optional argument to provide dependency injection for the application's output object. If the
 *                                             argument is an OutputInterface object that object will become the application's output object,
 *                                             otherwise a default output object is created.
 *
 * @since   4.0.0
 */
public function __construct(Registry $config, DispatcherInterface $dispatcher, Container $container, Language $language, ?InputInterface $input = null, ?OutputInterface $output = null)
{
    // Close the application if it is not executed from the command line.
    if (!\defined('STDOUT') || !\defined('STDIN') || !isset($_SERVER['argv'])) {
        $this->close();
    }
    // Set up a Input object for Controllers etc to use
    $this->input = new \Joomla\CMS\Input\Cli();
    $this->language = $language;
    parent::__construct($input, $output, $config);
    $this->setVersion(JVERSION);
    // Register the client name as cli
    $this->name = 'cli';
    $this->setContainer($container);
    $this->setDispatcher($dispatcher);
    // Set the execution datetime and timestamp;
    $this->set('execution.datetime', gmdate('Y-m-d H:i:s'));
    $this->set('execution.timestamp', time());
    $this->set('execution.microtimestamp', microtime(true));
    // Set the current directory.
    $this->set('cwd', getcwd());
    // Set up the environment
    $this->input->set('format', 'cli');
}