Optimized code

This commit is contained in:
zcmzc 2019-06-25 17:44:33 +08:00
parent 24a61adf1a
commit c9ba887042

View File

@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Hyperf\Di\Annotation;
use Doctrine\Instantiator\Instantiator;
use Hyperf\Di\MetadataCollector;
class AspectCollector extends MetadataCollector
@ -29,11 +28,12 @@ class AspectCollector extends MetadataCollector
public static function setAround(string $aspect, array $classes, array $annotations): void
{
$savedClasses = static::get('classes.' . $aspect, []);
$savedAnnotations = static::get('annotations.' . $aspect, []);
$classes && static::set('classes.' . $aspect, array_replace($savedClasses, $classes));
$annotations && static::set('annotations.' . $aspect, array_replace($savedAnnotations, $annotations));
static::collectRules($aspect);
$classes && static::set('classes.' . $aspect, $classes);
$annotations && static::set('annotations.' . $aspect, $annotations);
static::$aspectRules[$aspect] = [
'classes' => $classes,
'annotations' => $annotations,
];
}
public static function getRule(string $aspect): array
@ -45,14 +45,4 @@ class AspectCollector extends MetadataCollector
{
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 ?? '',
];
}
}