3fpixa
Last Updated: February 25, 2016
·
809
· raphaelstolt
Tweet avatar corner

Disabling Silex controllers execution

When enriching a classic web Silex application w/ a Cilex Console Service Provider, the following listing shows how to disable the web-facing controllers when using the application in CLI mode by utilising PHP's PHP_SAPI constant.

<?php
use Acme\Console\Command,
  Cilex\Provider\Console\Adapter\Silex\ConsoleServiceProvider,
  Silex\Application;

require_once __DIR__ . '/../vendor/autoload.php';

$app = new Application;

// Omitted Silex route definitions
// Console Service Provider and command-line commands
$app->register(new ConsoleServiceProvider(), array(
    'console.name' => 'MyApp',
    'console.version' => '1.0.5',
));
$commands = array(
    new Command\XyzInfoCommand(),
    new Command\XyzSnapshotCommand(),
);

foreach ($commands as $command) {
    $app['console']->add($command);
}

if (PHP_SAPI !== 'cli') {
    $app->run();
} else {
    $app['console']->run();
}
Say Thanks
Respond
Filed Under