forked from ray-di/Ray.Di
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
41 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,31 +4,27 @@ | |
|
||
namespace Ray\Di; | ||
|
||
use Doctrine\Common\Annotations\Reader; | ||
use Ray\Aop\ReflectionClass; | ||
use Ray\Di\Di\PostConstruct; | ||
use ReflectionClass; | ||
use ReflectionMethod; | ||
|
||
final class AnnotatedClass | ||
{ | ||
/** @var Reader */ | ||
private $reader; | ||
|
||
/** @var AnnotatedClassMethods */ | ||
private $injectionMethod; | ||
|
||
public function __construct(Reader $reader) | ||
public function __construct() | ||
{ | ||
$this->reader = $reader; | ||
$this->injectionMethod = new AnnotatedClassMethods($reader); | ||
$this->injectionMethod = new AnnotatedClassMethods(); | ||
} | ||
|
||
/** | ||
* Return factory instance | ||
* | ||
* @phpstan-param ReflectionClass<object> $class Target class reflection | ||
*/ | ||
public function getNewInstance(\Ray\Aop\ReflectionClass $class): NewInstance | ||
|
||
public function getNewInstance(ReflectionClass $class): NewInstance | ||
Check failure on line 27 in src/di/AnnotatedClass.php GitHub Actions / sa / PHPStan
|
||
{ | ||
$setterMethods = new SetterMethods([]); | ||
$methods = $class->getMethods(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,10 +103,12 @@ public function to(string $class): self | |
/** | ||
* Bind to constructor | ||
* | ||
* @param class-string $class class name | ||
* @param class-string<T> $class class name | ||
* @param array<string, string>|string $name "varName=bindName,..." or [$varName => $bindName, $varName => $bindName...] | ||
* | ||
* @throws ReflectionException | ||
* | ||
* @template T of object | ||
*/ | ||
public function toConstructor(string $class, $name, ?InjectionPoints $injectionPoints = null, ?string $postConstruct = null): self | ||
{ | ||
|
@@ -116,7 +118,9 @@ public function toConstructor(string $class, $name, ?InjectionPoints $injectionP | |
|
||
$this->untarget = null; | ||
$postConstructRef = $postConstruct ? new ReflectionMethod($class, $postConstruct) : null; | ||
$this->bound = (new DependencyFactory())->newToConstructor(new ReflectionClass($class), $name, $injectionPoints, $postConstructRef); | ||
/** @var ReflectionClass<object> $reflection */ | ||
$reflection = new ReflectionClass($class); | ||
Check failure on line 122 in src/di/Bind.php GitHub Actions / sa / PHPStan
|
||
$this->bound = (new DependencyFactory())->newToConstructor($reflection, $name, $injectionPoints, $postConstructRef); | ||
$this->container->add($this); | ||
|
||
return $this; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
namespace Ray\Di; | ||
|
||
use Ray\Aop\ReflectionClass; | ||
use Ray\ServiceLocator\ServiceLocator; | ||
use ReflectionMethod; | ||
|
||
use function assert; | ||
|
@@ -20,7 +19,7 @@ final class DependencyFactory | |
*/ | ||
public function newAnnotatedDependency(ReflectionClass $class): Dependency | ||
Check failure on line 20 in src/di/DependencyFactory.php GitHub Actions / sa / PHPStan
|
||
{ | ||
$annotateClass = new AnnotatedClass(ServiceLocator::getReader()); | ||
$annotateClass = new AnnotatedClass(); | ||
$newInstance = $annotateClass->getNewInstance($class); | ||
$postConstruct = $annotateClass->getPostConstruct($class); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters