-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b76035
commit edcb88f
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace App\Service; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Lle\CredentialBundle\Contracts\CredentialWarmupInterface; | ||
use Lle\CredentialBundle\Repository\CredentialRepository; | ||
use Lle\CredentialBundle\Service\CredentialWarmupTrait; | ||
use Lle\CruditBundle\Contracts\CrudConfigInterface; | ||
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; | ||
|
||
class CruditCredentialWarmup implements CredentialWarmupInterface | ||
{ | ||
use CredentialWarmupTrait; | ||
|
||
public function __construct( | ||
#[TaggedIterator('crudit.config')] protected iterable $cruditConfigs, | ||
protected CredentialRepository $credentialRepository, | ||
Check failure on line 18 in src/Service/CruditCredentialWarmup.php GitHub Actions / PHPStan
|
||
protected EntityManagerInterface $entityManager, | ||
) { | ||
} | ||
|
||
public function warmUp(): void | ||
{ | ||
$i = 0; | ||
$keys = [ | ||
CrudConfigInterface::INDEX, | ||
CrudConfigInterface::SHOW, | ||
CrudConfigInterface::EDIT, | ||
CrudConfigInterface::NEW, | ||
CrudConfigInterface::DELETE, | ||
CrudConfigInterface::EXPORT, | ||
]; | ||
foreach ($this->cruditConfigs as $cruditConfig) { | ||
$rubrique = $cruditConfig->getName(); | ||
|
||
// Page Roles | ||
foreach ($keys as $key) { | ||
$this->checkAndCreateCredential( | ||
'ROLE_' . $cruditConfig->getName() . '_' . $key, | ||
$rubrique, | ||
$cruditConfig->getName() . $key, | ||
$i++ | ||
); | ||
} | ||
|
||
// Actions Roles | ||
foreach ($cruditConfig->getListActions() as $action) { | ||
if ($action->getPath()->getRole()) { | ||
$this->checkAndCreateCredential( | ||
$action->getPath()->getRole(), | ||
$rubrique, | ||
$action->getLabel(), | ||
$i++ | ||
); | ||
} | ||
} | ||
// Item Actions Roles | ||
foreach ($cruditConfig->getItemActions() as $action) { | ||
if ($action->getPath()->getRole()) { | ||
$this->checkAndCreateCredential( | ||
$action->getPath()->getRole(), | ||
$rubrique, | ||
$action->getLabel(), | ||
$i++ | ||
); | ||
} | ||
} | ||
|
||
// Tabs Roles | ||
foreach ($cruditConfig->getTabs() as $key => $brickConfigList) { | ||
foreach ($brickConfigList as $brickConfig) { | ||
if ($brickConfig->getRole()) { | ||
$this->checkAndCreateCredential( | ||
$brickConfig->getRole(), | ||
$rubrique, | ||
$key . "/" . strtolower(str_replace("ROLE_${rubrique}_","",$brickConfig->getRole())), | ||
$i++ | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Service; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Lle\CredentialBundle\Contracts\CredentialWarmupInterface; | ||
use Lle\CredentialBundle\Repository\CredentialRepository; | ||
use Lle\CredentialBundle\Service\CredentialWarmupTrait; | ||
use Lle\CruditBundle\Registry\MenuRegistry; | ||
|
||
class FrontMenuCredentialWarmup implements CredentialWarmupInterface | ||
{ | ||
use CredentialWarmupTrait; | ||
|
||
public function __construct( | ||
protected MenuRegistry $menuRegistry, | ||
protected CredentialRepository $credentialRepository, | ||
protected EntityManagerInterface $entityManager | ||
) { | ||
} | ||
|
||
public function warmUp(): void | ||
{ | ||
$rubrique = "Menu"; | ||
$i = 0; | ||
foreach ($this->menuRegistry->getElements("") as $menuItem) { | ||
if ($menuItem->getRole()) { | ||
$this->checkAndCreateCredential( | ||
$menuItem->getRole(), | ||
$rubrique, | ||
"Menu " . str_replace("menu.", "", $menuItem->getId()), | ||
$i++ | ||
); | ||
} | ||
foreach ($menuItem->getChildren() as $submenuItem) { | ||
if ($submenuItem->getRole()) { | ||
$this->checkAndCreateCredential( | ||
$submenuItem->getRole(), | ||
$rubrique, | ||
"↳ Sous menu " . str_replace("menu.", "", $submenuItem->getId()), | ||
$i++ | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} |