Skip to content

Commit

Permalink
IBX-6282: Added support for custom name schema attributes (#257)
Browse files Browse the repository at this point in the history
For more details see https://issues.ibexa.co/browse/IBX-6282 and #257

Added support for custom attributes when generating content name schema.

Key changes:

* Added two new events:
  * `\Ibexa\Contracts\Core\Event\NameSchema\ResolveNameSchemaEvent`
  * `\Ibexa\Contracts\Core\Event\NameSchema\ResolveContentNameSchemaEvent`

* Changed new `NameSchemaService` method names:
  * `resolve` => `resolveNameSchema`
  * `resolveNameSchema` => `resolveContentNameSchema`

* Kept BC behavior on legacy `NameSchemaService` helper class

---------

Co-Authored-By: Paweł Niedzielski <[email protected]>
Co-Authored-By: Andrew Longosz <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2023
1 parent dbaf4fd commit 3e143a0
Show file tree
Hide file tree
Showing 20 changed files with 710 additions and 380 deletions.
126 changes: 3 additions & 123 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5035,31 +5035,6 @@ parameters:
count: 1
path: src/contracts/Container/Encore/ConfigurationDumper.php

-
message: "#^Method Ibexa\\\\Contracts\\\\Core\\\\Event\\\\ResolveUrlAliasSchemaEvent\\:\\:__construct\\(\\) has parameter \\$schemaIdentifiers with no value type specified in iterable type array\\.$#"
count: 1
path: src/contracts/Event/ResolveUrlAliasSchemaEvent.php

-
message: "#^Method Ibexa\\\\Contracts\\\\Core\\\\Event\\\\ResolveUrlAliasSchemaEvent\\:\\:getSchemaIdentifiers\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/contracts/Event/ResolveUrlAliasSchemaEvent.php

-
message: "#^Method Ibexa\\\\Contracts\\\\Core\\\\Event\\\\ResolveUrlAliasSchemaEvent\\:\\:getTokenValues\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/contracts/Event/ResolveUrlAliasSchemaEvent.php

-
message: "#^Method Ibexa\\\\Contracts\\\\Core\\\\Event\\\\ResolveUrlAliasSchemaEvent\\:\\:setTokenValues\\(\\) has parameter \\$names with no value type specified in iterable type array\\.$#"
count: 1
path: src/contracts/Event/ResolveUrlAliasSchemaEvent.php

-
message: "#^Property Ibexa\\\\Contracts\\\\Core\\\\Event\\\\ResolveUrlAliasSchemaEvent\\:\\:\\$schemaIdentifiers type has no value type specified in iterable type array\\.$#"
count: 1
path: src/contracts/Event/ResolveUrlAliasSchemaEvent.php

-
message: "#^Method Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\BinaryBase\\\\PathGenerator\\:\\:getStoragePathForField\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -7015,11 +6990,6 @@ parameters:
count: 1
path: src/contracts/Repository/LocationService.php

-
message: "#^Method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaServiceInterface\\:\\:resolveNameSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/contracts/Repository/NameSchema/NameSchemaServiceInterface.php

-
message: "#^PHPDoc tag @param for parameter \\$objectStateGroupId with type mixed is not subtype of native type int\\.$#"
count: 1
Expand Down Expand Up @@ -20245,16 +20215,6 @@ parameters:
count: 1
path: src/lib/Repository/ContentService.php

-
message: "#^Parameter \\#2 \\$fieldMap of method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaServiceInterface\\:\\:resolveNameSchema\\(\\) expects array\\<string, array\\<string, string\\>\\>, array\\<int\\|string, array\\<string, Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\Value\\>\\> given\\.$#"
count: 1
path: src/lib/Repository/ContentService.php

-
message: "#^Parameter \\#3 \\$fieldMap of method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaServiceInterface\\:\\:resolve\\(\\) expects array\\<string, array\\<string, string\\>\\>, array\\<int\\|string, array\\<string, Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\Value\\>\\> given\\.$#"
count: 1
path: src/lib/Repository/ContentService.php

-
message: "#^Parameter \\#3 \\$prioritizedLanguages of method Ibexa\\\\Core\\\\Repository\\\\Mapper\\\\ContentDomainMapper\\:\\:buildContentDomainObjectFromPersistence\\(\\) expects array\\<string\\>, array\\<string\\>\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -20336,12 +20296,12 @@ parameters:
path: src/lib/Repository/ContentTypeService.php

-
message: "#^Parameter \\#1 \\$value of method Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\FieldType\\:\\:getName\\(\\) expects Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\Value, Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\Value\\|null given\\.$#"
message: "#^Cannot access property \\$fieldTypeIdentifier on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\FieldDefinition\\|null\\.$#"
count: 1
path: src/lib/Repository/EventSubscriber/NameSchemaSubscriber.php
path: src/lib/Repository/Helper/NameSchemaService.php

-
message: "#^Parameter \\#3 \\$fieldMap of method Ibexa\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaService\\:\\:resolve\\(\\) expects array\\<string, array\\<string, string\\>\\>, array\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\> given\\.$#"
message: "#^Parameter \\#2 \\$fieldDefinition of method Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\FieldType\\:\\:getName\\(\\) expects Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\FieldDefinition, Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\FieldDefinition\\|null given\\.$#"
count: 1
path: src/lib/Repository/Helper/NameSchemaService.php

Expand Down Expand Up @@ -20645,16 +20605,6 @@ parameters:
count: 1
path: src/lib/Repository/Mapper/RoleDomainMapper.php

-
message: "#^Cannot access offset mixed on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\.$#"
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Cannot access property \\$fieldTypeIdentifier on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\FieldDefinition\\|null\\.$#"
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaService\\:\\:extractTokens\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -20665,26 +20615,6 @@ parameters:
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaService\\:\\:mergeFieldMap\\(\\) has parameter \\$fieldMap with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaService\\:\\:mergeFieldMap\\(\\) has parameter \\$languageCodes with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaService\\:\\:mergeFieldMap\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaService\\:\\:resolveNameSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaService\\:\\:resolveToken\\(\\) has parameter \\$groupLookupTable with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -20705,26 +20635,11 @@ parameters:
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Parameter \\#1 \\$value of method Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\FieldType\\:\\:getName\\(\\) expects Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\Value, string given\\.$#"
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Parameter \\#2 \\$fieldDefinition of method Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\FieldType\\:\\:getName\\(\\) expects Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\FieldDefinition, Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\FieldDefinition\\|null given\\.$#"
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Property Ibexa\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaService\\:\\:\\$settings type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Repository/NameSchema/NameSchemaService.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\NameSchema\\\\SchemaIdentifierExtractor\\:\\:extract\\(\\) should return array\\<string, array\\<string, string\\>\\> but returns array\\<string, array\\<int, string\\>\\>\\.$#"
count: 1
path: src/lib/Repository/NameSchema/SchemaIdentifierExtractor.php

-
message: "#^Parameter \\#1 \\$module of class Ibexa\\\\Core\\\\Base\\\\Exceptions\\\\UnauthorizedException constructor expects string, int\\<min, \\-1\\>\\|int\\<1, max\\> given\\.$#"
count: 1
Expand Down Expand Up @@ -58210,41 +58125,6 @@ parameters:
count: 2
path: tests/lib/Repository/Mapper/ContentLocationMapper/DecoratedLocationServiceTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaServiceTest\\:\\:getDataForTestResolve\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaServiceTest\\:\\:getDataForTestResolveNameSchema\\(\\) return type has no value type specified in iterable type iterable\\.$#"
count: 1
path: tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaServiceTest\\:\\:getEventDispatcherMock\\(\\) has parameter \\$tokenValues with no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaServiceTest\\:\\:testResolve\\(\\) has parameter \\$settings with no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

-
message: "#^PHPDoc tag @return contains unresolvable type\\.$#"
count: 1
path: tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

-
message: "#^Parameter \\#2 \\$content of method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaServiceTest\\:\\:buildNameSchemaService\\(\\) expects Ibexa\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Content, Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Content given\\.$#"
count: 4
path: tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

-
message: "#^Parameter \\#3 \\$fieldMap of method Ibexa\\\\Core\\\\Repository\\\\NameSchema\\\\NameSchemaService\\:\\:resolve\\(\\) expects array\\<string, array\\<string, string\\>\\>, array\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\> given\\.$#"
count: 1
path: tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\PHPUnitConstraint\\\\AllValidationErrorsOccur\\:\\:extractTranslatable\\(\\) has parameter \\$fieldErrors with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
56 changes: 56 additions & 0 deletions src/contracts/Event/NameSchema/AbstractNameSchemaEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Core\Event\NameSchema;

use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;

abstract class AbstractNameSchemaEvent extends AbstractSchemaEvent
{
private ContentType $contentType;

/** @var array<int|string, array<string, \Ibexa\Contracts\Core\FieldType\Value>> */
private array $fieldMap;

/** @var array<string> */
private array $languageCodes;

/**
* @param array<string, array<int, string>> $schemaIdentifiers
* @param array<int|string, array<string, \Ibexa\Contracts\Core\FieldType\Value>> $fieldMap
* @param array<string> $languageCodes
*/
public function __construct(
array $schemaIdentifiers,
ContentType $contentType,
array $fieldMap,
array $languageCodes
) {
parent::__construct($schemaIdentifiers);
$this->contentType = $contentType;
$this->fieldMap = $fieldMap;
$this->languageCodes = $languageCodes;
}

public function getContentType(): ContentType
{
return $this->contentType;
}

/** @return array<int|string, array<string, \Ibexa\Contracts\Core\FieldType\Value>> */
public function getFieldMap(): array
{
return $this->fieldMap;
}

/** @return array<string> */
public function getLanguageCodes(): array
{
return $this->languageCodes;
}
}
52 changes: 52 additions & 0 deletions src/contracts/Event/NameSchema/AbstractSchemaEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Core\Event\NameSchema;

use Symfony\Contracts\EventDispatcher\Event;

abstract class AbstractSchemaEvent extends Event
{
/** @var array<string, array<int, string>> */
private array $schemaIdentifiers;

/** @var array<string, array<string, string>> */
private array $tokenValues = [];

/**
* @param array<string, array<int, string>> $schemaIdentifiers
*/
public function __construct(array $schemaIdentifiers)
{
$this->schemaIdentifiers = $schemaIdentifiers;
}

/**
* @return array<string, array<string, string>>
*/
final public function getTokenValues(): array
{
return $this->tokenValues;
}

/**
* @param array<string, array<string, string>> $names
*/
final public function setTokenValues(array $names): void
{
$this->tokenValues = $names;
}

/**
* @return array<string, array<int, string>>
*/
public function getSchemaIdentifiers(): array
{
return $this->schemaIdentifiers;
}
}
16 changes: 16 additions & 0 deletions src/contracts/Event/NameSchema/ContentAwareEventInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Core\Event\NameSchema;

use Ibexa\Contracts\Core\Repository\Values\Content\Content;

interface ContentAwareEventInterface
{
public function getContent(): Content;
}
38 changes: 38 additions & 0 deletions src/contracts/Event/NameSchema/ResolveContentNameSchemaEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Core\Event\NameSchema;

use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;

final class ResolveContentNameSchemaEvent extends AbstractNameSchemaEvent implements ContentAwareEventInterface
{
private Content $content;

/**
* @param array<string, array<string>> $schemaIdentifiers
* @param array<int|string, array<string, \Ibexa\Contracts\Core\FieldType\Value>> $fieldMap
* @param array<string> $languageCodes
*/
public function __construct(
Content $content,
array $schemaIdentifiers,
ContentType $contentType,
array $fieldMap,
array $languageCodes
) {
parent::__construct($schemaIdentifiers, $contentType, $fieldMap, $languageCodes);
$this->content = $content;
}

public function getContent(): Content
{
return $this->content;
}
}
13 changes: 13 additions & 0 deletions src/contracts/Event/NameSchema/ResolveNameSchemaEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Core\Event\NameSchema;

final class ResolveNameSchemaEvent extends AbstractNameSchemaEvent
{
}
Loading

0 comments on commit 3e143a0

Please sign in to comment.