diff --git a/bin/migrate.php b/bin/migrate.php index 6b87215..db979f7 100755 --- a/bin/migrate.php +++ b/bin/migrate.php @@ -87,7 +87,7 @@ foreach ($iterator as $info) { $renderedArgs = ""; } - $attr[] = $attribute = sprintf(" #[%s%s]%s", $name, $renderedArgs ? "($renderedArgs)" : "", $renderedArgs ? " # migrated from: $args" : ""); + $attr[] = $attribute = sprintf("%s#[%s%s]%s", str_repeat(" ", strlen($line) - strlen(ltrim($line)) >= 4 ? 4 : 0), $name, $renderedArgs ? "($renderedArgs)" : "", $renderedArgs ? " # migrated from: $args" : ""); $newContent[] = $attribute; } diff --git a/src/ObjectReflection.php b/src/ObjectReflection.php index 81c5986..276c152 100644 --- a/src/ObjectReflection.php +++ b/src/ObjectReflection.php @@ -2,33 +2,42 @@ namespace Notes; +use Kash\HandleCacheTrait; +use Psr\SimpleCache\CacheInterface; use Reflector, ReflectionClass, ReflectionProperty, ReflectionMethod, ReflectionUnionType, ReflectionNamedType, ReflectionParameter; class ObjectReflection { + use HandleCacheTrait; protected string $classname; + protected ReflectionClass $classReflection; + public AnnotationReader $annotationReader; - public function __construct($class, AnnotationReader $annotationReader = null) { + public function __construct($class, AnnotationReader $annotationReader = null, ? CacheInterface $cache = null) { $this->classname = ltrim($class, '\\'); - $this->classReflection = $class instanceof ReflectionClass ? $class : new ReflectionClass($class); - $this->annotationReader = $annotationReader ?: AnnotationReader::fromClass($class); + $this->cache = $cache; + + #if ( ! $this->cache || ! $this->cache->has($class) ) { + $this->classReflection = $class instanceof ReflectionClass ? $class : new ReflectionClass($class); + $this->annotationReader = $annotationReader ?: AnnotationReader::fromClass($class); + # } } - public static function fromClass($class) : self + public static function fromClass($class, ? CacheInterface $cache = null) : self { - return new static($class); + return new static($class, null, $cache); } public function read(bool $fullUses = true, bool $fullObject = true, $fullMethod = true, $fullProperty = true) : array { - return [ + return $this->handleCaching(implode('', [ $this->classname, (int)$fullObject, (int) $fullMethod, (int) $fullProperty ]), fn() => [ 'uses' => $this->gatherUses($fullUses), 'class' => $this->gatherClass($fullObject), 'method' => $this->gatherMethods($fullMethod), 'property' => $this->gatherProperties($fullProperty), - ]; + ]); } public function gatherUses(bool $full = true) : array diff --git a/src/ObjectResolver.php b/src/ObjectResolver.php index efd4d57..2900314 100644 --- a/src/ObjectResolver.php +++ b/src/ObjectResolver.php @@ -2,6 +2,8 @@ namespace Notes; +use Psr\SimpleCache\CacheInterface; + class ObjectResolver { const KEY_ENTITY_NAME = 01; @@ -17,12 +19,12 @@ class ObjectResolver { public array $methods; - public function __construct(string $objectClass, bool $fullUses = true, bool $fullObject = true, $fullMethod = true, $fullProperty = true) + public function __construct(string $objectClass, bool $fullUses = true, bool $fullObject = true, $fullMethod = true, $fullProperty = true, ? CacheInterface $cache = null) { $this->objectClass = $objectClass; list($this->uses, $this->class, $this->methods, $this->properties) = array_values( - ObjectReflection::fromClass($objectClass)->read($fullUses, $fullObject, $fullMethod, $fullProperty) + ObjectReflection::fromClass($objectClass, $cache)->read($fullUses, $fullObject, $fullMethod, $fullProperty) ); $this->resolveAnnotations();