Skip to content

Instantly share code, notes, and snippets.

@jmas
Created May 17, 2016 22:04
Show Gist options
  • Save jmas/0ed24fe00bc2a8eb8361431e55d0cda8 to your computer and use it in GitHub Desktop.
Save jmas/0ed24fe00bc2a8eb8361431e55d0cda8 to your computer and use it in GitHub Desktop.
Slim Framework 3 as cli command
<?php
// php cli.php /update
require __DIR__ . '/vendor/autoload.php';
if (PHP_SAPI == 'cli') {
$argv = $GLOBALS['argv'];
array_shift($argv);
$pathInfo = implode('/', $argv);
$env = \Slim\Http\Environment::mock(['REQUEST_URI' => $pathInfo]);
$settings = require __DIR__ . '/src/settings.php'; // here are return ['settings'=>'']
$settings['environment'] = $env;
$app = new \Slim\App($settings);
$container = $app->getContainer();
$container['errorHandler'] = function ($container) {
return function ($request, $response, $exception) use ($container) {
print('error');
exit(1);
};
};
$container['notFoundHandler'] = function ($container) {
return function ($request, $response) use ($container) {
print('not_found');
exit(1);
};
};
$app->get('/update', function ($request, $response, $args) {
return 'update!';
});
$app->run();
}
@fedek6
Copy link

fedek6 commented Feb 12, 2019

Nice! Works perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment