Framework Structure
Serverless-PHP is a focuses on component based development like angular framework, here we call them handlers.
Handlers are the classes which implements to the HandlerInterface. They must be created inside the ./src/app/ folder. Handlers contain business logic of your app. they must have a public method handle( ) which takes $_DATA as an input provided in the router file and returns an object of Response class, which can be returned to the API Gateway to respond the user. In the handlers class you can use the Request class to access the parameters of the request made by the end user of your application to the API Gateway.
We define all these handlers and routes to access them in the ./src/routes.php. In this file we use Router class to set routes.
Here is a simple example of Handler Class
./index.php - This file is executed when function is invoked
./main.php - You can specify global code in this file (It will be executed every time when the function is invoked, you can set global constants here.
./serverless.yml - Stores deployment configurations for serverless framework.
./php/conf.d/php.ini - php ini file, here you can specify your php configuration.
./src/routes.php - Stores your application routes.
./src/app/DemoHandler.php - Stores handler class for the /demo route specified in ./src/routes.php
./src/classes/Request.php - Request class which is used to get the request parameters sent by the Api Gateway to the Lambda Function.
./src/classes/Response.php - Response class for generating response in Api Gateway fromat.
./src/classes/Router.php - Router class for managing routing of the application.
./src/interfaces/HandlerInterface - Interface for route handler classes.
This is a simple introduction to project structure, we will learn about every component one by one in next sections.
Last updated
Was this helpful?