{"id":15025253,"url":"https://github.com/davidecesarano/embryo","last_synced_at":"2025-04-09T20:03:56.483Z","repository":{"id":56963357,"uuid":"168327665","full_name":"davidecesarano/Embryo","owner":"davidecesarano","description":"Embryo Framework 3 skeleton application.","archived":false,"fork":false,"pushed_at":"2022-07-05T13:48:44.000Z","size":67,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"3.x","last_synced_at":"2025-04-09T20:03:51.289Z","etag":null,"topics":["php","php-7","php-framework","psr"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidecesarano.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-30T10:54:42.000Z","updated_at":"2023-02-25T16:19:49.000Z","dependencies_parsed_at":"2022-08-21T05:40:26.013Z","dependency_job_id":null,"html_url":"https://github.com/davidecesarano/Embryo","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidecesarano%2FEmbryo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidecesarano%2FEmbryo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidecesarano%2FEmbryo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidecesarano%2FEmbryo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidecesarano","download_url":"https://codeload.github.com/davidecesarano/Embryo/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103864,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","php-7","php-framework","psr"],"created_at":"2024-09-24T20:01:54.216Z","updated_at":"2025-04-09T20:03:56.458Z","avatar_url":"https://github.com/davidecesarano.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Embryo Framework 3 skeleton application\nYou can use this skeleton application to start working on a new Embryo Framework 3 application.\n\n* Getting Started\n    * [Requirements](#requirements)\n    * [Installation](#installation)\n    * [Configuration](#configuration)\n    * [Directory Structure](#directory-structure)\n* Concepts\n    * [Life Cycle](#life-cycle)\n    * [PSR-7](#psr-7)\n    * [Middleware](#middleware)\n    * [Dependency Container](#dependency-container)\n* Application\n    * [Routing](#routing)\n    * [Middleware](#middleware-1)\n    * [Controllers](#controllers)\n    * [Service Providers](#service-providers)\n    * Models\n    * Views\n* Packages\n    * Validation\n    * Session\n    * Cache\n    * Http Client\n    * Translation\n    * Logger\n    * CORS\n    * Storage\n\n## Getting Started\n### Requirements\n* PHP \u003e= 7.2\n* URL Rewriting\n\n### Installation\nUsing Composer:\n```\n$ composer create-project davidecesarano/embryo [my-app-name]\n```\n\n### Configuration\nEmbryo utilizes the [DotEnv](https://github.com/vlucas/phpdotenv) PHP library. In a fresh Embryo installation, the root directory of your application will contain a `.env.example` file. When you install Embryo via Composer, this file will automatically be renamed to `.env`. \n\n### Directory Structure\n| Directory    | Description                                                                                                                                                                                     |\n|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| app          | Contains the core code of your application.  This directory contains a variety of additional directories such as `Controllers`, `Exceptions`, `Helpers`, `Middleware`, `Models` and `Services`. |\n| bootstrap    | Contains the files which bootstraps your application such as app instantiation, middleware, services and settings.                                                                              |\n| public       | Contains the entry point for all request (`index.php` file) and the `assets` directory.                                                                                                         |\n| routes       | Contains all of the route definitions for your application. By default, several route files are included with Embryo: `app.php` and `api.php`.                                                  |\n| storage      | Contains your logs (`logs`), compiled templates file (`views`), file based sessions (`sessions`), caches files (`cache`).                                                                       |\n| translations | Contains your language files.                                                                                                                                                                   |\n| views        | Contains the views files.                                                                                                                                                                       |\n\n## Concepts\n### Life Cycle\n* The app is instantiated in `bootstrap/app.php` with `Embryo\\Application` class. During instantiation, Embryo registers services for the dependencies (`bootstrap/services.php`), middlewares (`bootstrap/middleware.php`) and routes files (in `routes` directory). The application constructor accepts an optional settings array that configures the application’s behavior (`bootstrap/settings.php`).\n* In `routes` direcotry define routes using the application instance’s routing methods. These instance methods register a route with the application’s Router object. Each routing method returns the Route instance so you can immediately invoke the Route instance’s methods to add middleware or assign a name.\n* In `public/index.php` invoke the application instance's `run()` method. This method starts the following process:\n    * enter in middleware stack;\n    * run application (dispatches the current HTTP request to the appropriate application route object);\n    * exit middleware stack;\n    * send HTTP response.\n\n### PSR-7\nEmbryo supports [PSR-7](https://www.php-fig.org/psr/psr-7/) interfaces for its Request and Response objects.\n\n### Middleware\nYou can run code before and after your Embryo application to manipulate the Request and Response objects as you see fit. This is called middleware.\nA middleware implements the [PSR-15 Middleware Interface](https://www.php-fig.org/psr/psr-15/).\n\n### Dependency Container\nEmbryo uses an dependency container to prepare, manage, and inject application dependencies. Embryo supports containers that implement [PSR-11](http://www.php-fig.org/psr/psr-11/).\n\n## Application\n### Routing\nYou can define application routes using the application instance’s routing methods. Every method accepts two arguments:\n* The route pattern (with optional placeholders)\n* The route callback (a closure, a `class@method` string or a  `['class', 'method']` array)\n```php\nuse Embryo\\Http\\Message\\{Response, ServerRequest};\n\n// GET Route\n$app-\u003eget('/blog/{id}', function(ServerRequest $request, Response $response, int $id) {\n    return $response-\u003ewrite('This is post with id '.$id);\n}\n```\n\nEmbryo Routing supports GET, POST, PUT, PATCH, DELETE and OPTIONS request methods. Every request method corresponds to a method of the Router object: `get()`, `post()`, `put()`, `patch()`, `delete()` and `options()`.\nYou can use `all()` and `map()` methods for supporting all methods or specific route methods.\n\nSee full documentation: [Embryo Routing](https://github.com/davidecesarano/Embryo-Routing#usage).\n\n#### Register route files\nAll Embryo routes are defined in your route files, which are located in the `routes` directory. These files are automatically loaded by your application in `boostrap/app.php` file.\nIf you want create new ruote file, add it in routes directory and register it in `import()` method of the application instance in `boostrap/app.php` file:\n```php\n$app-\u003eimport([\n    root_path('bootstrap/services.php'),\n    root_path('bootstrap/middleware.php'),\n    root_path('routes/api.php'),\n    root_path('routes/app.php'),\n    root_path('routes/my_route_file.php')\n]);\n```\n\n### Middleware\nIn Embryo you may create a PSR-15 middleware in `app\\Middleware` directory. You may add middleware to application, to specific route or to route group.\n\n#### Application middleware\nIf you want register middleware for every HTTP request, add application middleware in `bootstrap\\middleware.php`. The `addMiddleware()` method accepts a string, an array or an instance of `Psr\\Http\\Server\\MiddlewareInterface`.\n\n```php\n$app-\u003eaddMiddleware(App\\Middleware\\MyCustomMiddleware::class);\n```\n\n#### Route middleware\nYou can use the `middleware()` method to assign one or more middleware at the route. The `middleware()` method accepts a string, an array or an instance of `Psr\\Http\\Server\\MiddlewareInterface`.\n```php\n$app-\u003eget('/users', function(ServerRequest $request, Response $response) {\n    //...\n})-\u003emiddleware('App\\MiddlewareTestMiddleware1::class', 'App\\MiddlewareTestMiddleware2::class');\n```\n#### Route group middleware\nIn addition to the routes, you can assign one or more middleware to a group and to individual routes within the group. The `middleware()` method accepts a string, an array or an instance of `Psr\\Http\\Server\\MiddlewareInterface`.\n```php\n$app-\u003eprefix('/api')-\u003emiddleware(App\\Middleware\\GroupMiddlewareTest::class)-\u003egroup(function($app) {\n    $app-\u003eget('/user/{id}', function(ServerRequest $request, Response $response, int $id) {\n        //...\n    })-\u003emiddleware(App\\Middleware\\RouteMiddlewareTest::class);\n});\n```\n### Controllers\nInstead of defining all of your request handling logic as closures in your route files, you may wish to organize this behavior using \"controller\" classes.\nLet's take a look at an example of a basic controller. Note that the controller extends the base controller class included with Embryo:\n```php\nnamespace App\\Controllers;\n\nuse Embryo\\Controller;\nuse Embryo\\Http\\Message\\Response;\n\nclass UserController extends Controller\n{\n    /**\n     * @param int $id\n     * @return Response\n     */\n    public function show(int $id): Response\n    {\n        return $this-\u003eresponse()-\u003ewrite($id);\n    }\n}\n```\nYou can define a route to this controller method like so:\n```php\nuse App\\Controllers\\UserController;\n\n$app-\u003eget('/user/{id}', [UserController::class, 'show']);\n```\nControllers are **required** to extend a base class. However, you will not have access to features such as the `get()`, `request()` and `response()` methods.\n\n#### Dependency Injection \u0026 Controllers\nYou are able to type-hint any dependencies your controller may need in its constructor. The declared dependencies will automatically be resolved and injected into the controller instance:\n```php\nnamespace App\\Controllers;\n\nuse Embryo\\Controller;\nuse Path\\To\\Service;\n\nclass UserController extends Controller\n{\n    /**\n     * @var Service $service\n     */\n    private $service;\n\n    /**\n     * @param Service $service\n     */\n    public function __construct(Service $service)\n    {\n        $this-\u003eservice = $service;\n    }\n}\n```\nIn addition to constructor injection, you may also type-hint dependencies on your controller's methods:\n```php\nnamespace App\\Controllers;\n\nuse Embryo\\Controller;\nuse Embryo\\Http\\Message\\ServerRequest;\n\nclass UserController extends Controller\n{\n    /**\n     * @param ServerRequest $request\n     */\n    public function store(ServerRequest $request)\n    {\n        //...\n    }\n}\n```\nIn addition, you may also to use the `get()` method of the base controller class:\n```php\nnamespace App\\Controllers;\n\nuse Embryo\\Controller;\nuse Path\\To\\Service;\n\nclass UserController extends Controller\n{\n    public function show()\n    {\n       $service = $this-\u003eget(Service::class);\n       //...\n    }\n}\n```\nBase controller class also has access to PSR-7 `request()` and `response()` methods:\n```php\nnamespace App\\Controllers;\n\nuse Embryo\\Controller;\nuse Embryo\\Http\\Message\\Response;\n\nclass UserController extends Controller\n{\n    /**\n     * @return Response\n     */\n    public function store(): Response\n    {\n       $params = $this-\u003erequest()-\u003egetParsedBody();\n       //...\n       return $this-\u003eresponse()-\u003ewrite('Hello!');\n    }\n}\n```\nAlternatively, you may to access to `request()` and `response()` helpers:\n```php\nnamespace App\\Controllers;\n\nuse Embryo\\Controller;\nuse Embryo\\Http\\Message\\Response;\n\nclass UserController extends Controller\n{\n    /**\n     * @return Response\n     */\n    public function store(): Response\n    {\n       $params = request()-\u003egetParsedBody();\n       return response()-\u003ewrite('Hello!');\n    }\n}\n```\n### Service Providers\nService providers are the central place of all Embryo application bootstrapping. Your own application, as well as all of Embryo's core services, are bootstrapped via service providers.\n#### Writing a service\nThe service providers era located in `app/Services` directory.\nAll service providers extend the `Embryo\\Container\\ServiceProvider` class and contains a `register` method. Within the register method, you should only bind things into the service container.\n```php\nnamespace App\\Services;\n\nuse Embryo\\Container\\ServiceProvider;\n\nclass TestService extends ServiceProvider\n{\n    /**\n     * Registers service provider.\n     *\n     * @return void\n     */\n    public function register()\n    {\n        $this-\u003econtainer-\u003eset('test', function($container){\n            return 'Hello from my test service';\n        });\n    }\n}\n```\n#### Registering a service\n### Models\n\n### Views\n\n## Packages\n\n### Validation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidecesarano%2Fembryo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidecesarano%2Fembryo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidecesarano%2Fembryo/lists"}