- Prepping 8.1 migration
This commit is contained in:
1 parent
00ebf3381f
commit
e97df353ae
18 files changed
+18
-392
No files matched your search
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Annotation;
|
||||
|
||||
interface Annotation {}
|
||||
@@ -1,103 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Annotation;
|
||||
|
||||
use Reflector, ReflectionClass, ReflectionProperty, ReflectionMethod;
|
||||
|
||||
/**
|
||||
* This class exists while waiting for the official RFC [ https://wiki.php.net/rfc/annotations_v2 ]
|
||||
*/
|
||||
class AnnotationReader
|
||||
{
|
||||
const PHP_TYPES = [ "string", "int", "float", "object", "double", "closure", ];
|
||||
|
||||
public string $class;
|
||||
|
||||
public function __construct($class) {
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
public static function fromClass($class) : self
|
||||
{
|
||||
return new static($class);
|
||||
}
|
||||
|
||||
public function getProperty(ReflectionProperty $property)
|
||||
{
|
||||
return $this->parseDocComment($property);
|
||||
}
|
||||
|
||||
public function getClass(ReflectionClass $class)
|
||||
{
|
||||
return $this->parseDocComment($class);
|
||||
}
|
||||
|
||||
public function getMethod(ReflectionMethod $method)
|
||||
{
|
||||
return $this->parseDocComment($method);
|
||||
}
|
||||
|
||||
protected function parseDocComment(Reflector $reflect)
|
||||
{
|
||||
$namespace = $this->getObjectNamespace($reflect);
|
||||
$tags = [];
|
||||
|
||||
foreach(preg_split("/\r\n|\n|\r/", $reflect->getDocComment()) as $line) {
|
||||
$line = ltrim($line, "* \t\/");
|
||||
$line = rtrim($line, "\t ");
|
||||
|
||||
if ( substr($line, 0, 1) === '@' ) {
|
||||
$line = ltrim($line, '@');
|
||||
|
||||
$open = strpos($line, "(");
|
||||
$close = strrpos($line, ")");
|
||||
|
||||
if ( ! in_array(false, [ $open, $close ], true) && ( ++$open !== $close ) ) {
|
||||
$arguments = substr($line, $open, $close - $open);
|
||||
|
||||
try {
|
||||
$tags[] = [
|
||||
'tag' => substr($line, 0, $open - 1),
|
||||
'arguments' => eval("namespace $namespace; return [ $arguments ];" ),
|
||||
];
|
||||
}
|
||||
catch(\Throwable $error) {
|
||||
throw new \InvalidArgumentException("An error occured while parsing annotation from '" . $this->getObjectName($reflect) . "' : @$line -- " . $error->getMessage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tags[] = [
|
||||
'tag' => $line,
|
||||
'arguments' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
protected 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;
|
||||
}
|
||||
}
|
||||
|
||||
protected 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
namespace Ulmus\Annotation\Classes;
|
||||
|
||||
class Collation implements \Ulmus\Annotation\Annotation {
|
||||
class Collation implements \Notes\Annotation {
|
||||
|
||||
}
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
namespace Ulmus\Annotation\Classes;
|
||||
|
||||
class Method implements \Ulmus\Annotation\Annotation {
|
||||
class Method implements \Notes\Annotation {
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Annotation\Classes;
|
||||
|
||||
class Table implements \Ulmus\Annotation\Annotation {
|
||||
class Table implements \Notes\Annotation {
|
||||
|
||||
public string $name;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Annotation\Property;
|
||||
|
||||
class Field implements \Ulmus\Annotation\Annotation {
|
||||
class Field implements \Notes\Annotation {
|
||||
|
||||
public string $type;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Annotation\Property;
|
||||
|
||||
class Filter implements \Ulmus\Annotation\Annotation {
|
||||
class Filter implements \Notes\Annotation {
|
||||
|
||||
public string $method;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Annotation\Property;
|
||||
|
||||
class FilterJoin implements \Ulmus\Annotation\Annotation {
|
||||
class FilterJoin implements \Notes\Annotation {
|
||||
|
||||
public string $method;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Annotation\Property;
|
||||
|
||||
class GroupBy implements \Ulmus\Annotation\Annotation {
|
||||
class GroupBy implements \Notes\Annotation {
|
||||
|
||||
public array $fields = [];
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Annotation\Property;
|
||||
|
||||
class Join implements \Ulmus\Annotation\Annotation {
|
||||
class Join implements \Notes\Annotation {
|
||||
|
||||
public string $type;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Annotation\Property;
|
||||
|
||||
class OrderBy implements \Ulmus\Annotation\Annotation {
|
||||
class OrderBy implements \Notes\Annotation {
|
||||
|
||||
public string $field;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Annotation\Property;
|
||||
|
||||
class Relation implements \Ulmus\Annotation\Annotation {
|
||||
class Relation implements \Notes\Annotation {
|
||||
|
||||
public string $type;
|
||||
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
namespace Ulmus\Annotation\Property\Relation;
|
||||
|
||||
class Ignore implements \Ulmus\Annotation\Annotation {}
|
||||
class Ignore implements \Notes\Annotation {}
|
||||
@@ -4,7 +4,7 @@ namespace Ulmus\Annotation\Property;
|
||||
|
||||
use Ulmus\Query;
|
||||
|
||||
class Where implements \Ulmus\Annotation\Annotation {
|
||||
class Where implements \Notes\Annotation {
|
||||
|
||||
public /* stringable */ $field;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Annotation\Property;
|
||||
|
||||
class WithJoin implements \Ulmus\Annotation\Annotation {
|
||||
class WithJoin implements \Notes\Annotation {
|
||||
|
||||
protected array $joins;
|
||||
|
||||
|
||||
Reference in new issue
Block a user