Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection][ProxyManagerBridge] Added type-hints to LazyProxy classes and interfaces #32283

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
Show file tree
Hide file tree
Changes from all commits
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
Added type-hints to LazyProxy classes and interfaces.
  • Loading branch information
derrabus committed Jul 6, 2019
commit 211b718e28b63891153c284e3d20058898f37821
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator)
public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator)
{
return $this->factory->createProxy(
$this->factory->getGenerator()->getProxifiedClass($definition),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,14 @@ public function isProxyCandidate(Definition $definition): bool
/**
* {@inheritdoc}
*/
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null): string
public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode): string
fabpot marked this conversation as resolved.
Show resolved Hide resolved
{
$instantiation = 'return';

if ($definition->isShared()) {
$instantiation .= sprintf(' $this->%s[%s] =', $definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates', var_export($id, true));
}

if (null === $factoryCode) {
throw new \InvalidArgumentException(sprintf('Missing factory code to construct the service "%s".', $id));
}

$proxyClass = $this->getProxyClassName($definition);

return <<<EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,6 @@ public function getPrivatePublicDefinitions()
];
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Missing factory code to construct the service "foo".
*/
public function testGetProxyFactoryCodeWithoutCustomMethod()
{
$definition = new Definition(__CLASS__);
$definition->setLazy(true);
$this->dumper->getProxyFactoryCode($definition, 'foo');
}

public function testGetProxyFactoryCodeForInterface()
{
$class = DummyClass::class;
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bridge/ProxyManager/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": "^7.2.9",
"symfony/dependency-injection": "^4.4|^5.0",
"symfony/dependency-injection": "^5.0",
"ocramius/proxy-manager": "~2.1"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ interface InstantiatorInterface
*
* @return object
*/
public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator);
public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RealServiceInstantiator implements InstantiatorInterface
/**
* {@inheritdoc}
*/
public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator)
public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator)
{
return $realInstantiator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ public function isProxyCandidate(Definition $definition);
/**
* Generates the code to be used to instantiate a proxy in the dumped factory code.
*
* @param Definition $definition
* @param string $id Service identifier
* @param string $factoryCode The code to execute to create the service
*
* @return string
*/
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode);
public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode);

/**
* Generates the code for the lazy proxy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function isProxyCandidate(Definition $definition): bool
/**
* {@inheritdoc}
*/
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null): string
public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode): string
{
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ProxyHelper
/**
* @return string|null The FQCN or builtin name of the type hint, or null when the type hint references an invalid self|parent context
*/
public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, $noBuiltin = false)
public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, bool $noBuiltin = false)
{
if ($p instanceof \ReflectionParameter) {
$type = $p->getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function isProxyCandidate(Definition $definition)
return $definition->isLazy();
}

public function getProxyFactoryCode(Definition $definition, $id, $factoryCall = null)
public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode)
{
return " // lazy factory for {$definition->getClass()}\n\n";
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.