An open API service indexing awesome lists of open source software.

https://github.com/xtompie/middleware


https://github.com/xtompie/middleware

Last synced: 5 months ago
JSON representation

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);
}
}
}

```