- WIP on attributes ; on testing phase
This commit is contained in:
1 parent
a876ea9045
commit
87b9ea2e2a
3 files changed
+21
-10
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user