Skip to content

Commit

Permalink
feature: update resource metadata properties and factories to handle …
Browse files Browse the repository at this point in the history
…new properties and resource filtering, and drops the yaml supports
  • Loading branch information
johnkrovitch committed Oct 28, 2023
1 parent 139e529 commit cb866ac
Show file tree
Hide file tree
Showing 55 changed files with 1,566 additions and 723 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
],
"require": {
"php": "^8.2",
"cuyz/valinor": "^1.0.0",
"doctrine/annotations": "^2.0",
"friendsofsymfony/ckeditor-bundle": "^2.4",
"johnkrovitch/configuration": "^2.2",
Expand Down
20 changes: 15 additions & 5 deletions config/services/resources.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
services:
lag_admin.resource.registry: '@LAG\AdminBundle\Resource\Registry\ResourceRegistryInterface'
LAG\AdminBundle\Resource\Registry\ResourceRegistryInterface:
class: LAG\AdminBundle\Resource\Registry\ResourceRegistry
lag_admin.resource.registry: '@LAG\AdminBundle\Metadata\Registry\ResourceRegistryInterface'
LAG\AdminBundle\Metadata\Registry\ResourceRegistryInterface:
class: LAG\AdminBundle\Metadata\Registry\ResourceRegistry
arguments:
$resourcePaths: '%lag_admin.resource_paths%'
$locator: '@lag_admin.metadata.locator'
$resourceFactory: '@lag_admin.resource.factory'

LAG\AdminBundle\Metadata\Registry\CacheRegistryDecorator:
decorates: 'lag_admin.resource.registry'
arguments:
$decorated: '@.inner'

lag_admin.metadata.locator: '@LAG\AdminBundle\Metadata\Locator\MetadataLocatorInterface'
LAG\AdminBundle\Metadata\Locator\MetadataLocatorInterface:
class: LAG\AdminBundle\Metadata\Locator\CompositeLocator
arguments:
$locators: !tagged_iterator lag_admin.resource.locator
$kernel: '@kernel'

LAG\AdminBundle\Metadata\Locator\AttributeLocator:
tags: ['lag_admin.resource.locator']

LAG\AdminBundle\Metadata\Locator\YamlLocator:
tags: ['lag_admin.resource.locator']
lag_admin.resource.context: '@LAG\AdminBundle\Metadata\Context\ResourceContextInterface'
LAG\AdminBundle\Metadata\Context\ResourceContextInterface:
class: LAG\AdminBundle\Metadata\Context\ResourceContext
arguments:
$parametersExtractor: '@lag_admin.request.parameters_extractor'
$resourceRegistry: '@lag_admin.resource.registry'
82 changes: 42 additions & 40 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
cacheDirectory="var/phpunit/cache">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="var/phpunit/logs/clover.xml"/>
<html outputDirectory="var/phpunit/coverage"
lowUpperBound="35"
highLowerBound="70"/>
</report>
</coverage>
<testsuites>
<testsuite name="AdminBundle Test Suite">
<directory>tests/phpunit</directory>
</testsuite>
</testsuites>
<php>
<server name="KERNEL_DIR" value="src/LAG/AdminBundle/Tests/Fixtures/app"/>
<!-- ###+ symfony/framework-bundle ### -->
<env name="APP_ENV" value="test"/>
<env name="APP_SECRET" value="4885b6328504a001d0e801257fb51d3f"/>
<env name="APP_SECRET" value="4885b6328504a001d0e801257fb51d3f"/>
<!-- ###- symfony/framework-bundle ### -->
<!-- ###+ doctrine/doctrine-bundle ### -->
<!-- Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url -->
<!-- IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml -->
<!-- -->
<!-- DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" -->
<!-- DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7" -->
<env name="DATABASE_URL" value="postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&amp;charset=utf8"/>
<!-- ###- doctrine/doctrine-bundle ### -->
</php>
<logging>
<junit outputFile="var/phpunit/logs/junit.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" cacheDirectory="var/phpunit/cache">
<coverage>
<report>
<clover outputFile="var/phpunit/logs/clover.xml"/>
<html outputDirectory="var/phpunit/coverage" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>

<testsuites>
<testsuite name="AdminBundle Test Suite">
<directory>tests/phpunit</directory>
</testsuite>
</testsuites>

<php>
<server name="KERNEL_DIR" value="src/LAG/AdminBundle/Tests/Fixtures/app"/>
<!-- ###+ symfony/framework-bundle ### -->
<env name="APP_ENV" value="test"/>
<env name="APP_SECRET" value="4885b6328504a001d0e801257fb51d3f"/>
<env name="APP_SECRET" value="4885b6328504a001d0e801257fb51d3f"/>
<!-- ###- symfony/framework-bundle ### -->
<!-- ###+ doctrine/doctrine-bundle ### -->
<!-- Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url -->
<!-- IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml -->
<!-- -->
<!-- DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" -->
<!-- DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7" -->
<env name="DATABASE_URL"
value="postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&amp;charset=utf8"/>
<!-- ###- doctrine/doctrine-bundle ### -->
</php>

<logging>
<junit outputFile="var/phpunit/logs/junit.xml"/>
</logging>

<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
6 changes: 4 additions & 2 deletions src/Event/OperationEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ enum OperationEvents: string
{
public const OPERATION_CREATE = 'lag_admin.operation.create';
public const OPERATION_CREATED = 'lag_admin.operation.created';
public const OPERATION_CREATE_RESOURCE_PATTERN = 'lag_admin.%s.operation.%s.create';
public const OPERATION_CREATED_RESOURCE_PATTERN = 'lag_admin.%s.operation.%s.created';

public const RESOURCE_OPERATION_CREATE_PATTERN = 'lag_admin.%s.operation.%s.create';
public const RESOURCE_OPERATION_CREATED_PATTERN = 'lag_admin.%s.operation.%s.created';

public const OPERATION_CREATE_PATTERN = 'lag_admin.%s.operation.create';
public const OPERATION_CREATED_PATTERN = 'lag_admin.%s.operation.created';
}
174 changes: 151 additions & 23 deletions src/Metadata/AdminResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,71 @@
use LAG\AdminBundle\Bridge\Doctrine\ORM\State\ORMDataProcessor;
use LAG\AdminBundle\Bridge\Doctrine\ORM\State\ORMDataProvider;
use LAG\AdminBundle\Exception\Operation\OperationMissingException;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
class AdminResource
{
private OperationInterface $currentOperation;

public function __construct(
#[NotBlank]
private ?string $name = null,

#[NotBlank]
private ?string $dataClass = null,

#[NotBlank(allowNull: true)]
private ?string $title = null,

#[NotBlank(allowNull: true)]
private ?string $group = null,

#[NotBlank(allowNull: true)]
private ?string $icon = null,

/** @var OperationInterface[] $operations */
#[Length(min: 1)]
private array $operations = [
new Index(),
new GetCollection(),
new Get(),
new Create(),
new Update(),
new Delete(),
new Show(),
],
private string $processor = ORMDataProcessor::class,

#[NotBlank]
private ?string $processor = ORMDataProcessor::class,

#[NotBlank]
private string $provider = ORMDataProvider::class,

/** @var string[] $identifiers */
private array $identifiers = ['id'],
private string $routePattern = 'lag_admin.{resource}.{operation}',

private string $routePattern = '{application}.{resource}.{operation}',

private ?string $routePrefix = '/{resourceName}',
private ?string $translationPattern = null,

private ?string $translationPattern = '{application}.{resource}.{message}',

private ?string $translationDomain = null,

#[NotBlank]
private ?string $applicationName = null,

private ?string $formType = null,

private array $formOptions = [],

private bool $validation = true,

private ?array $validationContext = null,

private bool $ajax = true,

private ?array $normalizationContext = null,

private ?array $denormalizationContext = null,
) {
}

Expand Down Expand Up @@ -181,6 +218,19 @@ public function withRoutePattern(string $routePattern): self
return $self;
}

public function getRoutePrefix(): ?string
{
return $this->routePrefix;
}

public function withRoutePrefix(?string $prefix): self
{
$self = clone $this;
$self->routePrefix = $prefix;

return $self;
}

public function getIdentifiers(): array
{
return $this->identifiers;
Expand All @@ -194,54 +244,132 @@ public function withIdentifiers(array $identifiers): self
return $self;
}

public function getCurrentOperation(): OperationInterface
public function getTranslationPattern(): ?string
{
return $this->currentOperation;
return $this->translationPattern;
}

public function withCurrentOperation(OperationInterface $currentOperation): self
public function withTranslationPattern(?string $translationPattern): self
{
$self = clone $this;
$self->currentOperation = $currentOperation;
$self->translationPattern = $translationPattern;

return $self;
}

public function getRoutePrefix(): ?string
public function getTranslationDomain(): ?string
{
return $this->routePrefix;
return $this->translationDomain;
}

public function withRoutePrefix(?string $prefix): self
public function withTranslationDomain(?string $translationDomain): self
{
$self = clone $this;
$self->routePrefix = $prefix;
$self->translationDomain = $translationDomain;

return $self;
}

public function getTranslationPattern(): ?string
public function getApplicationName(): ?string
{
return $this->translationPattern;
return $this->applicationName;
}

public function withTranslationPattern(?string $translationPattern): self
public function withApplicationName(?string $applicationName): self
{
$self = clone $this;
$self->translationPattern = $translationPattern;
$self->applicationName = $applicationName;

return $self;
}

public function getTranslationDomain(): ?string
public function getFormType(): ?string
{
return $this->translationDomain;
return $this->formType;
}

public function withTranslationDomain(?string $translationDomain): self
public function withFormType(?string $formType): self
{
$self = clone $this;
$self->translationDomain = $translationDomain;
$self->formType = $formType;

return $self;
}

public function getFormOptions(): ?array
{
return $this->formOptions;
}

public function withFormOptions(?array $formOptions): self
{
$self = clone $this;
$self->formOptions = $formOptions;

return $self;
}

public function isValidationEnabled(): bool
{
return $this->validation;
}

public function withValidation(bool $validation): self
{
$self = clone $this;
$self->validation = $validation;

return $self;
}

public function getValidationContext(): ?array
{
return $this->validationContext;
}

public function withValidationContext(array $context): self
{
$self = clone $this;
$self->validationContext = $context;

return $self;
}

public function hasAjax(): bool
{
return $this->ajax;
}

public function withAjax(bool $ajax): self
{
$self = clone $this;
$self->ajax = $ajax;

return $self;
}

public function getNormalizationContext(): ?array
{
return $this->normalizationContext;
}

public function withNormalizationContext(array $context): self
{
$self = clone $this;
$self->normalizationContext = $context;

return $self;
}

public function getDenormalizationContext(): ?array
{
return $this->denormalizationContext;
}

public function withDenormalizationContext(array $context): self
{
$self = clone $this;
$self->denormalizationContext = $context;

return $self;
}
Expand Down
Loading

0 comments on commit cb866ac

Please sign in to comment.