PHP code example of davidecesarano / embryo-routing
1. Go to this page and download the library: Download davidecesarano/embryo-routing 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/ */
davidecesarano / embryo-routing example snippets
use Embryo\Container\Container;
use Embryo\Http\Emitter\Emitter;
use Embryo\Http\Factory\{ServerRequestFactory, ResponseFactory};
use Embryo\Http\Server\RequestHandler;
use Embryo\Routing\Router;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
$container = new Container;
$request = (new ServerRequestFactory)->createServerRequestFromServer();
$response = (new ResponseFactory)->createResponse(200);
$requestHandler = new RequestHandler;
$emitter = new Emitter;
// GET Route
$router->get('/blog/{id}', function(Request $request, Response $response, int $id) {
$response->getBody()->write('This is post with id '.$id);
return $response;
});
use Embryo\Routing\Controller;
use Psr\Http\Message\ResponseInterface;
class User extends Controller
{
public function getById(int $id): ResponseInterface
{
$this->response->getBody()->write('The User id is: '.$id);
return $this->response;
}
}
use Path\To\MyService;
use Embryo\Routing\Controller;
use Psr\Http\Message\ResponseInterface;
class User extends Controller
{
public function getById(MyService $service, int $id): ResponseInterface
{
//...
}
}
$router = new Router;
$router->setNamespace('App\\Controller');
$router->get('/', 'PageController@index'); // App\Controller\PageController
//...