Skip to content
forked from pavlakis/slim-cli

A Slim 3 middleware enabling a mock GET request to be made through the CLI.

License

Notifications You must be signed in to change notification settings

lineten/slim-cli

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Total Downloads Latest Stable Version codecov

Slim 3 Framework CLI Request Middleware

This middleware will transform a CLI call into a GET Request.

Add it with composer

composer require pavlakis/slim-cli

Pass the parameters in this order

route / method / query string

php public/index.php /status GET event=true

Add it in the middleware section of your application

$app->add(new \pavlakis\cli\CliRequest());

Pass a route to test it with

$app->get('/status', 'PHPMinds\Action\EventStatusAction:dispatch')
    ->setName('status');

Check you're only using a CLI call

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"]))

Credits

Based on Bobby DeVeaux's (@bobbyjason) Gulp Skeleton

About

A Slim 3 middleware enabling a mock GET request to be made through the CLI.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%