Skip to content

Commit

Permalink
fix aop
Browse files Browse the repository at this point in the history
  • Loading branch information
assert6 committed Apr 18, 2019
1 parent 454e2f3 commit bc6770e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/Aop/Aop.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ private function doPoint(
* @param string $class Class name
* @param string $method Method name
* @param array $annotations The annotations of method
* @return bool
*/
public function match(string $beanName, string $class, string $method, array $annotations)
public function match(string $beanName, string $class, string $method, array $annotations): bool
{
$shouldProxy = false;
foreach ($this->aspects as $aspectClass => $aspect) {
if (!isset($aspect['point'], $aspect['advice'])) {
continue;
Expand All @@ -209,8 +211,10 @@ public function match(string $beanName, string $class, string $method, array $an

if ($includeMath && ! $excludeMath) {
$this->map[$class][$method][] = $aspect['advice'];
$shouldProxy = true;
}
}
return $shouldProxy;
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/Bean/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,22 @@ private function set(string $name, ObjectDefinition $objectDefinition)
*/
private function proxyBean(string $name, string $className, $object)
{
if (!AspectCollector::hasClassname($className)) {
return $object;
}

/* @var Aop $aop */
$aop = App::getBean(Aop::class);

$rc = new \ReflectionClass($className);
$rms = $rc->getMethods();

$shouldProxy = false;
foreach ($rms as $rm) {
$method = $rm->getName();
$annotations = Collector::$methodAnnotations[$className][$method] ?? [];
$annotations = array_unique($annotations);
$aop->match($name, $className, $method, $annotations);
$shouldProxy |= $aop->match($name, $className, $method, $annotations);
}

if (! $shouldProxy) {
return $object;
}

$handler = new AopHandler($object);
Expand Down

0 comments on commit bc6770e

Please sign in to comment.