Skip to content

Commit

Permalink
Merge branch '2.x' of github.com:ray-di/Ray.Di into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Dec 3, 2019
2 parents 47bb1d0 + de3935e commit dd17568
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,13 @@ private function setDefaultValue(\ReflectionParameter $parameter)
private function getType(\ReflectionParameter $parameter) : string
{
$type = $parameter->getType();
if ($type instanceof \ReflectionType && \in_array((string) $type, ['bool', 'int', 'string', 'array', 'resource', 'callable'], true)) {
if (! $type instanceof \ReflectionType) {
return '';
}
if (\in_array($type->getName(), ['bool', 'int', 'string', 'array', 'resource', 'callable'], true)) {
return '';
}

return (string) $type;
return $type->getName();
}
}
33 changes: 31 additions & 2 deletions src/InjectionPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Doctrine\Common\Annotations\Reader;
use Ray\Di\Di\Qualifier;

final class InjectionPoint implements InjectionPointInterface
final class InjectionPoint implements InjectionPointInterface, \Serializable
{
/**
* @var \ReflectionParameter
Expand All @@ -19,9 +19,28 @@ final class InjectionPoint implements InjectionPointInterface
*/
private $reader;

/**
* @var string
*/
private $pClass;

/**
* @var string
*/
private $pFunction;

/**
* @var string
*/
private $pName;

public function __construct(\ReflectionParameter $parameter, Reader $reader)
{
$this->parameter = $parameter;
$this->pFunction = $parameter->getDeclaringFunction()->name;
$class = $parameter->getDeclaringClass();
$this->pClass = $class instanceof \ReflectionClass ? $class->name : '';
$this->pName = $parameter->name;
$this->reader = $reader;
}

Expand All @@ -30,7 +49,7 @@ public function __construct(\ReflectionParameter $parameter, Reader $reader)
*/
public function getParameter() : \ReflectionParameter
{
return $this->parameter;
return $this->parameter ?? new \ReflectionParameter([$this->pClass, $this->pFunction], $this->pName);
}

/**
Expand Down Expand Up @@ -79,4 +98,14 @@ public function getQualifiers() : array

return $qualifiers;
}

public function serialize() : string
{
return serialize([$this->reader, $this->pClass, $this->pFunction, $this->pName]);
}

public function unserialize($serialized)
{
[$this->reader, $this->pClass, $this->pFunction, $this->pName] = unserialize($serialized);
}
}

0 comments on commit dd17568

Please sign in to comment.