-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAclResourceSyncCommand.php
More file actions
75 lines (62 loc) · 1.99 KB
/
Copy pathAclResourceSyncCommand.php
File metadata and controls
75 lines (62 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace ADT\FancyAdmin\Console;
use ADT\FancyAdmin\Model\Entities\AclRole;
use ADT\FancyAdmin\Model\Entities\Identity;
use ADT\FancyAdmin\Model\Entities\Profile;
use ADT\FancyAdmin\Model\Queries\Factories\AclRoleQueryFactory;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use Exception;
use Nette\Security\IResource;
use Nette\Security\Resource;
use ReflectionEnum;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(name: 'fancyadmin:acl-resource:sync', description: 'AclResource sync')]
class AclResourceSyncCommand extends \ADT\FancyAdmin\Console\Command
{
public function __construct(
private readonly EntityManagerInterface $em,
)
{
parent::__construct();
}
/**
* @throws NonUniqueResultException
* @throws Exception
*/
protected function executeCommand(InputInterface $input, OutputInterface $output): int
{
$autoloadPath = __DIR__ . '/../../../vendor/composer/autoload_classmap.php';
$classMap = require $autoloadPath;
$foundEnums = [];
foreach ($classMap as $className => $filePath) {
// 💡 Kontrola, že soubor opravdu obsahuje enum — bez autoloadu
if (!file_exists($filePath)) {
continue;
}
$contents = file_get_contents($filePath);
if ($contents === false) {
continue;
}
// rychlá kontrola, že v souboru je enum (před autoloadem)
if (!preg_match('/\benum\b/', $contents)) {
continue;
}
if (!enum_exists($className, false)) {
continue;
}
var_dump($className);
$ref = new ReflectionEnum($className);
// buď implementuje interface, nebo má getResourceId() (např. z traitu)
if ($ref->implementsInterface(Resource::class) || $ref->hasMethod('getResourceId')) {
$foundEnums[] = $className;
}
}
var_dump($foundEnums);
return Command::SUCCESS;
}
}