Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
},
"autoload": {
"psr-4": {
"EzSystems\\EzPlatformGraphQL\\": "src"
"EzSystems\\EzPlatformGraphQL\\": "src",
"Ibexa\\GraphQL\\": "src"
}
},
"autoload-dev": {
Expand Down
31 changes: 25 additions & 6 deletions src/Schema/Domain/ImageVariationDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,47 @@
use EzSystems\EzPlatformGraphQL\Schema\Builder;
use EzSystems\EzPlatformGraphQL\Schema\Domain;
use Generator;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;

/**
* Adds configured image variations to the ImageVariationIdentifier type.
*/
class ImageVariationDomain implements Domain\Iterator, Schema\Worker
class ImageVariationDomain implements Domain\Iterator, Schema\Worker, LoggerAwareInterface
{
use LoggerAwareTrait;

const TYPE = 'ImageVariationIdentifier';
const ARG = 'ImageVariation';

/**
* @var ConfigResolverInterface
*/
/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */
private $configResolver;

public function __construct(ConfigResolverInterface $configResolver)
{
/** @var \EzSystems\EzPlatformGraphQL\Schema\Domain\NameValidator */
private $nameValidator;

public function __construct(
ConfigResolverInterface $configResolver,
NameValidator $nameValidator
) {
$this->configResolver = $configResolver;
$this->nameValidator = $nameValidator;
$this->logger = new NullLogger();
}

public function iterate(): Generator
{
foreach ($this->configResolver->getParameter('image_variations') as $identifier => $variation) {
if (!$this->nameValidator->isValidName($identifier)) {
$message = "Skipped schema generation for Image Variation with identifier '%s'. "
. 'Please rename given image variation according to GraphQL specification '
. '(http://spec.graphql.org/June2018/#sec-Names)';

$this->logger->warning(sprintf($message, $identifier));
continue;
}

yield [self::ARG => ['identifier' => $identifier, 'variation' => $variation]];
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/Schema/Domain/NameValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* @copyright Copyright (C) eZ Systems 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\GraphQL\Schema\Domain;

/**
* Validates given name according to GraphQL specification. See http://spec.graphql.org/June2018/#sec-Names.
*/
final class NameValidator
{
private const NAME_PATTERN = '/^[_a-zA-Z][_a-zA-Z0-9]*$/';

public function isValidName(string $name): bool
{
return preg_match(self::NAME_PATTERN, $name) === 1;
}
}
2 changes: 2 additions & 0 deletions src/Schema/ImagesVariationsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

/**
* Generates the ImageVariationIdentifier enum that indexes images variations identifiers.
*
* @deprecated since 1.0, will be removed in 4.0.
*/
class ImagesVariationsBuilder implements SchemaBuilder
{
Expand Down