https://github.com/xtompie/middleware
https://github.com/xtompie/middleware
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/xtompie/middleware
- Owner: xtompie
- Created: 2021-12-15T18:05:36.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-15T19:40:57.000Z (over 4 years ago)
- Last Synced: 2025-07-15T22:16:11.817Z (about 1 year ago)
- Language: PHP
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Middleware
Middleware component
## Requiments
PHP >= 8.0
## Installation
Using [composer](https://getcomposer.org/)
```
composer require xtompie/middleware
```
## Docs
One middleware is a callble `fn(mixed $input, $next): mixed`
### Private service middleware
Service without middleware:
```php
dao->query([
"select" => "*", "from" => "article", "order" => "top DESC"
"offset" => $offset, "limit" => $limit
])
->mapInto(Article::class)
->pipeInto(ArticleCollection::class);
}
}
}
```
Service with middleware
```php
cache,
$this->logger,
fn ($args) => return $this->invoke(...$args)
],
func_get_args()
)
}
protected function invoke(int $limit, int $offset): ArticleCollection
{
return $this->dao->query([
"select" => "*", "from" => "article", "order" => "top DESC"
"offset" => $offset, "limit" => $limit
])
->mapInto(Article::class)
->pipeInto(ArticleCollection::class);
}
}
}
```
or with cached middleware chain
```php
middleware = $middleware->withMiddlewares([
$this->cache,
$this->logger,
fn ($args) => return $this->invoke(...$args)
])
}
public function __invoke(int $limit, int $offset): ArticleCollection
{
return ($this->middleware)(func_get_args());
}
protected function invoke(int $limit, int $offset): ArticleCollection
{
return $this->dao->query([
"select" => "*", "from" => "article", "order" => "top DESC"
"offset" => $offset, "limit" => $limit
])
->mapInto(Article::class)
->pipeInto(ArticleCollection::class);
}
}
}
```