Download the PHP package tobento/app-http without Composer
On this page you can find all versions of the php package tobento/app-http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tobento/app-http
More information about tobento/app-http
Files in tobento/app-http
Package app-http
Short Description App http support.
License MIT
Homepage https://www.tobento.ch
Informations about the package app-http
App Http
Http, routing, middleware and session support for the app.
Table of Contents
- Getting Started
- Requirements
- Documentation
- App
- Http Boot
- Http Config
- Request And Response
- Http Functions
- Swap PSR-7 And PSR-17 Implementation
- Requester And Responser Boot
- Middleware Boot
- Add Middleware via Config
- Add Middleware via Boot
- Middleware Aliases
- Middleware Groups
- Available Middleware
- Previous Uri Session Middleware
- Secure Policy Headers Middleware
- Routing Boot
- Routing via Boot
- Domain Routing
- Route Handler
- Route List Command
- Session Boot
- Session Config
- Session Lifecycle
- Session Error Handling
- Cookies Boot
- Cookies Config
- Cookies Usage
- Cookies Encryption
- Error Handler Boot
- Http Exceptions
- Render Exception Views
- Handle Other Exceptions
- Prioritize Error Handler
- Credits
Getting Started
Add the latest version of the app http project running this command.
Requirements
- PHP 8.0 or greater
Documentation
App
Check out the App Skeleton if you are using the skeleton.
You may also check out the App to learn more about the app in general.
Http Boot
The http boot does the following:
- PSR-7 implementations
- PSR-17 implementations
- installs and loads http config file
- base and current uri implementation
- http error handling implementation
- emits response
Http Config
Check out to change needed values.
Request And Response
You may access the PSR-7 and PSR-17 interfaces by the app:
Check out the Uri Service to learn more about the base and current uri.
Http Functions
The following Http functions are available:
Swap PSR-7 And PSR-17 Implementation
You might swap the PSR-7 and PSR-17 implementation to any alternative.\ Check out the App - Customization to learn more about it.
Requester And Responser Boot
The requester and responser boot does the following:
- RequesterInterface implementation
- ResponserInterface implementation and adds its middleware
Check out the Requester Service to learn more about it.
Check out the Responser Service to learn more about it.
Responser Messages
Messages will be translated if you have installed the App Message - Translating Messages.
Added Middleware
Class | Description |
---|---|
Tobento\Service\Responser\Middleware\Responser::class | Adds the responser to the request attributes. |
Tobento\Service\Responser\Middleware\ResponserMergeInput::class | Merges the responser input with the request input. |
Middleware Boot
The middleware boot does the following:
- PSR-15 HTTP handlers (middleware) implementation
- dispatches middleware
Check out the Middleware Service to learn more about the middleware implementation.
Add Middleware via Config
You can configure middleware in the config file which are applied to all routes and requests:
Add Middleware via Boot
You might create a boot for adding middleware:
Middleware Aliases
Add Aliases via Config
You can configure middleware aliases in the config file :
Middleware Groups
Add Groups via Config
You can configure middleware groups in the config file :
Available Middleware
Previous Uri Session Middleware
The middleware is automatically added by the Session Boot which stores the uri history in the session.
Get Previous Uri
Exclude From Previous Uri History
You may exclude a certain uri from the history by adding a header on the response:
Secure Policy Headers Middleware
This middleware will add the following secure policy headers to the response:
In the file:
Using inline scripts and styles
The middleware will add a header with a nonce for and . Therefore, to allow inline scripts or styles you must add the nonce to the html:
If using the App View bundle, you can retrieve the nonce from the view:
Routing Boot
The routing boot does the following:
- boots http and middleware boot
- RouterInterface implementation
- adds routing macro
- adds http error handler for routing exceptions
Check out the Routing Service to learn more about the routing.
Routing via Boot
You might create a boot for defining routes:
Then adding your routes boot on the app:
Domain Routing
You may specify the domains for routing in the file.
Check out the Routing Service - Domain Routing section to learn more about domain routing.
Route Handler
You may add route handlers to interact with the route handling.
Here is some benefits of adding handlers:
- you may cache responses
- on certain requests you may throw an exception to be later catched by an error handler (e.g. validation)
- and much more
First, create a route handler:
Finally, add the route handler:
The only handler added is the with a priority of .
Route List Command
If you have installed the App Console you may run the route:list command providing an overview of all the routes that are defined by your application:
Displays only specific routes by its name with additional information:
Session Boot
The session boot does the following:
- SessionInterface implementation
- adds session middleware
Check out the Session Service to learn more about the session in general.
Session Config
Check out to change needed values.
Session Lifecycle
The session gets started and saved by the session middleware whereby interacting with session data is available after.
Session Error Handling
You may add an error handler for handling exceptions caused by the session middleware.
You may handle these exceptions with the Error Handler - Handle Other Exceptions instead.
Check out the Throwable Handlers to learn more about handlers in general.
Cookies Boot
The cookies boot does the following:
- implements cookie interfaces based on cookies config file
- adds middleware based on cookies config file
Check out the Cookie Service to learn more it.
Cookies Config
Check out to change needed values.
Cookies Usage
Read and write cookies
Check out the Cookie Values to learn more it.
Check out the Cookies to learn more it.
Cookies Encryption
First install the app-encryption bundle:
Then, just boot the if you want to encrypt and decrypt all cookies values. That's all.
Whitelist cookie
To whitelist a cookie (disable encryption), use the after the booting:
Configuration
The encrypting and decrypting is done with the implemented processed by the specified middleware in the file.
You may check out the App Encryption to learn more about it.
Error Handler Boot
By default, the error handler will render exceptions in json or plain text format. If you want to render exception views to support html and xml formats check out the Render Exception Views section.
It handles the following exceptions as well as the Http Exceptions:
As Code | Exception |
---|---|
404 | |
403 | |
403 | |
403 | |
500 | Any other not handled before |
Http Exceptions
There are several HTTP exceptions you can throw from your controllers and middleware, which are handled by the default error handler:
As Code | Exception |
---|---|
any | |
400 | |
401 | |
403 | |
404 | |
429 |
Example:
Render Exception Views
In order to render exceptions in html or xml format, the must be available within the app. You might install the App View bundle or just implement the :
It renders the following view if exist:
View | Description |
---|---|
Any specific error with the named code. | |
Any specific error with the named code in xml format. | |
If specific does not exist. | |
If specific does not exist in xml format. |
Handle Other Exceptions
You might handle other exceptions by just exending the error handler:
Messages will be translated if you have installed the App Translation using uses the as resource name. Check out the Translation Resources and Translation Files Resources to learn more about it.
And boot your custom error handler instead of the default:
Prioritize Error Handler
You may create an error handler and use the constant to define a priority.
The default priority is , higher gets handled first.
And boot your error handler:
Credits
- Tobias Strub
- All Contributors
All versions of app-http with dependencies
psr/container Version ^2.0
psr/http-message Version ^1.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
psr/http-factory Version ^1.0
nyholm/psr7 Version ^1.4
nyholm/psr7-server Version ^1.0
laminas/laminas-httphandlerrunner Version ^1.4
tobento/app Version ^1.0
tobento/app-migration Version ^1.0
tobento/service-middleware Version ^1.0.2
tobento/service-routing Version ^1.0.5
tobento/service-session Version ^1.0.1
tobento/service-cookie Version ^1.0.1
tobento/service-requester Version ^1.0.2
tobento/service-responser Version ^1.0
tobento/service-uri Version ^1.0.1
tobento/service-config Version ^1.0.3
tobento/service-migration Version ^1.0
tobento/service-error-handler Version ^1.0
tobento/service-translation Version ^1.0.3