Added type-hints to LazyProxy classes and interfaces.
This commit is contained in:
parent
b057243f10
commit
211b718e28
@ -38,7 +38,7 @@ class RuntimeInstantiator implements InstantiatorInterface
|
||||
/**
|
||||
* {@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),
|
||||
|
@ -48,7 +48,7 @@ class ProxyDumper implements DumperInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null): string
|
||||
public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode): string
|
||||
{
|
||||
$instantiation = 'return';
|
||||
|
||||
@ -56,10 +56,6 @@ class ProxyDumper implements DumperInterface
|
||||
$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
|
||||
|
@ -109,17 +109,6 @@ class ProxyDumperTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
@ -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": {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -30,13 +30,9 @@ interface DumperInterface
|
||||
/**
|
||||
* 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.
|
||||
|
@ -33,7 +33,7 @@ class NullDumper implements DumperInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null): string
|
||||
public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -88,7 +88,7 @@ class DummyProxyDumper implements ProxyDumper
|
||||
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";
|
||||
}
|
||||
|
Reference in New Issue
Block a user