Created
May 17, 2016 22:04
-
-
Save jmas/0ed24fe00bc2a8eb8361431e55d0cda8 to your computer and use it in GitHub Desktop.
Slim Framework 3 as cli command
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
<?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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Works perfectly.