Skip to content

Commit

Permalink
IBX-201: Refactored ExportParametersFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Jul 27, 2021
1 parent 5424bdb commit fa565b3
Show file tree
Hide file tree
Showing 11 changed files with 699 additions and 244 deletions.
22 changes: 16 additions & 6 deletions src/bundle/Resources/config/services/factory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ services:
autoconfigure: true
public: false

EzSystems\EzRecommendationClient\Factory\:
resource: '../../../../src/lib/Factory/*'
EzSystems\EzRecommendationClient\Factory\EzRecommendationClientAPIFactory: ~

EzSystems\EzRecommendationClient\Factory\ExportParametersFactory: ~
EzSystems\EzRecommendationClient\Factory\FakeRequestFactory: ~

EzSystems\EzRecommendationClient\Factory\ConfigurableExportParametersFactory:
EzSystems\EzRecommendationClient\Factory\RequestFactoryInterface:
'@EzSystems\EzRecommendationClient\Factory\FakeRequestFactory'

EzSystems\EzRecommendationClient\Factory\TokenFactory: ~

EzSystems\EzRecommendationClient\Factory\TokenFactoryInterface:
'@EzSystems\EzRecommendationClient\Factory\TokenFactory'

Ibexa\Personalization\Factory\Export\ParametersFactory:
arguments:
$innerService: '@EzSystems\EzRecommendationClient\Factory\ExportParametersFactory'
$credentialsResolver: '@EzSystems\EzRecommendationClient\Config\ExportCredentialsResolver'
$siteAccessService: '@ezpublish.siteaccess_service'
$credentialsResolver: '@EzSystems\EzRecommendationClient\Config\EzRecommendationClientCredentialsResolver'

Ibexa\Personalization\Factory\Export\ParametersFactoryInterface:
'@Ibexa\Personalization\Factory\Export\ParametersFactory'
20 changes: 17 additions & 3 deletions src/lib/Exception/CredentialsNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@

namespace EzSystems\EzRecommendationClient\Exception;

class CredentialsNotFoundException extends NotFoundException
use Throwable;

final class CredentialsNotFoundException extends NotFoundException
{
public function __construct(int $code = 0, ?Throwable $previous = null)
public function __construct(?string $siteAccess = null, int $code = 0, Throwable $previous = null)
{
parent::__construct('Credentials for recommendation client are not set', $code, $previous);
$message = 'Credentials for recommendation client are not set';

if (null !== $siteAccess) {
$message .= sprintf(
' for siteAccess: %s', $siteAccess
);
}

parent::__construct(
$message,
$code,
$previous
);
}
}
13 changes: 0 additions & 13 deletions src/lib/Exception/ExportCredentialsNotFoundException.php

This file was deleted.

29 changes: 28 additions & 1 deletion src/lib/Exception/MissingExportParameterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@

namespace EzSystems\EzRecommendationClient\Exception;

class MissingExportParameterException extends ExportException
use Ibexa\Personalization\Factory\Export\ParametersFactoryInterface;
use Throwable;

final class MissingExportParameterException extends ExportException
{
/**
* @param array<int, string> $missingParameters
*/
public function __construct(array $missingParameters, string $type, int $code = 0, Throwable $previous = null)
{
$parameters = [];

if ($type === ParametersFactoryInterface::COMMAND_TYPE) {
foreach ($missingParameters as $parameter) {
$parameters[] = str_replace('_', '-', $parameter);
}
} else {
$parameters = $missingParameters;
}

parent::__construct(
sprintf(
'Required parameters: %s are missing',
implode(', ', $parameters)
),
$code,
$previous
);
}
}
130 changes: 0 additions & 130 deletions src/lib/Factory/ConfigurableExportParametersFactory.php

This file was deleted.

Loading

0 comments on commit fa565b3

Please sign in to comment.