Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: PHPStan

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:
phpstan:
Expand All @@ -13,20 +13,20 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [8.1]
php_version: [8.4]

steps:
- uses: actions/checkout@v2

- name: "Install dependencies with Composer"
uses: php-actions/composer@v5
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php_version }}
version: 2
args: --profile --ignore-platform-reqs

- name: 'PHPStan Static Analysis'
uses: php-actions/phpstan@v2
uses: php-actions/phpstan@v3
with:
configuration: tests/phpstan.neon
memory_limit: 256M
6 changes: 3 additions & 3 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: PHPUnit

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:
phpunit:
Expand All @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [8.1]
php_version: [8.4]

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Validate

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:
php-coding-standard:
Expand All @@ -23,7 +23,7 @@ jobs:

- name: 'Cache Composer packages'
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"license": "MIT",
"require": {
"php": "^8.0",
"symfony/console": "^6.0 || ^7.0",
"symfony/console": "^7.0 || ^8.0",
"2lenet/crudit-bundle": "*",
"2lenet/credential-bundle": "*",
"2lenet/dashboard2-bundle": "*",
"symfony/framework-bundle": "^6.0 || ^7.0",
"symfony/http-kernel": "^6.0 || ^7.0",
"symfony/framework-bundle": "^7.0 || ^8.0",
"symfony/http-kernel": "^7.0 || ^8.0",
"doctrine/orm": "^2.15 || ^3.0",
"doctrine/doctrine-bundle": "^2.0",
"symfony/security-bundle": "^6.0 || ^7.0",
"symfony/security-bundle": "^7.0 || ^8.0",
"doctrine/persistence": "^2.0 || ^3.0"
},
"autoload": {
Expand Down
41 changes: 41 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"/>
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>*/lib/Doctrine/Common/Annotations/DocParser.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints.UsedLongTypeHint"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace.UseFromSameNamespace"/>
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" type="bool" value="true"/>
</properties>
</rule>

<rule ref="Generic.Files.LineLength">
<exclude name="Generic.Files.LineLength"/>
</rule>

<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint">
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint"/>
</rule>

<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.NewlineBeforeOpenBrace">
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.NewlineBeforeOpenBrace"/>
</rule>

<rule ref="PSR12"/>

<file>src/</file>
<exclude-pattern>src/Resources/skeleton/**/*$</exclude-pattern>


</ruleset>
1 change: 0 additions & 1 deletion src/DependencyInjection/LleCruditPlatformExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Lle\CruditPlatformBundle\DependencyInjection;

use Lle\CredentialBundle\Contracts\CredentialWarmupInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
Expand Down
141 changes: 91 additions & 50 deletions src/Service/CruditCredentialWarmup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
use Lle\CredentialBundle\Contracts\CredentialWarmupInterface;
use Lle\CredentialBundle\Repository\CredentialRepository;
use Lle\CredentialBundle\Service\CredentialWarmupTrait;
use Lle\CruditBundle\Contracts\BrickConfigInterface;
use Lle\CruditBundle\Contracts\CrudConfigInterface;
use Lle\CruditBundle\Dto\Field\Field;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;

class CruditCredentialWarmup implements CredentialWarmupInterface
{
use CredentialWarmupTrait;

public function __construct(
#[TaggedIterator('crudit.config')] protected iterable $cruditConfigs,
#[AutowireIterator('crudit.config')] protected iterable $cruditConfigs,
protected CredentialRepository $credentialRepository,
protected EntityManagerInterface $entityManager,
) {
Expand All @@ -25,52 +24,33 @@ public function __construct(
public function warmUp(): void
{
$i = 0;
$keys = [
CrudConfigInterface::INDEX,
CrudConfigInterface::SHOW,
CrudConfigInterface::EDIT,
CrudConfigInterface::NEW,
CrudConfigInterface::DELETE,
CrudConfigInterface::EXPORT,
];
/** @var CrudConfigInterface $cruditConfig */
foreach ($this->cruditConfigs as $cruditConfig) {
/** @var CrudConfigInterface $cruditConfig */
/** @var string $rubrique */
$rubrique = $cruditConfig->getName();

foreach (CrudConfigInterface::BASIC_ACTIONS_KEYS as $role => $label) {
$this->createRoleForAction($cruditConfig, $role, $rubrique, $label, $i++);
}

// Page Roles
foreach ($keys as $key) {
$this->checkAndCreateCredential(
'ROLE_' . $cruditConfig->getName() . '_' . $key,
$rubrique,
$cruditConfig->getName() . $key,
$i++
);

// Field Roles
foreach ($cruditConfig->getFields($key) as $field) {
$fields = $field instanceof Field ? [$field] : $field;

foreach ($fields as $subField) {
if ($subField->getRole()) {
$this->checkAndCreateCredential(
$subField->getRole(),
$rubrique,
$key . "/" . strtolower(str_replace("ROLE_${rubrique}_", "", $subField->getRole())),
$i++
);
}
}
}
foreach (CrudConfigInterface::BASIC_FIELDS_KEYS as $key) {
$this->createRoleForFields($cruditConfig, $key, $rubrique, $i++);
}

foreach ($cruditConfig::ADDITIONAL_FIELDS_KEYS as $key) {
$this->createRoleForFields($cruditConfig, $key, $rubrique, $i++);
}

// Actions Roles
foreach ($cruditConfig->getListActions() as $action) {
if ($action->getPath()->getRole()) {
$this->checkAndCreateCredential(
$action->getPath()->getRole(),
$rubrique,
$action->getLabel(),
$i++
$i++,
type: 'credential.action.list',
);
}

Expand All @@ -79,7 +59,8 @@ public function warmUp(): void
$action->getRole(),
$rubrique,
$action->getLabel(),
$i++
$i++,
type: 'credential.action.list',
);
}
}
Expand All @@ -91,7 +72,8 @@ public function warmUp(): void
$action->getPath()->getRole(),
$rubrique,
$action->getLabel(),
$i++
$i++,
type: 'credential.action.item',
);
}

Expand All @@ -100,7 +82,8 @@ public function warmUp(): void
$action->getRole(),
$rubrique,
$action->getLabel(),
$i++
$i++,
type: 'credential.action.item',
);
}
}
Expand All @@ -112,7 +95,8 @@ public function warmUp(): void
$action->getPath()->getRole(),
$rubrique,
$action->getLabel(),
$i++
$i++,
type: 'credential.action.show',
);
}

Expand All @@ -121,24 +105,81 @@ public function warmUp(): void
$action->getRole(),
$rubrique,
$action->getLabel(),
$i++
$i++,
type: 'credential.action.show',
);
}
}

// Tabs Roles
foreach ($cruditConfig->getTabs() as $key => $brickConfig) {
$brickConfigList = $brickConfig instanceof BrickConfigInterface ? [$brickConfig] : $brickConfig;

foreach ($brickConfigList as $brickConfig) {
if ($brickConfig->getRole()) {
if ($cruditConfig->getTabConfig()?->getTabs()) {
foreach ($cruditConfig->getTabConfig()->getTabs() as $tabs) {
if ($tabs->getRole()) {
$this->checkAndCreateCredential(
$brickConfig->getRole(),
$tabs->getRole(),
$rubrique,
$key . "/" . strtolower(str_replace("ROLE_${rubrique}_", "", $brickConfig->getRole())),
$i++
$tabs->getLabel(),
$i++,
type: 'credential.tab',
);
}

/** @var array $bricks */
foreach ($tabs->getBricks() as $bricks) {
foreach ($bricks as $brickConfig) {
if ($brickConfig->getRole()) {
/** @var class-string $brickClass */
$brickClass = get_class($brickConfig);
$brickClassPart = explode('\\', $brickClass);

$this->checkAndCreateCredential(
$brickConfig->getRole(),
$rubrique,
$tabs->getLabel(),
$i++,
type: $brickConfig->getTitle() ?? (
'credential.'
. strtolower(str_replace('Config', '', end($brickClassPart)))
),
);
}
}
}
}
}
}
}

public function createRoleForAction(
CrudConfigInterface $crudConfig,
string $role,
string $rubrique,
string $label,
int $i,
): void {
$this->checkAndCreateCredential(
strtoupper('ROLE_' . $crudConfig->getName() . '_' . $role),
$rubrique,
strtolower('action.' . $label),
$i,
type: 'credential.action',
);
}

public function createRoleForFields(CrudConfigInterface $cruditConfig, string $key, string $rubrique, int $i): void
{
foreach ($cruditConfig->getFields($key) as $field) {
$fields = $field instanceof Field ? [$field] : $field;

foreach ($fields as $subField) {
if ($subField->getRole()) {
$this->checkAndCreateCredential(
$subField->getRole(),
$rubrique,
$subField->getLabel(),
$i,
type: 'credential.field',
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Service/FrontMenuCredentialWarmup.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function warmUp(): void
$rubrique = "Menu";
$i = 0;
foreach ($this->menuRegistry->getElements("") as $menuItem) {
echo("Menu " . str_replace("menu.", "", $menuItem->getId())."\n");
echo("Menu " . str_replace("menu.", "", $menuItem->getId()) . "\n");
if ($menuItem->getRole()) {
$this->checkAndCreateCredential(
$menuItem->getRole(),
Expand All @@ -34,7 +34,7 @@ public function warmUp(): void
);
}
foreach ($menuItem->getChildren() as $submenuItem) {
echo("↳ Sous menu " . str_replace("menu.", "", $submenuItem->getId())."\n");
echo("↳ Sous menu " . str_replace("menu.", "", $submenuItem->getId()) . "\n");

if ($submenuItem->getRole()) {
$this->checkAndCreateCredential(
Expand Down
Loading
Loading