PHP code example of pavlakis / slim-cli

1. Go to this page and download the library: Download pavlakis/slim-cli library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pavlakis / slim-cli example snippets


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

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

$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');
        }

        ...

    }

}

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