-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added attributes support for generating name schema
x Fixed
- Loading branch information
Showing
11 changed files
with
405 additions
and
117 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
29 changes: 29 additions & 0 deletions
29
src/contracts/Event/NameSchema/ResolveContentNameSchemaEvent.php
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,29 @@ | ||
<?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; | ||
|
||
final class ResolveContentNameSchemaEvent extends AbstractNameSchemaEvent | ||
{ | ||
private Content $content; | ||
|
||
public function __construct( | ||
array $schemaIdentifiers, | ||
Content $content | ||
) { | ||
parent::__construct($schemaIdentifiers); | ||
$this->content = $content; | ||
} | ||
|
||
public function getContent(): Content | ||
{ | ||
return $this->content; | ||
} | ||
} |
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 | ||
|
||
/** | ||
* @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; | ||
|
||
final class ResolveNameSchemaEvent extends AbstractNameSchemaEvent | ||
{ | ||
private ContentType $contentType; | ||
|
||
private array $fieldMap; | ||
|
||
private array $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; | ||
} | ||
|
||
public function getFieldMap(): array | ||
{ | ||
return $this->fieldMap; | ||
} | ||
|
||
public function getLanguageCodes(): array | ||
{ | ||
return $this->languageCodes; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/contracts/Event/NameSchema/ResolveUrlAliasSchemaEvent.php
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,29 @@ | ||
<?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; | ||
|
||
final class ResolveUrlAliasSchemaEvent extends AbstractNameSchemaEvent | ||
{ | ||
private Content $content; | ||
|
||
public function __construct( | ||
array $schemaIdentifiers, | ||
Content $content | ||
) { | ||
parent::__construct($schemaIdentifiers); | ||
$this->content = $content; | ||
} | ||
|
||
public function getContent(): Content | ||
{ | ||
return $this->content; | ||
} | ||
} |
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
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,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\Core\Repository\NameSchema; | ||
|
||
final class NameSchemaFilter | ||
{ | ||
public const META_STRING = 'EZMETAGROUP_'; | ||
|
||
/** | ||
* Builds a lookup / translation table for groups in the $namePattern. | ||
* The groups are referenced with a generated meta-token in the original | ||
* name pattern. | ||
* | ||
* Returns intermediate name pattern where groups are replaced with meta-tokens. | ||
* | ||
* @param string $nameSchema | ||
* | ||
* @return array{string, array<string, string>} | ||
*/ | ||
public function filterNameSchema(string $nameSchema): array | ||
{ | ||
$retNamePattern = $nameSchema; | ||
$foundGroups = preg_match_all('/\((.+)\)/U', $nameSchema, $groupArray); | ||
$groupLookupTable = []; | ||
|
||
if ($foundGroups) { | ||
$i = 0; | ||
foreach ($groupArray[1] as $group) { | ||
// Create meta-token for group | ||
$metaToken = self::META_STRING . $i; | ||
|
||
// Insert the group with its placeholder token | ||
$retNamePattern = str_replace($group, $metaToken, $retNamePattern); | ||
|
||
// Remove the pattern "(" ")" from the tokens | ||
$group = str_replace(['(', ')'], '', $group); | ||
|
||
$groupLookupTable[$metaToken] = $group; | ||
++$i; | ||
} | ||
$nameSchema = $retNamePattern; | ||
} | ||
|
||
return [$nameSchema, $groupLookupTable]; | ||
} | ||
} |
Oops, something went wrong.