codingculture / request-resolver-bundle
Joins the power of symfony OptionsResolver and Requests to create a clean API for your requests
Installs: 12 561
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 2
Open Issues: 1
Type:symfony-bundle
Requires
- symfony/config: ^4.0 || ^5.0 || ^6.0
- symfony/dependency-injection: ^4.0 || ^5.0 || ^6.0
- symfony/http-foundation: ^4.0 || ^5.0 || ^6.0
- symfony/http-kernel: ^4.0 || ^5.1.5 || ^6.0
- symfony/options-resolver: ^4.0 || ^5.0 || ^6.0
Requires (Dev)
- phpspec/phpspec: ^7.1
README
This Symfony bundle tries to make request assertion a little bit easier.
This bundle is still a work in progress.
PHP7.1+ only.
Usage
<?php
...
class SomeController extends Controller
{
public function someAction()
{
$request = $this->get('codingculture.requestresolver.resolver')->resolve(new SomeRequest());
$request->getId();
}
}
<?php
...
final class SomeRequest implements ResolvableRequestInterface
{
private $options = [];
public function getId(): string
{
return $this->options['id'];
}
public function defineOptions(OptionsResolver $resolver): OptionsResolver
{
$resolver->setRequired('id')
}
public function setOptions(array $options)
{
$this->options = $options;
}
public function getContentType(): string
{
return RequestResolver::CONTENT_TYPE_ALLOW_ALL;
}
}
If a user sent a bad request, an InvalidArgumentException (or an extension of it) will be thrown on resolve method.
Todo
- Write better docs