Skip to content

Commit

Permalink
[general] Upgrading simple auth to use casbin (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jul 23, 2024
1 parent b8c4a8e commit 1f0894a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"cweagans/composer-patches": "^1.7",
"doctrine/orm": "2.15.*",
"fastybird/metadata-library": "dev-main",
"fastybird/simple-auth": "^0.12",
"fastybird/simple-auth": "^0.13",
"nette/bootstrap": "^3.1",
"nette/application": "^3.1",
"nette/di": "^3.0",
Expand Down
19 changes: 19 additions & 0 deletions src/Subscribers/EntityDiscriminator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
use FastyBird\Library\Application\Exceptions;
use ReflectionClass;
use function array_keys;
use function end;
use function explode;
use function in_array;
use function sprintf;
use function str_contains;
use function strtolower;

/**
* @package FastyBird:ApplicationLibrary!
Expand Down Expand Up @@ -82,6 +86,10 @@ public function loadClassMetadata(ORM\Event\LoadClassMetadataEventArgs $event):
}
}

if (!in_array($classReflection->name, $extendedDiscriminatorMap, true)) {
$extendedDiscriminatorMap[$this->getShortName($classReflection->name)] = $classReflection->name;
}

foreach ($extendedDiscriminatorMap as $name => $classString) {
$metadata->addDiscriminatorMapClass($name, $classString);
}
Expand Down Expand Up @@ -166,4 +174,15 @@ private function ensureDiscriminatorIsUnique(string $discriminator, ReflectionCl
}
}

private function getShortName(string $className): string
{
if (!str_contains($className, '\\')) {
return strtolower($className);
}

$parts = explode('\\', $className);

return strtolower(end($parts));
}

}

0 comments on commit 1f0894a

Please sign in to comment.