- Totally reworked Notes to allievate most conceptions problems. Removed old annotations artifacts too

This commit is contained in:
mcndave committed 2024-05-09 19:43:08 +00:00
1 parent 996c8fa14a
commit 61b84bfd09
18 files changed
+495 -463

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
<?php
namespace Notes;
use Notes\Common\ReflectedAttribute;
use Reflector, ReflectionClass, ReflectionProperty, ReflectionMethod;
class AttributeReader
{
const PHP_TYPES = [ "string", "int", "float", "object", "double", "closure", ];
public static function reflectAttributes(\Reflector $reflect) : array
{
$list = [];
foreach($reflect->getAttributes() as $attribute) {
try {
$list[] = new ReflectedAttribute(
tag: substr(strrchr($attribute->getName(), "\\"), 1),
object: $attribute->newInstance(),
arguments: $attribute->getArguments(),
);
}
catch(\Throwable $e) {
throw new \Exception(sprintf("%s for %s in file '%s'", $e->getMessage(), $reflect, static::getObjectName($reflect)));
}
}
return $list;
}
protected static function getObjectName(Reflector $reflect) : string
{
switch(true) {
case $reflect instanceof ReflectionMethod :
case $reflect instanceof ReflectionProperty :
return $reflect->class . "::" . $reflect->name;
case $reflect instanceof ReflectionClass :
return $reflect->name;
}
throw new \InvalidArgumentException("Given reflector is not supported within getObjectName().");
}
protected static function getObjectNamespace(Reflector $reflect) : string
{
switch(true) {
case $reflect instanceof ReflectionMethod :
case $reflect instanceof ReflectionProperty :
return $reflect->getDeclaringClass()->getNamespaceName();
case $reflect instanceof ReflectionClass :
return $reflect->getNamespaceName();
}
throw new \InvalidArgumentException("Given reflector is not supported within getObjectNamespace().");
}
}