Skip to content

Instantly share code, notes, and snippets.

@jmas

jmas/cli.php

Created May 17, 2016
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@fedek6 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