Skip to content

Commit

Permalink
Update to 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Usbac committed Sep 14, 2021
1 parent b5d7c08 commit fbe71d1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Release Notes

## v4.1.0 (2021-09-14)

### Added

- Add optional parameter to Middleware closures with the `Wolff\Core\Http\Response` object.

### Fixed

- Environment override of some configuration values not working.

## v4.0.3 (2021-08-03)

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<p align="center">
<img src="https://travis-ci.org/Usbac/wolff.svg?branch=master">
<img src="https://img.shields.io/badge/stable-4.0.3-blue.svg">
<img src="https://img.shields.io/badge/stable-4.1.0-blue.svg">
<img src="https://img.shields.io/badge/license-MIT-orange.svg">
</p>

Expand Down Expand Up @@ -67,7 +67,7 @@ More info about the installation process in the [Docs - install](https://getwolf

### Bundle

_You can also download [here](https://github.com/Usbac/wolff/releases/download/v4.0.3/wolff-bundle.zip) the last bundle ready to be used._
_You can also download [here](https://github.com/Usbac/wolff/releases/download/v4.1.0/wolff-bundle.zip) the last bundle ready to be used._

## Example

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"framework", "php", "small", "web", "apps", "fast", "full", "db"
],
"type": "project",
"version": "4.0.3",
"version": "4.1.0",
"license": "MIT",
"support": {
"issues": "https://github.com/Usbac/Wolff/issues",
Expand Down
19 changes: 18 additions & 1 deletion docs/en/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ With that in mind, the middleware class has a `before` and `after` method to add
`before(string $url, \Closure $func): void`
`after(string $url, \Closure $func): void`

The function parameter must take two parameters, the Wolff request object (instance of `Wolff\Core\Http\Request`), and a function that when executed, will call the next middleware. So if this function isn't executed by that middleware, the middleware chain will stop right there.
The function parameter can take up to three arguments:

1. A Wolff request object (instance of `Wolff\Core\Http\Request`).
2. A function that when executed, will call the next middleware. So if this function isn't executed by that middleware, the middleware chain will stop right there.
3. A Wolff response object (instance of `Wolff\Core\Http\Response`).

The function parameter can return a string which will be appended to the response.

_Keep in mind that the middlewares are executed in the order they are added._

## Examples

### Simple message in all admin pages

```php
Middleware::before('admin/*', function($req, $next) {
echo 'Entering in an admin page';
Expand All @@ -28,6 +34,17 @@ Middleware::before('admin/*', function($req, $next) {

That will render the text 'Entering in an admin page' for every page inside `admin`, like `admin/settings`, `admin/panel` or `admin/product/info`.

### Setting content type in page

```php
Middleware::before('/api', function($req, $next, $res) {
$res->setHeader('Content-Type', 'application/json');
});
```

That will set the content-type header to `application/json` when accessing to the `api` page.

### Showing Hello world everywhere

```php
Middleware::before('*', function($req, $next) {
Expand Down

0 comments on commit fbe71d1

Please sign in to comment.