Skip to content

Added an ArgumentResolver with clean extension point #18308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cs fixes
  • Loading branch information
HeahDude authored and Iltar van der Berg committed Apr 1, 2016
commit cee5106960c38fe70585c1c9e9634a663f6f5456
9 changes: 4 additions & 5 deletions UPGRADE-3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ HttpKernel
deprecated and will be removed in Symfony 4.0. The inline fragment
renderer should be used with object attributes.

* The `ControllerResolver::getArguments()` method is deprecated and will be
removed in 4.0. If you have your own `ControllerResolverInterface`
implementation, you should replace this method by implementing the
`ArgumentResolverInterface` and injecting it in the `HttpKernel`, or using
the `ArgumentResolver` and injecting this in the `HttpKernel`.
* The `ControllerResolver::getArguments()` method has been deprecated and will
be removed in 4.0. If you have your own `ControllerResolverInterface`
implementation, you should inject either an `ArgumentResolverInterface`
instance or the new `ArgumentResolver` in the `HttpKernel`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something similar (but then removed instead of deprecated) should be added to UPGRADE-4.0.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be easier to document this in the PR where it's actually removed?


Serializer
----------
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
<argument type="service" id="logger" on-invalid="ignore" />
</service>

<service id="argument_metadata_factory" class="Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory" public="false" />

<service id="argument_resolver" class="Symfony\Component\HttpKernel\Controller\ArgumentResolver" public="false">
<argument type="service" id="argument_metadata_factory" />
<argument type="collection" />
</service>

<service id="argument_metadata_factory" class="Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory" public="false" />

<service id="argument_value_resolver.argument_from_attribute" class="Symfony\Component\HttpKernel\Controller\ArgumentValueResolver\ArgumentFromAttributeResolver" public="false">
<tag name="controller_argument.value_resolver" priority="100" />
</service>
Expand Down
10 changes: 6 additions & 4 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ CHANGELOG
3.1.0
-----
* deprecated passing objects as URI attributes to the ESI and SSI renderers
* Added a `LegacyArgumentResolver` with `getArguments()` and the corresponding interface `ArgumentResolverInterface`
* Deprecated `ControllerResolver::getArguments()`, which uses the `LegacyArgumentResolver` as BC layer by extending it
* The `HttpKernel` now accepts an additional argument for an `ArgumentResolverInterface`
* Added the `ArgumentResolver` which features an extension point to resolve arguments in a more dynamic way
* added `Symfony\Component\HttpKernel\Controller\LegacyArgumentResolver`
* deprecated `ControllerResolver::getArguments()`
* made `ControllerResolver` extend the `LegacyArgumentResolver` for BC
* added `Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface`
* added `Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface` as argument to `HttpKernel`
* added `Symfony\Component\HttpKernel\Controller\ArgumentResolver`

3.0.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactoryInterface;

/**
* Responsible for the resolving of arguments passed to an action.
* Responsible for resolving the arguments passed to an action.
*
* @author Iltar van der Berg <kjarli@gmail.com>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Symfony\Component\HttpFoundation\Request;

/**
* An ArgumentResolverInterface implementation knows how to determine the
* An ArgumentResolverInterface instance knows how to determine the
* arguments for a specific action.
*
* @author Fabien Potencier <fabien@symfony.com>
Expand All @@ -29,7 +29,7 @@ interface ArgumentResolverInterface
*
* @return array An array of arguments to pass to the controller
*
* @throws \RuntimeException When value for argument given is not provided
* @throws \RuntimeException When no value could be provided for a required argument
*/
public function getArguments(Request $request, $controller);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just checked a bunch of files including the ones you mentioned and I think it's github, all files I've checked have a blank line in the end for me

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
* Grabs a non-variadic value from the request and returns it.
* Yields a non-variadic argument's value from the request attributes.
*
* @author Iltar van der Berg <kjarli@gmail.com>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
* Returns the default value defined in the action signature if present and no value has been given.
* Yields the default value defined in the action signature when no value has been given.
*
* @author Iltar van der Berg <kjarli@gmail.com>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
* Supports the same instance as the request object passed along.
* Yields the same instance as the request object passed along.
*
* @author Iltar van der Berg <kjarli@gmail.com>
*/
Expand All @@ -27,7 +27,7 @@ final class RequestResolver implements ArgumentValueResolverInterface
*/
public function supports(Request $request, ArgumentMetadata $argument)
{
return $argument->getType() === Request::class || is_subclass_of($request, $argument->getType());
return $argument->getType() === Request::class || is_subclass_of(Request::class, $argument->getType());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
* Grabs the variadic value from the request and returns it.
* Yields a variadic argument's values from the request attributes.
*
* @author Iltar van der Berg <kjarli@gmail.com>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
interface ArgumentValueResolverInterface
{
/**
* Whether this resolver can resolve can resolve the value for the given ArgumentMetadata.
* Whether this resolver can resolve the value for the given ArgumentMetadata.
*
* @param Request $request
* @param ArgumentMetadata $argument
Expand All @@ -34,8 +34,6 @@ public function supports(Request $request, ArgumentMetadata $argument);
/**
* Yield the possible value(s).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically, this method is returning an iterator of the possible values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "Yields"

*
* An implementation must yield at least one value.
*
* @param Request $request
* @param ArgumentMetadata $argument
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getController(Request $request)
/**
* {@inheritdoc}
*
* @deprecated this method is deprecated as of 3.1 and will be removed in 4.0. Implement the ArgumentResolverInterface or extend the LegacyArgumentResolver instead.
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0. Implement the ArgumentResolverInterface or extend the LegacyArgumentResolver instead.
*/
public function getArguments(Request $request, $controller)
{
Expand All @@ -95,7 +95,7 @@ public function getArguments(Request $request, $controller)
}

/**
* @deprecated this method is deprecated as of 3.1 and will be removed in 4.0. Implement the ArgumentResolverInterface or extend the LegacyArgumentResolver instead.
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0. Implement the ArgumentResolverInterface or extend the LegacyArgumentResolver instead.
*/
protected function doGetArguments(Request $request, $controller, array $parameters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LegacyArgumentResolver implements ArgumentResolverInterface
*/
public function getArguments(Request $request, $controller)
{
// only trigger the deprecation notice if actually used, the ControllerResolver still extends this for BC reasons
// only trigger the deprecation notice if actually used, the ControllerResolver still extends it for BC
@trigger_error(sprintf('The %s class is deprecated since 3.1 and will be removed in 4.0. Please use the %s instead.', __CLASS__, ArgumentResolver::class), E_USER_DEPRECATED);

if (is_array($controller)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(ControllerResolverInterface $resolver, Stopwatch $st
$this->stopwatch = $stopwatch;
$this->argumentResolver = $argumentResolver;

// required for BC reasons
// BC
if (null === $this->argumentResolver) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is for BC you should add a comment so we don't forget to remove the block in 4.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be implied by the getArguments method deprecation but adding it just in case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

$this->argumentResolver = $resolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function createArgumentMetadata($controller)
}

foreach ($reflection->getParameters() as $param) {
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param), $this->isVariadic($param), $this->hasDefaulValue($param), $this->getDefaulValue($param));
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param), $this->isVariadic($param), $this->hasDefaultValue($param), $this->getDefaultValue($param));
}

return $arguments;
Expand All @@ -59,7 +59,7 @@ private function isVariadic(\ReflectionParameter $parameter)
*
* @return bool
*/
private function hasDefaulValue(\ReflectionParameter $parameter)
private function hasDefaultValue(\ReflectionParameter $parameter)
{
return $parameter->isDefaultValueAvailable();
}
Expand All @@ -71,9 +71,9 @@ private function hasDefaulValue(\ReflectionParameter $parameter)
*
* @return mixed|null
*/
private function getDefaulValue(\ReflectionParameter $parameter)
private function getDefaultValue(\ReflectionParameter $parameter)
{
return $this->hasDefaulValue($parameter) ? $parameter->getDefaultValue() : null;
return $this->hasDefaultValue($parameter) ? $parameter->getDefaultValue() : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to throw an exception with the ArgumentMetadata if the factory set it to null already ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You lost me here for a second, what do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got confused because the ArgumentMetadataFactory always set the default value to null whether it has some, but throwing an exception in ArgumentMetadata while trying to get that null from the resolver makes sense indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it this way because of "If the parameter is not optional a ReflectionException will be thrown."

}

/**
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy