1. Go to this page and download the library: Download davidecesarano/embryo 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 example snippets
use Embryo\Http\Message\{Response, ServerRequest};
// GET Route
$app->get('/blog/{id}', function(ServerRequest $request, Response $response, int $id) {
return $response->write('This is post with id '.$id);
}
namespace App\Controllers;
use Embryo\Controller;
use Embryo\Http\Message\Response;
class UserController extends Controller
{
/**
* @param int $id
* @return Response
*/
public function show(int $id): Response
{
return $this->response()->write($id);
}
}
use App\Controllers\UserController;
$app->get('/user/{id}', [UserController::class, 'show']);
namespace App\Controllers;
use Embryo\Controller;
use Path\To\Service;
class UserController extends Controller
{
/**
* @var Service $service
*/
private $service;
/**
* @param Service $service
*/
public function __construct(Service $service)
{
$this->service = $service;
}
}
namespace App\Controllers;
use Embryo\Controller;
use Embryo\Http\Message\ServerRequest;
class UserController extends Controller
{
/**
* @param ServerRequest $request
*/
public function store(ServerRequest $request)
{
//...
}
}
namespace App\Controllers;
use Embryo\Controller;
use Path\To\Service;
class UserController extends Controller
{
public function show()
{
$service = $this->get(Service::class);
//...
}
}
namespace App\Controllers;
use Embryo\Controller;
use Embryo\Http\Message\Response;
class UserController extends Controller
{
/**
* @return Response
*/
public function store(): Response
{
$params = $this->request()->getParsedBody();
//...
return $this->response()->write('Hello!');
}
}
namespace App\Controllers;
use Embryo\Controller;
use Embryo\Http\Message\Response;
class UserController extends Controller
{
/**
* @return Response
*/
public function store(): Response
{
$params = request()->getParsedBody();
return response()->write('Hello!');
}
}
namespace App\Services;
use Embryo\Container\ServiceProvider;
class TestService extends ServiceProvider
{
/**
* Registers service provider.
*
* @return void
*/
public function register()
{
$this->container->set('test', function($container){
return 'Hello from my test service';
});
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.