Skip to content

Commit

Permalink
Merge pull request #525 from sypets/sypets/move-command-controller
Browse files Browse the repository at this point in the history
Update and move page for Command Line Dispatcher (Symfony)
  • Loading branch information
sypets authored Jul 19, 2019
2 parents 5b854bc + 22f872f commit 2bd4800
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 160 deletions.
159 changes: 0 additions & 159 deletions Documentation/ApiOverview/BackendModules/CliScripts/Index.rst

This file was deleted.

2 changes: 1 addition & 1 deletion Documentation/ApiOverview/BackendModules/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ backend. They are described in this chapter.
Structure/Index
TemplateClass/Index
BackendModuleApi/Index
CliScripts/Index


98 changes: 98 additions & 0 deletions Documentation/ApiOverview/CommandControllers/Index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
.. include:: ../../Includes.txt


.. _cli-mode:
.. _cli-mode-dispatcher:
.. _cli-mode-command-controllers:

==================================
Command Line Dispatcher (Symfony)
==================================

It is possible to run some TYPO3 CMS scripts from the
command line. This makes it possible - for example -
to set up cronjobs.

TYPO3 uses Symfony commands to provide an easy to use, well-documented API for
writing CLI (command line interface) commands.


Creating a new Symfony Command in Your Extension
------------------------------------------------

.. rst-class:: bignums-xxl

#. Add :file:`Configuration/Commands.php` to your extension

TYPO3 looks in this file for configured commands. It should
return a simple array with the command name and class.

For example to add a command named **yourext:dothings**::

return [
'yourext:dothings' => [
'class' => \Vendor\Extension\Command\DoThingsCommand::class
],
];

By default, the command can be used in the scheduler too. You can deactivate
this by setting `schedulable` to `false`::

return [
'yourext:dothings' => [
'class' => \Vendor\Extension\Command\DoThingsCommand::class,
'schedulable' => false,
]
];


#. Create the corresponding class file: :file:`Classes/Command/DoThingsCommand.php`

Symfony commands should extend the class :php:`Symfony\Component\Console\Command\Command`.

The command should implement at least a :php:`configure` and an :php:`execute` method.


**configure()** as the name would suggest allows to configure the command.
Via :php:`configure()`, a description or a help text can be added, or mandatory and optional arguments and parameters defined.

A simple example can be found in the :php:`ListSysLogCommand`:

.. code-block:: php
/**
* Configure the command by defining the name, options and arguments
*/
protected function configure()
{
$this->setDescription('Show entries from the sys_log database table of the last 24 hours.');
$this->setHelp('Prints a list of recent sys_log entries.' . LF . 'If you want to get more detailed information, use the --verbose option.');
}
**execute()** contains the logic you want to execute when executing the command.

.. seealso::

A detailed description and an example can be found in `the Symfony Command Documentation <https://symfony.com/doc/current/console.html>`_.

Running the Command From the Command Line
-----------------------------------------

The above example can be run via command line:

.. code-block:: bash
bin/typo3 yourext:dothings
Running the Command From the Scheduler
--------------------------------------

By default, it is possible to run the command from the
`TYPO3 scheduler <https://docs.typo3.org/c/typo3/cms-scheduler/master/en-us/>`__ as well
if (`schedulable` is not set to false).

In the backend: :guilabel:`SYSTEM > Scheduler`

1 change: 1 addition & 0 deletions Documentation/ApiOverview/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This chapter describes the most important elements of the API.
BackendModules/Index
BackendRouting/Index
BackendUserObject/Index
CommandControllers/Index
Context/Index
Typo3CoreEngine/Index
FormEngine/Index
Expand Down

0 comments on commit 2bd4800

Please sign in to comment.