Download the PHP package cubadevops/flexi without Composer
On this page you can find all versions of the php package cubadevops/flexi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cubadevops/flexi
More information about cubadevops/flexi
Files in cubadevops/flexi
Package flexi
Short Description The flexible framework that respects standards
License MIT
Informations about the package flexi
Flexi Framework
Flexi is a modular PHP framework designed to facilitate the development of scalable and maintainable applications. It leverages Dependency Injection (DI), a flexible routing system, CQRS and an event-driven architecture.
Table of Contents
- Features
- Structure
- Installation
- Configuration
- Services
- Routes
- Events and Listeners
- Queries
- Commands
- Usage
- Router
- Event System
- CQRS
- Contributing
- License
Features
- Modularity & Extensibility: Flexi offers a modular architecture that promotes code organization and reusability. Its extensibility allows developers to customize and extend functionality according to specific project requirements.
- Dependency Injection: Built-in support for Dependency Injection simplifies management and injection of dependencies, enhancing code maintainability and testability. DI in Flexi is implemented using a container that manages service with lazy loading instantiation.
- Flexible Routing: With a flexible routing system, developers can easily define and manage HTTP request handling, streamlining development of complex routing logic enriched with middleware support.
- Event-Driven Architecture: Flexi's event-driven architecture enables asynchronous handling of events by event listeners, fostering loose coupling and flexibility in application design.
- CQRS & Scalability: Support for Command Query Responsibility Segregation (CQRS) promotes scalability and performance optimization. Combined with features like asynchronous processing, Flexi facilitates the development of scalable applications capable of handling high traffic and data loads.
- Configuration via JSON: Configuration in Flexi is managed through JSON files, making it easy to define services, routes, events, queries, and commands. This approach simplifies configuration management and promotes consistency across projects. Json Schema will be implemented to validate the configuration files.
Structure
- Core: the
src/
directory contains the core classes and interfaces that make up the framework. - Modules: the
modules/
directory contains the all pieces of code that are not part of the core framework. Each module is a separate directory that contains its own controllers, services, and configuration files. There are plug and play plugins that can be added to the application to extend its functionality. - Config: the
src/Config/
andmodules/*/Config
directory contains the configuration files for the framework (routes
,commands
,queries
,event listeners
andservices
). - Console: the
bin/
directory contains the console application that can be run from the command line.(coming soon)
Installation
You can install Flexi Framework using Composer:
This command creates a minimal ready boilerplate application in the my-app
directory.
Steps after install
To get started with Flexi Framework, ensure you:
- Configure your web server to point to the
public
directory in the root of the project. - Deny direct access to any directory that is not the
public
directory. - Serve static files directly and route all other requests to the
index.php
file in thepublic
directory. - Set up the
.env
file with the necessary environment variables for your application.
After setup, browse to the URL of your application to see the welcome page. If you use the default configuration with Docker, you can access the application at http://localhost:8080.
Configuration
Configuration for Flexi is managed through JSON files. These files define services, routes, events, queries, and commands used within your application.
Services
Services are defined in the services.json
file located in the Config
directory. This file outlines how each service
should be instantiated, either directly or via factory methods.
Example
Note:
- The
alias
key is used to reference services by a different name. - Arguments prefixed with
@
are references to other services (can be alias as well) - Arguments prefixed with
ENV.
are references to environment variables. - Quoted strings without
@
orENV.
prefixes are treated as string values. - All other values are treated as the standard json_decode values.
- The
glob
key is used to include services frommodules
.
Routes
Routes are defined in the routes.json
file. Each route specifies the HTTP method, path, and the controller that should
handle the request.
Example
Note:
- Controllers should implement the
Psr\Http\Server\RequestHandlerInterface
interface if you want attach middlewares. However they must have ahandle
method that receives aPsr\Http\Message\ServerRequestInterface
and returns aPsr\Http\Message\ResponseInterface
. - The optional
parameters
key is used to define how many params should be passed to the request and if they are required. - The optional
middlewares
key is used to define the middlewares that should be executed before the controller. They are executed in the order they are defined and can stop the execution chain if they return a response directly or pass the request to the next middleware. - The
glob
key is used to include additional route definitions frommodules
.
Events and Listeners
Events and listeners are defined in the listeners.json
file. This file maps events to their corresponding listeners.
Example
Note:
- The
event
key can be a specific event name or a wildcard*
to listen to all events. - The listener class should implement the
CubaDevOps\Flexi\Domain\Interfaces\EventListenerInterface
interface.
Queries
Queries are defined in the queries.json
file. Each query handler is mapped to a specific DTO and an optional CLI
alias.
Example
Note:
- Handlers should implement the
CubaDevOps\Flexi\Domain\Interfaces\HandlerInterface
interface.
Commands
Commands are defined similarly to queries in the commands.json
file.
Example
Note:
- Handlers should implement the
CubaDevOps\Flexi\Domain\Interfaces\HandlerInterface
interface.
Usage
Router
The Router
class is responsible for managing routes and dispatching requests to the appropriate controllers.
Example Usage
Event System
The event system in Flexi is based on the EventBus pattern. Events are dispatched to listeners which can handle them accordingly.
Example
CQRS
Flexi implements the CQRS pattern with separate handling for commands and queries.
Command Example
Query Example
Controllers and Response
The response is a PSR-7 response object that can be returned from a controller or middleware. Controllers that extend the CubaDevOps\Flexi\Infrastructure\Classes\HttpHandler
have an easy way to build responses using the createResponse
method. If you you don't extend the HttpHandler
you can use a factory that implements Psr\Http\Message\ResponseFactoryInterface
interface to build the response. Flexi use the GuzzleHttp\Psr7\HttpFactory
as default factory.
Example
Middlewares
Middlewares are classes that can be executed before the controller. They can modify the request, response or stop the execution chain. Middlewares should implement the Psr\Http\Server\MiddlewareInterface
interface.
Example
Documentation
The documentation is available online at https://flexi.cubadevops.com (Under construction and not yet available).
Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes you would like to make.
License
Flexi is open-source software licensed under the MIT license.
All versions of flexi with dependencies
ext-json Version *
cubadevops/upgrader Version ^1.6
guzzlehttp/guzzle Version ^7.7
psr/cache Version ^1.0
psr/container Version ^2.0
psr/event-dispatcher Version ^1.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
psr/link Version ^1.0
psr/log Version ^1.1
psr/simple-cache Version ^1.0
symfony/error-handler Version ^5.4
vlucas/phpdotenv Version ^5.5
ext-pcntl Version *