Webscooby yii-web component ¶
Add supports PSR-7 http messages, and PSR-15 middlewares. Also add the ability to add parameters to views via objects, that implement ContentParametersInjectionInterface.
Installation ¶
- Use composer.
composer require webscooby/yii-web
- Add WebRequestFactory to bootstrap. For example, add to your config:
use Webscooby\Yii\Web\WebRequestFactory;
return [
'bootstrap' => [
WebRequestFactory::class
]
];
- Add psr-17 to configuration. Recommend using httpsoft/http-message
Using ¶
- For using middlewares attach MiddlewareDispatcherBehavior to controller or module. Example:
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;use Webscooby\Yii\Web\MiddlewareDispatcherBehavior;
class SomeController extends Controller {
public function behaviors(): array
{
return [
//Middleware can be added as class, object or callback
[
'class' => MiddlewareDispatcherBehavior::class,
'middlewares' => [SomeMiddleware::class, $someMiddleware]
],
//Also middleware can be limited for the specified action
[
'class' => MiddlewareDispatcherBehavior::class,
'actions' => ['index'],
'middlewares' => [
static function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
...
}
]
]
];
}
}
- For adding parameters to view, change view class and add your injections. Example:
<?php
use Webscooby\Security\User\UserViewInjection;
use Webscooby\Yii\Web\View;
return [
'components' => [
'view' => [
'class' => View::class,
'injections' => [
UserViewInjection::class,
static function(): array {
return [
...
];
},
$injector
]
]
]
];
Requirements ¶
- PHP 7.4 or higher.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.