mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-04 04:37:46 +08:00
Optimized code
This commit is contained in:
parent
24a61adf1a
commit
c9ba887042
@ -12,7 +12,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Hyperf\Di\Annotation;
|
namespace Hyperf\Di\Annotation;
|
||||||
|
|
||||||
use Doctrine\Instantiator\Instantiator;
|
|
||||||
use Hyperf\Di\MetadataCollector;
|
use Hyperf\Di\MetadataCollector;
|
||||||
|
|
||||||
class AspectCollector extends MetadataCollector
|
class AspectCollector extends MetadataCollector
|
||||||
@ -29,11 +28,12 @@ class AspectCollector extends MetadataCollector
|
|||||||
|
|
||||||
public static function setAround(string $aspect, array $classes, array $annotations): void
|
public static function setAround(string $aspect, array $classes, array $annotations): void
|
||||||
{
|
{
|
||||||
$savedClasses = static::get('classes.' . $aspect, []);
|
$classes && static::set('classes.' . $aspect, $classes);
|
||||||
$savedAnnotations = static::get('annotations.' . $aspect, []);
|
$annotations && static::set('annotations.' . $aspect, $annotations);
|
||||||
$classes && static::set('classes.' . $aspect, array_replace($savedClasses, $classes));
|
static::$aspectRules[$aspect] = [
|
||||||
$annotations && static::set('annotations.' . $aspect, array_replace($savedAnnotations, $annotations));
|
'classes' => $classes,
|
||||||
static::collectRules($aspect);
|
'annotations' => $annotations,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRule(string $aspect): array
|
public static function getRule(string $aspect): array
|
||||||
@ -45,14 +45,4 @@ class AspectCollector extends MetadataCollector
|
|||||||
{
|
{
|
||||||
return static::$aspectRules;
|
return static::$aspectRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function collectRules(string $aspect)
|
|
||||||
{
|
|
||||||
$instantiator = new Instantiator();
|
|
||||||
$instance = $instantiator->instantiate($aspect);
|
|
||||||
static::$aspectRules[$aspect] = [
|
|
||||||
'classes' => $instance->classes ?? '',
|
|
||||||
'annotations' => $instance->annotations ?? '',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user