PHP code example of jasny / codeception-module

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

    

jasny / codeception-module example snippets


use Mouf\Picotainer\Picotainer;
use Jasny\Router;
use Jasny\Router\Routes\Glob as Routes;
use Jasny\RouterInterface;

return new Picotainer([
    RouterInterface::class => function() {
        return new Router(new Routes([
            '/' => ['controller' => 'foo'],
            // ...
        ]));
    }
]);

use Mouf\Picotainer\Picotainer;
use Jasny\Router;
use Jasny\Router\Routes\Glob as Routes;
use Jasny\RouterInterface;
use Jasny\HttpMessage\ServerRequest;
use Jasny\HttpMessage\Response;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

return new new Picotainer([
    RouterInterface::class => function() {
        return new Router(new Routes([
            '/' => ['controller' => 'foo'],
            // ...
        ]));
    },
    ServerRequestInterface::class => function() {
        return new ServerRequest();
    },
    ResponseInterface::class => function() {
        return new Response();
    }
]);

use Mouf\Picotainer\Picotainer;
use Jasny\Router;
use Jasny\Router\Routes\Glob as Routes;
use Jasny\RouterInterface;
use Jasny\HttpMessage\ServerRequest;
use Jasny\HttpMessage\Response;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

return new Picotainer([
    RouterInterface::class => function() {
        return new Router(new Routes([
            '/' => ['controller' => 'foo'],
            // ...
        ]));
    },
    ServerRequestInterface::class => function() {
        return (new ServerRequest())->withGlobalEnvironment(true);
    },
    ResponseInterface::class => function() {
        return (new Response())->withGlobalEnvironment(true);
    }
]);

use Mouf\Picotainer\Picotainer;
use Jasny\Router;
use Jasny\Router\Routes\Glob as Routes;
use Jasny\RouterInterface;
use Jasny\ErrorHandler;
use Jasny\ErrorHandlerInterface;

return new Picotainer([
    RouterInterface::class => function($container) {
        $router = new Router(new Routes([
            '/' => ['controller' => 'foo'],
            // ...
        ]));
        
        $errorHandler = $container->get(ErrorHandlerInterface::class);
        $router->add($errorHandler->asMiddleware());
        
        return $router;
    },
    ErrorHandlerInterface::class => function() {
        $errorHandler = new ErrorHandler();
        
        $errorHandler->logUncaught(E_PARSE | E_ERROR | E_WARNING | E_USER_WARNING);
        $errorHandler->logUncaught(Exception::class);
        $errorHandler->logUncaught(Error::class); // PHP7 only
        
        return $errorHandler;
    });
]);