Hack command line application container created for Decouple Framework.

Maintainers

Details

github.com/decouple/cli

Source

Issues

Installs: 41

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Language:Hack

dev-master 2017-02-18 04:01 UTC

This package is not auto-updated.

Last update: 2024-05-25 16:06:44 UTC


README

Hack command line application container created for Decouple Framework.

Usage

<?hh // partial

use Decouple\CLI\App;
use Decouple\CLI\Request\Request;
use Decouple\Decoupler\Decoupler;
use Decouple\Registry\Paths;
use Decouple\Log\Log;

// Define a vector of valid commands
$commands = Vector {
  "Decouple\Test\TestCommand",
  "Decouple\DBAL_CLI\Command\MigrateUpCommand",
  "Decouple\DBAL_CLI\Command\MigrateDownCommand",
  "Decouple\DBAL_CLI\Command\MigrateRefreshCommand",
  "Decouple\DBAL_CLI\Command\SeedCommand"
};

// Remove the name of the binary .hh
$args = new Vector($argv);
if($args->get(0) == 'decouple.hh') { $args->removeKey(0); }

// Create the CLI Request
$request = new Request($args);

// Create a Decoupler injector instance
$decoupler = new Decoupler(Map {});

// Register a $paths container containing at least a path to the "config" dir
$paths = new Paths(Map {
  "config" => "/path/to/configs"
});

// Create the CLI App with the given Request,
$app = new App($request, $decoupler, new Paths($paths), $commands);

/**
* Using the Decoupler you can now add a parameter with any of the types below
* to your Command constructors and it will be automatically injected
*/
$services = Map {
  "Decouple\Log\Log" => new Log((string)$paths->get('logs') . "/cli.log"),
  "Decouple\Registry\Paths" => new Paths($paths),
  "Decouple\CLI\Request\Request" => $request
};
$app->addServices($services);

$app->execute();