Download the PHP package crazy-goat/micro-app without Composer
On this page you can find all versions of the php package crazy-goat/micro-app. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download crazy-goat/micro-app
More information about crazy-goat/micro-app
Files in crazy-goat/micro-app
Package micro-app
Short Description A lightweight micro PHP application framework
License MIT
Homepage https://github.com/crazy-goat/micro-app
Informations about the package micro-app
MicroApp PHP Framework
MicroApp is a minimalist PHP micro-backend framework built to run on top of the fast Workerman HTTP server. It enables you to quickly create lightweight micro-backends using Symfony commands and attribute-based routing.
Features
- Minimal setup, rapid development for micro-backends
- Runs on Workerman for high-performance HTTP serving
- Attribute-based routes using PHP 8+ attributes
- Symfony Console integration for easy command management
- Configurable port, interface, and worker count
- Event Dispatcher for custom event handling
- Middleware Support for request/response processing
Getting Started
Dependencies
- PHP 8.1+
- Workerman
- Symfony Console
- FastRoute
Installation
Install MicroApp via Composer:
Creating a Micro-Backend
- Create a Symfony Application using
MicroApp:
- Your controller must have at least one function with the
#[Route]attribute. - Each route function must accept a
Requestand return aResponse.
- Run your application:
Example:
Configuration Options
| Option | Description | Default |
|---|---|---|
--port |
Port to listen on | 8080 |
--listen |
Interface/address to bind | 0.0.0.0 |
--workers |
Number of PHP worker processes | 4 |
--reuse_port |
Use SO_REUSEPORT if available | false |
--dev |
Reload server every request. Use for development | false |
--max-reques |
Reload server N request. Use this if you have memory leaks. | null |
--reload-on-exception |
If exception appears in code, reload worker. | false |
Server commands
server start- Start the serverserver stop- Stop the serverserver restart- Restart the serverserver reload- Reload the serverserver status- Show the server statusserver connections- Show the server connections
Routing
To register a route, you must use the #[Route] attribute. You can provide HTTP method(s) (e.g., GET, POST) and a path.
These parameters are directly passed to the nikic/FastRoute's addRoute method, allowing you to define flexible and powerful routing rules.
Accessing the route parameters is as simple as accessing the $request->context['router']['arguments']['name'] array.
Event Dispatcher
MicroApp includes a simple Event Dispatcher that allows you to hook into various lifecycle events of the application.
You can register listeners using the onEvent() method on your MicroApp instance.
Available Events
| Event Name | Parameters |
|---|---|
onServerStart |
Worker $worker |
onMessage |
TcpConnection $connection, Request $request |
onResponse |
TcpConnection $connection, Request $request, Response $response |
onWorkerStart |
Worker $worker |
onConnect |
TcpConnection $connection |
onClose |
TcpConnection $connection |
onWorkerReload |
Worker $worker |
Example
Middlewares
MicroApp supports middleware to process requests before they reach your controller and to modify responses before they are sent.
Middlewares are classes that implement CrazyGoat\MicroApp\Middlewares\MiddlewareInterface.
When registering middleware, you must provide an index. By default, the router middleware's index is 1000.
Middlewares with an index lower than 1000 will execute before the router, allowing pre-processing of the request,
while those with a higher index will execute after the router. Note that only one middleware can be registered per index.
Example Middleware
License
MIT
Credits
All versions of micro-app with dependencies
ext-pcntl Version *
ext-posix Version *
symfony/console Version ^7.0
nikic/fast-route Version ^1.3
workerman/workerman Version ^5.1