- Added old migration script, reworked security attribute also

This commit is contained in:
Dave Mc Nicoll committed 2025-05-23 19:03:39 +00:00
1 parent fa4fe32277
commit 0db34fe228
3 files changed
+26 -141

No files matched your search

+2
View File
@@ -45,6 +45,8 @@ abstract class Reflected
$type = $property->getType();
if ($type instanceof \ReflectionUnionType ) {
$this->type = [];
foreach($type->getTypes() as $item) {
$this->type[] = new ReflectedPropertyType($item->getName(), $item->isBuiltIn(), $item->allowsNull());
}
+24 -12
View File
@@ -40,29 +40,41 @@ class SecurityHandler {
return true;
}
public function taxus(string $className, string $methodName, object $user = null) : ? ResponseInterface
public function taxus(string $className, string $methodName, ... $arguments) : ? ResponseInterface
{
$fromObject = $this->findAttributes(Attribute\Taxus::class, $className);
$fromMethod = $this->findAttributes(Attribute\Taxus::class, $className, $methodName);
if ($fromMethod || $fromObject) {
if ( $this->taxusGrantPermission($fromMethod, $user) || $this->taxusGrantPermission($fromObject, $user) ) {
return null;
}
$granted = $this->hasGrantPermission($className , $methodName, ...$arguments);
if ($granted) {
return null;
}
else {
if ($this->unauthorizeResponse) {
if ($this->unauthorizeResponse instanceof ResponseInterface) {
return $this->unauthorizeResponse;
}
return call_user_func_array($this->unauthorizeResponse, [ $user, ['method' => $fromMethod, 'object' => $fromObject ], $className, $methodName ]);
return call_user_func_array($this->unauthorizeResponse, [ ...$arguments, ['method' => $methodName, 'object' => $className ], $className, $methodName ]);
}
else {
throw new \ErrorException("Unauthorized response given.");
}
}
}
return null;
public function hasGrantPermission(string $className, string $methodName, ... $arguments) : bool
{
$fromObject = $this->findAttributes(Attribute\Taxus::class, $className);
$fromMethod = $this->findAttributes(Attribute\Taxus::class, $className, $methodName);
if ($fromMethod || $fromObject) {
if ( $this->taxusGrantPermission($fromMethod, ... $arguments) || $this->taxusGrantPermission($fromObject, ... $arguments) ) {
return true;
}
return false;
}
return true;
}
protected function findAttributes(string $attribute, string $class, ? string $method = null) : array
@@ -90,10 +102,10 @@ class SecurityHandler {
return [];
}
protected function taxusGrantPermission(array $attributeList, object $user = null) : bool
protected function taxusGrantPermission(array $attributeList, ...$arguments) : bool
{
foreach ($attributeList as $item) {
if ( $grant = $this->taxus->granted($item->privilege, $user, $item) ) {
if ( $grant = $this->taxus->granted($item->privilege, ... array_merge($arguments, [ $item ])) ) {
if (is_bool($grant) ? $grant : $grant === TaxusGrantEnum::Authorized) {
return true;
}