2017 © Pedro Peláez
 

library symfony-command-collector

Small script for extending symfony command for collecting symfony sub-commands.

image

rikby/symfony-command-collector

Small script for extending symfony command for collecting symfony sub-commands.

  • Thursday, September 22, 2016
  • by andkirby
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Symfony console commands collector

Installation

Just run in your project:, (*1)

composer require rikby/symfony-command-collector ^0.1.0@stable

First steps

There is a code which could help you to merge sub-commands from different places., (*2)

Let's admit we have command super which is an enter-point for our console commands., (*3)

super has sub-commands sub1 and sub2., (*4)

We have packages which could extend this command. There two sub-commands in two packages., (*5)

bin/
    .autoload-init.php
    super
src/
    SubOneCommand.php
    SubTwoCommand.php
vendor/
    my-vendor/
        pack111/
            bin/super-app-include.php
            src/FooCommand.php
        pack222/
            bin/super-app-include.php
            src/BarCommand.php
composer.json

Content of bin/super, (*6)

#!/usr/bin/env php
<?php
require_once __DIR__ . '/.autoload-init.php';

use Symfony\Component\Console\Application as App;
use Rikby\SymfonyConsole\CommandCollector\Collector;

$app = new App('Super shell console.', '0.1.0');
$app->add(new SubOneCommand());
$app->add(new SubTwoCommand());

//collect other commands
$collector = new Collector();
$collector->setPaths([__DIR__.'/../vendor/*/*/bin'])
    ->setName('super')
    ->setCompiledFile(__DIR__.'/.build-super.php')
    ->captureCommands();

// here .build-super.php must be generated even it's empty
require_once __DIR__.'/.build-super.php';

$app->run();

Code ->setPaths([__DIR__.'/../vendor/*/*/bin']) will push to search files in bin/ directory within all packages. Target filename is super-app-inlclude.php because of ->setName('super') and format %s-app-inlclude.php., (*7)

Content of vendor/my-vendor/pack111/bin/super-app-include.php:, (*8)

<?php
/** @var $app Symfony\Component\Console\Application */
$app->add(new My\PackOne\FooCommand());

Content of vendor/my-vendor/pack222/bin/super-app-include.php:, (*9)

<?php
/** @var $app Symfony\Component\Console\Application */
$app->add(new My\PackTwo\BarCommand());

As you may suspected the generated file bin/.build-super.php will contain following code of these two files super-app-include.php., (*10)

<?php
/** @var $app Symfony\Component\Console\Application */
$app->add(new My\PackOne\FooCommand());
/** @var $app Symfony\Component\Console\Application */
$app->add(new My\PackTwo\BarCommand());

In case you need to regenerate the file you have two options: - Remove file bin/.build-super.php - Call CollectorTrait::forceCaptureCommands(), (*11)

Integrate into a class

Actually there is the trait Rikby\SymfonyConsole\CommandCollector\CollectorTrait which can be used anywhere.
Class Rikby\SymfonyConsole\CommandCollector\Collector just wraps it., (*12)

TBD

There is an approach for including ***-app-include.php instead merging them.
Maybe it would be useful to links to these files., (*13)

The Versions

22/09 2016

dev-master

9999999-dev

Small script for extending symfony command for collecting symfony sub-commands.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

22/09 2016

v0.1.0

0.1.0.0

Small script for extending symfony command for collecting symfony sub-commands.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires