PHP code example of bloatless / endocore

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

    

bloatless / endocore example snippets


return [
    'home' => [
        'method' => 'GET',
        'pattern' => '/about',
        'handler' => 'Bloatless\EndocoreApp\Actions\AboutAction',
    ],
];

return [
    'home' => [
        'method' => 'POST',
        'pattern' => '/customers',
        'handler' => 'Bloatless\EndocoreApp\Actions\AddCustomerAction',
    ],
];

return [
    'customer' => [
        'method' => 'GET',
        'pattern' => '/customers/{id}',
        'handler' => 'Bloatless\EndocoreApp\Actions\CustomerAction',
    ],
];

[
    'id' => 123
]

return [
    'customer' => [
        'method' => 'GET',
        'pattern' => '/customers/{id:[0-9]+}',
        'handler' => 'Bloatless\EndocoreApp\Actions\CustomerAction',
    ],
];

class MyJsonAction extends JsonAction
{
    public function __invoke(array $arguments = []): Response
    {
        $data = [
            'foo' => 'Some data...',
        ];
        return $this->responder->found($data);
    }
}

class MyHtmlAction extends HtmlAction
{
    public function __invoke(array $arguments = []): Response
    {        
        $data = [
            'body' => '<p>Hello World!</p>',
        ];
        return $this->responder->found($data);
    }
}

class MyHtmlAction extends HtmlAction
{
    public function __invoke(array $arguments = []): Response
    {
        $this->logger->warning('Some error occurred');  
    }
}

'logger' => [
    'path_logs' => __DIR__ . '/../logs',
    'min_level' => 'warning',
],

$this->logger->debug('Some error occurred');
$this->logger->notice('Some error occurred');
$this->logger->info('Some error occurred');
$this->logger->warning('Some error occurred');
$this->logger->error('Some error occurred');
$this->logger->critial('Some error occurred');
$this->logger->alert('Some error occurred');
$this->logger->emergency('Some error occurred');

$this->logger->log('warning', 'Some error occurred');

$this->logger->warning('Some error message', [
    'browser' => 'Firefox',
]);

class MyHtmlAction extends HtmlAction
{
    public function __invoke(array $arguments = []): Response
    {
        // some error occurs...
        return $this->responder->error(['data' => 'some additional data...']);
    }
}

class MyHtmlAction extends HtmlAction
{
    public function __invoke(array $arguments = []): Response
    {
        return $this->responder->badRequest(); // 400
        return $this->responder->notFound(); // 404
        return $this->responder->methodNotAllowed(); // 405
    }
}

class MyDomain
{
    public function myMethod(): string
    {
        throw new EndocoreException('Something went wrong...');
    }
}

class MyDomain
{
    public function myMethod(): string
    {
        throw new BadRequestException(); // 400
        throw new NotFoundException(); // 404
        throw new MethodNotAllowedException(); // 405
    }
}

php composer.phar create-project bloatless/endocore-app my_sample_project