PHP code example of aol / atc

1. Go to this page and download the library: Download aol/atc 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/ */

    

aol / atc example snippets


$router->addGet('Index', '/');

namespace Your\Namespace\Prefix;

class Index extends \Aol\Atc\Action
{
    public function __invoke(Request $request)
    {
        return Response::create('Hello world');
    }
}

$router->addGet('Index', '/{name}/');

class Index extends \Aol\Atc\Action
{
    public function __invoke(Request $request)
    {
        return Response::create('Hello ' . $this->params['name']);
    }
}

class Index extends \Aol\Atc\Action
{
    protected $allowed_formats = ['text/html'];
    protected $view = 'index';

    public function __invoke(Request $request)
    {
        return ['name' => $this->params['name']];
    }
}

<!-- file: your/view/dir/index.php -->
Hello <?=$data['name']

class Index extends \Aol\Atc\Action
{
    public function __invoke(Request $request)
    {
        throw new \Aol\Atc\Exceptions\NotAuthorizedException;
    }
}

class NotSignedInException extends \Aol\Atc\Exception
{
    public function __invoke(Request $request)
    {
        return new RedirectResponse('/signin/');
    }
}

$router = (new \Aura\Router\RouterFactory())->newInstance();
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$action_factory = new \Aol\Atc\ActionFactory('Your\\Namespace\\Prefix\\');
$presenter = new \Aol\Atc\Presenter(__DIR__ . '/your/view/dir/');
$event_dispatcher = new \Aol\Atc\EventDispatcher;
$exception_handler = new \Aol\Atc\EventHandlers\DispatchErrorHandler;

$dispatch = new \Aol\Atc\Dispatch(
    $router,
    $request,
    $action_factory,
    $presenter,
    $event_dispatcher,
    $exception_handler
);

$response = $dispatch->run(); // Returns a symfony response object
$response->send();


bash
# Install Composer
curl -sS https://getcomposer.org/installer | php