Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Use nette reflection, package is not deprecated it's just read only a…
Browse files Browse the repository at this point in the history
…nd compatible with nette 3 (#40)

* Use nette reflection again
  • Loading branch information
dakorpar authored May 13, 2019
1 parent bca7dc6 commit 3cc49c7
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 22 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"nette/di": "~3.0",
"nette/php-generator": "^3.0",
"nette/tokenizer": "~3.0",
"kdyby/annotations": "dev-master",
"nette/reflection": "^2.4",
"kdyby/annotations": "^2.6",
"symfony/property-access": "~4.2"
},
"require-dev": {
Expand Down Expand Up @@ -58,7 +59,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "3.0-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/Kdyby/Aop/DI/AopExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private function patchService($serviceId, Code\ClassType $advisedClass, Code\Php
{
static $publicSetup;
if ($publicSetup === NULL) {
$refl = new \ReflectionProperty('Nette\DI\ServiceDefinition', 'setup');
$refl = new Nette\Reflection\Property('Nette\DI\ServiceDefinition', 'setup');
$publicSetup = $refl->isPublic();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kdyby/Aop/DI/AspectsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function loadConfiguration()
}

if (!($config = $extension->getAspectsConfiguration()) || !$config instanceof AspectsConfig) {
$refl = new \ReflectionMethod($extension, 'getAspectsConfiguration');
$refl = Nette\Reflection\Method::from($extension, 'getAspectsConfiguration');
$given = is_object($config) ? 'instance of ' . get_class($config) : gettype($config);
throw new Kdyby\Aop\UnexpectedValueException("Method $refl is expected to return instance of Kdyby\\Aop\\DI\\AspectsConfig, but $given given.");
}
Expand Down
8 changes: 4 additions & 4 deletions src/Kdyby/Aop/JoinPoint/MethodInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public function getArguments()
}


public function getTargetObjectReflection(): \ReflectionClass
public function getTargetObjectReflection(): Nette\Reflection\ClassType
{
return new \ReflectionClass($this->targetObject);
return Nette\Reflection\ClassType::from($this->targetObject);
}


public function getTargetReflection(): \ReflectionMethod
public function getTargetReflection(): Nette\Reflection\Method
{
return new \ReflectionMethod($this->targetObject, $this->targetMethod);
return Nette\Reflection\Method::from($this->targetObject, $this->targetMethod);
}

}
8 changes: 4 additions & 4 deletions src/Kdyby/Aop/PhpGenerator/PointcutMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class PointcutMethod
*/
private $method;

public function __construct(\ReflectionMethod $from)
public function __construct(Nette\Reflection\Method $from)
{
$this->method = (new Code\Factory())->fromMethodReflection($from);
}

public static function from(\ReflectionMethod $from): PointcutMethod
public static function from(Nette\Reflection\Method $from): PointcutMethod
{
$method = new self($from);
$params = [];
Expand All @@ -65,7 +65,7 @@ public static function from(\ReflectionMethod $from): PointcutMethod
$params[$param->getName()] = $factory->fromParameterReflection($param);
}
$method->setParameters($params);
if ($from instanceof \ReflectionMethod) {
if ($from instanceof Nette\Reflection\Method) {
$isInterface = $from->getDeclaringClass()->isInterface();
$method->setStatic($from->isStatic());
$method->setVisibility($from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : ($isInterface ? NULL : 'public')));
Expand Down Expand Up @@ -249,7 +249,7 @@ public function beforePrint()
/**
* @throws \ReflectionException
*/
public static function expandTypeHints(\ReflectionMethod $from, PointcutMethod $method): PointcutMethod
public static function expandTypeHints(Nette\Reflection\Method $from, PointcutMethod $method): PointcutMethod
{
$parameters = $method->getParameters();
/** @var Code\Parameter[] $parameters */
Expand Down
2 changes: 1 addition & 1 deletion src/Kdyby/Aop/Pointcut/Matcher/WithinMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct($type)
$this->pattern = str_replace('\\*', '.*', preg_quote($type));

} else {
$this->type = (new \ReflectionClass($type))->getName();
$this->type = Nette\Reflection\ClassType::from($type)->getName();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Kdyby/Aop/Pointcut/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Method
const VISIBILITY_PRIVATE = 'private';

/**
* @var \ReflectionMethod
* @var Nette\Reflection\Method
*/
private $method;

Expand All @@ -44,7 +44,7 @@ class Method



public function __construct(\ReflectionMethod $method, ServiceDefinition $serviceDefinition)
public function __construct(Nette\Reflection\Method $method, ServiceDefinition $serviceDefinition)
{
$this->method = $method;
$this->serviceDefinition = $serviceDefinition;
Expand Down Expand Up @@ -141,7 +141,7 @@ public function getParameterNames(): array
return array_keys($this->method->getParameters());
}

public function unwrap(): \ReflectionMethod
public function unwrap(): Nette\Reflection\Method
{
return $this->method;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Kdyby/Aop/Pointcut/ServiceDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @property string $serviceId
* @property array|Method[] $openMethods
* @property \ReflectionClass $typeReflection
* @property Nette\Reflection\ClassType $typeReflection
*/
class ServiceDefinition
{
Expand All @@ -35,7 +35,7 @@ class ServiceDefinition
private $serviceDefinition;

/**
* @var \ReflectionClass
* @var Nette\Reflection\ClassType
*/
private $originalType;

Expand Down Expand Up @@ -64,7 +64,7 @@ public function __construct(Nette\DI\Definitions\Definition $def, $serviceId)
throw new Kdyby\Aop\InvalidArgumentException("Given service definition has unresolved class, please specify service type explicitly.");
}

$this->originalType = new \ReflectionClass($def->getType());
$this->originalType = Nette\Reflection\ClassType::from($def->getType());
$this->serviceId = $serviceId;
}

Expand All @@ -79,7 +79,7 @@ public function getServiceId()
}


public function getTypeReflection(): \ReflectionClass
public function getTypeReflection(): Nette\Reflection\ClassType
{
return $this->originalType;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/KdybyTests/Aop/Extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class ExtensionTest extends Tester\TestCase
private static function getAspects($service)
{
try {
$propRefl = (new \ReflectionClass($service))
$propRefl = (Nette\Reflection\ClassType::from($service))
->getProperty('_kdyby_aopAdvices'); // internal property

$propRefl->setAccessible(TRUE);
Expand Down
2 changes: 1 addition & 1 deletion tests/KdybyTests/Aop/ServiceDefinition.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ServiceDefinitionTest extends Tester\TestCase
public function testInheritedConstructor()
{
$definition = $this->createDefinition(InheritedClass::class);
Assert::equal($definition->getOpenMethods(), ['__construct' => new Pointcut\Method(new \ReflectionMethod(InheritedClass::class, '__construct'), $definition)]);
Assert::equal($definition->getOpenMethods(), ['__construct' => new Pointcut\Method(Nette\Reflection\Method::from(InheritedClass::class, '__construct'), $definition)]);
}


Expand Down

0 comments on commit 3cc49c7

Please sign in to comment.