- Restricted source of permission
This commit is contained in:
parent
b093f53a6b
commit
237f0a30d2
@ -1,82 +0,0 @@
|
|||||||
<?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
|
|
||||||
{
|
|
||||||
# dump($this);
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAttributes(null|string|array $attributeType = null): array
|
|
||||||
{
|
|
||||||
if ($attributeType) {
|
|
||||||
$list = [];
|
|
||||||
|
|
||||||
foreach($this->attributes as $attribute) {
|
|
||||||
foreach((array) $attributeType as $type) {
|
|
||||||
if ($attribute->object instanceof $type) {
|
|
||||||
$list[] = $attribute;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_reverse($list);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_reverse($this->attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAttribute(string|array $attributeType): ?object
|
|
||||||
{
|
|
||||||
return $this->getAttributes($attributeType)[0] ?? null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -66,12 +66,11 @@ class SecurityHandler {
|
|||||||
$fromObject = $this->findAttributes(Attribute\Taxus::class, $className);
|
$fromObject = $this->findAttributes(Attribute\Taxus::class, $className);
|
||||||
$fromMethod = $this->findAttributes(Attribute\Taxus::class, $className, $methodName);
|
$fromMethod = $this->findAttributes(Attribute\Taxus::class, $className, $methodName);
|
||||||
|
|
||||||
if ($fromMethod || $fromObject) {
|
if ($fromMethod) {
|
||||||
if ( $this->taxusGrantPermission($fromMethod, ... $arguments) || $this->taxusGrantPermission($fromObject, ... $arguments) ) {
|
return $this->taxusGrantPermission($fromMethod, ... $arguments);
|
||||||
return true;
|
}
|
||||||
}
|
elseif ($fromObject) {
|
||||||
|
return $this->taxusGrantPermission($fromObject, ... $arguments);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user