https://github.com/antidot-framework/antidot-cli
Symfony console component tweaked for Antidot Framework
https://github.com/antidot-framework/antidot-cli
Last synced: 2 months ago
JSON representation
Symfony console component tweaked for Antidot Framework
- Host: GitHub
- URL: https://github.com/antidot-framework/antidot-cli
- Owner: antidot-framework
- License: bsd-2-clause
- Created: 2019-04-07T18:01:46.000Z (about 6 years ago)
- Default Branch: 3.x.x
- Last Pushed: 2024-05-22T18:54:18.000Z (about 1 year ago)
- Last Synced: 2025-04-18T17:23:49.907Z (2 months ago)
- Language: PHP
- Homepage: https://cli.antidotfw.io
- Size: 43 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Antidot Framework Console Tool
[](https://scrutinizer-ci.com/g/antidot-framework/antidot-cli/?branch=master)
[](https://scrutinizer-ci.com/g/antidot-framework/antidot-cli/?branch=master)
[](https://scrutinizer-ci.com/g/antidot-framework/antidot-cli/build-status/master)
[](https://scrutinizer-ci.com/code-intelligence)This library is an adapter for using the [Symfony Console component](https://symfony.com/doc/current/components/console.html)
using the standard Zend Framework configuration and any dependency injection container compatible with
the `Psr\ContainerInterface`## Install
Using composer package manager
````bash
composer require antidot-fw/cli
````### Antidot Framework:
The Cli component is installed by default in [Antidot Framework Starter](https://github.com/antidot-framework/antidot-starter)
### Zend Expressive:
The Cli component will be automatically installed by running composer require command when we have previously
installed the library [Zend Config Aggregator](https://github.com/zendframework/zend-config-aggregator)All we'll need to do is create the Console entry point:
````php
#!/usr/bin/env php
get(Console::class);$console->run();
});
````Finally we will give execution permissions to the file `bin/console`
````bash
# Debian systems
chmod +x bin/console
````### As Standalone application
The Cli component can also be used to create console applications without any Framework,
all we need is an implementation of the dependency injection container compatible with the
standard `Psr\ContainerInterface`Assuming we create a project with the following structure:
````
bin/console
config/container.php
composer.json
````As a dependency we could use the [Antidot Framework adapter For Aura Container](https://github.com/antidot-framework/aura-container-config)
````json
# composer.json
{
"name": "antidot-fw/console-example",
"description": "Antidot framework console project example",
"type": "project",
"require": {
"antidot-fw/cli": "dev-master",
"antidot-fw/aura-container-config": "dev-master"
},
"require-dev": {
"symfony/var-dumper": "^4.3"
},
"autoload": {
"psr-4": {
"App\\": "src"
}
}
}
````We create the file `config/container.php` that must return a configured instance of `Psr\ContainerInterface` to us.
````php
[], 'console' => [ 'commands' => [] ] ];
// Build container
$builder = new ContainerBuilder();
return $builder->newConfiguredInstance([
new ContainerConfig(\is_array($config) ? $config : []),
], $builder::AUTO_RESOLVE);
````We need to create the Console entry point:
````php
get(Console::class);$console->run();
});
````And give to it execution permissions
````bash
# Debian systems
chmod +x bin/console
````## Usage
Una vez instalada la Consola, podemos ver los comndos disponibles ejecutando el punto de entrada con el parametro
`list` o sin parametro````bash
bin/console
````### Create Commands
To create console commands you need to create a class that extends from `Symfony\Component\Console\Command\Command`
````php
dependency = $dependency;
parent::__construct();
}
protected function configure(): void
{
$this->setName('some:command:name');
}
protected function execute(InputInterface $input, OutputInterface $output): void
{
$output->writeLn('Hello World!!!');
}
}
````For more information you can see [the official documentation](https://symfony.com/doc/current/console.html) of Symfony in this regard.
### Config
The configuration consists of three different elements: `dependencies`, `console.commands` y `console.helper-sets`
````php
'var/cache/config-cache.php',
'dependencies' => [
'invokables' => [
SomeCommandClass::class => SomeCommandClass::class,
SomeHelperSet::class => SomeHelperSet::class,
]
],
'console' => [
'commands' => [
'some:command:name' => SomeCommandClass::class
],
'helper-sets' => [
SomeHelperSet::class
]
]
];
````