Download the PHP package pocket-framework/framework without Composer
On this page you can find all versions of the php package pocket-framework/framework. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pocket-framework/framework
More information about pocket-framework/framework
Files in pocket-framework/framework
Package framework
Short Description A small PHP framework that just tries to get out of the way
License Apache-2.0
Informations about the package framework
Pocket Framework
A small PHP framework that tries to get out of the way
Pocket Framework is a small PHP framework that is designed to get out of the way. Write your code using plain PHP Objects for almost anything, sprinkle in a few attributes, and you are all set!
Installation
Installation is done using composer:
Requirements
- PHP 8.2 or higher
Usage
Pocket Framework requires a small bootstrapping script to get running, as the framework requires an HTTP dispatcher (nikic/fast-route is included) as well as a PSR-11-compatible service container. We recommend using php-di/php-di.
Configuration
Pocket Framework currently does not have much configuration outside of defining your PSR-11 service container (which is done on a library-by-library basis), and telling the PocketFramework\Framework\Router\RouteProcessor where to look for your controller and actions. Otherwise you declare your controllers (if you are using the Model-View-Controller pattern) or Actions (if you are using Action-Domain-Responder pattern) via PHP attributes.
If you have PSR-15 middleware you can add them to the routing stack as well. These middlewares can help with authentication, logging, or anything else you need to do before a route is dispatched.
Declaring Routes
Pocket Framework allows you to declare routes as PHP attributes on generic PHP objects, using either the Model-View-Controller (MVC) pattern or the Action-Domain-Responder (ADR) pattern. You can even mix-and-match! The only difference is where the attributes live.
Pocket Framework ships with two attributes - PocketFramework\Framework\Router\RouteGroup and PocketFramework\Framework\Router\RouteInfo. The RouteInfo attribute declares that a method or class should be attached to a specific route, and lets you define the path, methods, and any route-specific middleware that is needed. RouteGroup is used to define a base-route for a class that contains multiple routes that share a common base URI.
If you are using ADR, where one class generally handles one action or route, you can use RouteInfo directly on the invokable class to map it to a route. Pocket Framework will then invoke that class when the route is accessed.
If you are using MVC, where an object may handle multiple routes, you can instead use RouteInfo on a class method to map the method to a route. If you combine it with a RouteGroup attribute, all the routes in the class will share a common base URI.
Both RouteGroup and RouteInfo allow you to have dynamic chunks in the URL. You can add {<identifier>:<regex>} in the URL to specify a value to capture and compare against. This value will be passed to the associated route for use in your business logic. Keep in mind that no matter the regex, the value is passed into the controller as a string as a URL itself is a string.
All versions of framework with dependencies
psr/http-server-middleware Version ^1.0
nikic/fast-route Version ^1.3
laminas/laminas-diactoros Version ^3.8
laminas/laminas-httphandlerrunner Version ^2.1
psr/container Version ^2.0