- Totally reworked Notes to allievate most conceptions problems. Removed old annotations artifacts too
This commit is contained in:
1 parent
996c8fa14a
commit
61b84bfd09
18 files changed
+495
-463
No files matched your search
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Notes\Common;
|
||||
|
||||
use Notes\Attribute\Ignore;
|
||||
|
||||
abstract class Reflected
|
||||
{
|
||||
public function hasIgnoreAttribute() : bool
|
||||
{
|
||||
return [] !== array_filter($this->attributes, fn($e) => $e->object instanceof Ignore);
|
||||
}
|
||||
|
||||
public function allowsNull() : bool
|
||||
{
|
||||
return empty($this->type) || $this->expectType("null");
|
||||
}
|
||||
|
||||
public function expectType(string $type) : bool
|
||||
{
|
||||
$type = strtolower($type);
|
||||
|
||||
foreach($this->getTypes() as $item) {
|
||||
|
||||
if ($type === "null") {
|
||||
if ($item->type === "null" || $item->nullable) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
elseif ($type === $item->type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getTypes() : array
|
||||
{
|
||||
return is_array($this->type) ? $this->type : [ $this->type ];
|
||||
}
|
||||
|
||||
public function typeFromReflection(\ReflectionProperty|\ReflectionParameter $property) : void
|
||||
{
|
||||
if ( $property->hasType() ) {
|
||||
$type = $property->getType();
|
||||
|
||||
if ($type instanceof \ReflectionUnionType ) {
|
||||
foreach($type->getTypes() as $item) {
|
||||
$this->type[] = new ReflectedPropertyType($item->getName(), $item->isBuiltIn(), $item->allowsNull());
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->type = new ReflectedPropertyType($type->getName(), $type->isBuiltIn(), $type->allowsNull());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user