Skip to content

Commit

Permalink
CredentialWarmup
Browse files Browse the repository at this point in the history
  • Loading branch information
sebheitzmann committed Oct 24, 2023
1 parent 2b76035 commit edcb88f
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/Service/CruditCredentialWarmup.php
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

Check failure on line 12 in src/Service/CruditCredentialWarmup.php

View workflow job for this annotation

GitHub Actions / PHPStan

Class App\Service\CruditCredentialWarmup implements unknown interface Lle\CredentialBundle\Contracts\CredentialWarmupInterface.
{
use CredentialWarmupTrait;

Check failure on line 14 in src/Service/CruditCredentialWarmup.php

View workflow job for this annotation

GitHub Actions / PHPStan

Class App\Service\CruditCredentialWarmup uses unknown trait Lle\CredentialBundle\Service\CredentialWarmupTrait.

public function __construct(
#[TaggedIterator('crudit.config')] protected iterable $cruditConfigs,
protected CredentialRepository $credentialRepository,

Check failure on line 18 in src/Service/CruditCredentialWarmup.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter $credentialRepository of method App\Service\CruditCredentialWarmup::__construct() has invalid type Lle\CredentialBundle\Repository\CredentialRepository.

Check failure on line 18 in src/Service/CruditCredentialWarmup.php

View workflow job for this annotation

GitHub Actions / PHPStan

Property App\Service\CruditCredentialWarmup::$credentialRepository has unknown class Lle\CredentialBundle\Repository\CredentialRepository as its type.
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(

Check failure on line 39 in src/Service/CruditCredentialWarmup.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method App\Service\CruditCredentialWarmup::checkAndCreateCredential().
'ROLE_' . $cruditConfig->getName() . '_' . $key,
$rubrique,
$cruditConfig->getName() . $key,
$i++
);
}

// Actions Roles
foreach ($cruditConfig->getListActions() as $action) {
if ($action->getPath()->getRole()) {
$this->checkAndCreateCredential(

Check failure on line 50 in src/Service/CruditCredentialWarmup.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method App\Service\CruditCredentialWarmup::checkAndCreateCredential().
$action->getPath()->getRole(),
$rubrique,
$action->getLabel(),
$i++
);
}
}
// Item Actions Roles
foreach ($cruditConfig->getItemActions() as $action) {
if ($action->getPath()->getRole()) {
$this->checkAndCreateCredential(

Check failure on line 61 in src/Service/CruditCredentialWarmup.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method App\Service\CruditCredentialWarmup::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(

Check failure on line 74 in src/Service/CruditCredentialWarmup.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method App\Service\CruditCredentialWarmup::checkAndCreateCredential().
$brickConfig->getRole(),
$rubrique,
$key . "/" . strtolower(str_replace("ROLE_${rubrique}_","",$brickConfig->getRole())),
$i++
);
}
}
}
}
}
}
47 changes: 47 additions & 0 deletions src/Service/FrontMenuCredentialWarmup.php
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

Check failure on line 11 in src/Service/FrontMenuCredentialWarmup.php

View workflow job for this annotation

GitHub Actions / PHPStan

Class App\Service\FrontMenuCredentialWarmup implements unknown interface Lle\CredentialBundle\Contracts\CredentialWarmupInterface.
{
use CredentialWarmupTrait;

Check failure on line 13 in src/Service/FrontMenuCredentialWarmup.php

View workflow job for this annotation

GitHub Actions / PHPStan

Class App\Service\FrontMenuCredentialWarmup uses unknown trait Lle\CredentialBundle\Service\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++
);
}
}
}
}
}

0 comments on commit edcb88f

Please sign in to comment.