Slim 3 Framework CLI Request Middleware
This middleware will transform a CLI call into a Request.
Via Composer
composer require pavlakis/slim-cli
route / method / query string
php public/index.php /status GET event=true
$app->add(new \pavlakis\cli\CliRequest());
Adding custom parameters:
$app->add(
new \pavlakis\cli\CliRequest(
new EnvironmentProperties(['SERVER_PORT' => 9000])
)
);
$app->get('/status', 'PHPMinds\Action\EventStatusAction:dispatch')
->setName('status');
final class EventStatusAction
{
...
public function dispatch(Request $request, Response $response, $args)
{
// ONLY WHEN CALLED THROUGH CLI
if (PHP_SAPI !== 'cli') {
return $response->withStatus(404)->withHeader('Location', '/404');
}
if (!$request->getParam('event')) {
return $response->withStatus(404)->withHeader('Location', '/404');
}
...
}
}
Or we can use a PHP Server Interface (SAPI) Middleware to do the SAPI check adding by adding it to a route:
// By default returns a 403 if SAPI not part of the whitelist
$app->get('/status', 'PHPMinds\Action\EventStatusAction:dispatch')
->add(new Pavlakis\Middleware\Server\Sapi(["cli"]))
$ composer test
Please see CONTRIBUTING for details.
Based on Bobby DeVeaux's (@bobbyjason) Gulp Skeleton
The BSD 3-Clause License. Please see License File for more information.