You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1. Magento Architecture and Customization Techniques/7. Utilize the CLI.md
+65Lines changed: 65 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -31,3 +31,68 @@ Production - max speed, no errors, no file generation:
31
31
- errors logged, not displayed
32
32
- static not created dynamically, must be deployed
33
33
- not need for www-data to write, pub/static can be read-only
34
+
35
+
### How to add CLI commands (off-topic)
36
+
37
+
Magento 2 CLI is based on the Symfony Console component.
38
+
39
+
To create new CLI command you need:
40
+
- Create command class (the recommended location is {module}/Console/Command)
41
+
This class must extends from [\Symfony\Component\Console\Command\Command](https://github.com/symfony/console/blob/master/Command/Command.php) and have 2 methods:
42
+
43
+
`configure` - to set the name, description, command line arguments etc
44
+
45
+
`execute` - is the place where you write your code
46
+
47
+
```php
48
+
<?php
49
+
namespace Vendor\Module\Console\Command;
50
+
51
+
class ExampleCommand extends \Symfony\Component\Console\Command\Command
protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
70
+
{
71
+
$output->writeln('hello world');
72
+
}
73
+
}
74
+
```
75
+
76
+
- Declare your command in [\Magento\Framework\Console\CommandListInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Console/CommandListInterface.php) using dependency injection ({module}/etc/di.xml).
77
+
See also CommandListInterface implementation: [\Magento\Framework\Console\CommandList](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Console/CommandList.php)
0 commit comments