-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e44f67
commit 0069c1e
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use Lcobucci\DependencyInjection\ContainerConfig; | ||
use LuisMulinari\Consoleful\Command\ContainerAwareCommand; | ||
use LuisMulinari\Consoleful\Application; | ||
use Lcobucci\DependencyInjection\ContainerInjector; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
|
||
class ExampleCommand extends ContainerAwareCommand | ||
{ | ||
use ContainerInjector; | ||
|
||
protected function configure() | ||
{ | ||
$this->setName("example"); | ||
$this->setDescription('* Simple example'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$container = $this->getContainer(); | ||
|
||
$progress = new ProgressBar($output, 5); | ||
|
||
$progress->start(); | ||
|
||
$i = 0; | ||
while ($i++ < 5) { | ||
$progress->advance(); | ||
|
||
sleep(1); | ||
} | ||
|
||
$progress->finish(); | ||
|
||
$output->writeln($container->getParameter('parameter.example')); | ||
} | ||
} | ||
|
||
class DatabaseCommand extends ContainerAwareCommand | ||
{ | ||
use ContainerInjector; | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('database'); | ||
$this->setDescription('* Exemple with database'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
if (!class_exists('Doctrine\DBAL\Connection')) { | ||
$output->write('You need to include "doctrine/dbal" package in your composer.json'); | ||
|
||
return false; | ||
} | ||
|
||
$databaseTables = $this->getContainer()->get('database.connection')->query('SHOW TABLES')->fetchAll(); | ||
|
||
$tableHelper = $this->getHelper('table'); | ||
|
||
$tableHelper->setHeaders(['Table name']); | ||
$tableHelper->setRows($databaseTables); | ||
|
||
$tableHelper->render($output); | ||
} | ||
} | ||
|
||
|
||
$application = new Application( | ||
'Application name', | ||
'Version', | ||
new ContainerConfig(__DIR__ . '/services.xml') // services.[xml|yml|php] | ||
); | ||
|
||
$application->add(new ExampleCommand()); | ||
$application->add(new DatabaseCommand()); | ||
|
||
$application->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<parameters> | ||
<parameter key="database.connection.params" type="collection"> | ||
<parameter key="dbname">__dbname__</parameter> | ||
<parameter key="user">__user__</parameter> | ||
<parameter key="password">__password__</parameter> | ||
<parameter key="host">127.0.0.1</parameter> | ||
<parameter key="driver">pdo_mysql</parameter> | ||
</parameter> | ||
</parameters> | ||
|
||
<services> | ||
<service id="database.connection" alias="doctrine.dbal.connection"/> | ||
|
||
<service id="doctrine.dbal.configuration" class="Doctrine\DBAL\Configuration" /> | ||
<service id="doctrine.dbal.connection" class="Doctrine\DBAL\Connection" factory-class="Doctrine\DBAL\DriverManager" factory-method="getConnection"> | ||
<argument>%database.connection.params%</argument> | ||
<argument type="service" id="doctrine.dbal.configuration" /> | ||
</service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<imports> | ||
<import resource="database.xml"/> | ||
</imports> | ||
|
||
<parameters> | ||
<parameter key="parameter.example">Example param from container</parameter> | ||
</parameters> | ||
</container> |