Skip to content

Commit

Permalink
Refactor structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakhar Shokel committed Apr 22, 2024
1 parent 85134ab commit 3269aa9
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 68 deletions.
4 changes: 1 addition & 3 deletions src/Annotation/RestAnnotationInterface.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

declare(strict_types=1);

namespace Paysera\Bundle\ApiBundle\Annotation;

use Paysera\Bundle\ApiBundle\Service\Annotation\ReflectionMethodWrapper;
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;

interface RestAnnotationInterface
{
public function isSeveralSupported(): bool;
Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Attribute;
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
use Paysera\Bundle\ApiBundle\Exception\ConfigurationException;
use Paysera\Bundle\ApiBundle\Service\Annotation\ReflectionMethodWrapper;
use Paysera\Bundle\ApiBundle\Service\RoutingLoader\ReflectionMethodWrapper;

#[Attribute(Attribute::TARGET_METHOD)]
class Body implements RestAttributeInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/BodyContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Attribute;
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
use Paysera\Bundle\ApiBundle\Service\Annotation\ReflectionMethodWrapper;
use Paysera\Bundle\ApiBundle\Service\RoutingLoader\ReflectionMethodWrapper;

#[Attribute(Attribute::TARGET_METHOD)]
class BodyContentType implements RestAttributeInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/PathAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Paysera\Bundle\ApiBundle\Entity\PathAttributeResolverOptions;
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
use Paysera\Bundle\ApiBundle\Exception\ConfigurationException;
use Paysera\Bundle\ApiBundle\Service\Annotation\ReflectionMethodWrapper;
use Paysera\Bundle\ApiBundle\Service\RoutingLoader\ReflectionMethodWrapper;

#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class PathAttribute implements RestAttributeInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Paysera\Bundle\ApiBundle\Entity\QueryResolverOptions;
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
use Paysera\Bundle\ApiBundle\Exception\ConfigurationException;
use Paysera\Bundle\ApiBundle\Service\Annotation\ReflectionMethodWrapper;
use Paysera\Bundle\ApiBundle\Service\RoutingLoader\ReflectionMethodWrapper;

#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Query implements RestAttributeInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/RequiredPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Attribute;
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
use Paysera\Bundle\ApiBundle\Service\Annotation\ReflectionMethodWrapper;
use Paysera\Bundle\ApiBundle\Service\RoutingLoader\ReflectionMethodWrapper;

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class RequiredPermissions implements RestAttributeInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/ResponseNormalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Attribute;
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
use Paysera\Bundle\ApiBundle\Service\Annotation\ReflectionMethodWrapper;
use Paysera\Bundle\ApiBundle\Service\RoutingLoader\ReflectionMethodWrapper;

#[Attribute(Attribute::TARGET_METHOD)]
class ResponseNormalization implements RestAttributeInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/RestAttributeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Paysera\Bundle\ApiBundle\Attribute;

use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
use Paysera\Bundle\ApiBundle\Service\Annotation\ReflectionMethodWrapper;
use Paysera\Bundle\ApiBundle\Service\RoutingLoader\ReflectionMethodWrapper;

interface RestAttributeInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Attribute;
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
use Paysera\Bundle\ApiBundle\Entity\ValidationOptions;
use Paysera\Bundle\ApiBundle\Service\Annotation\ReflectionMethodWrapper;
use Paysera\Bundle\ApiBundle\Service\RoutingLoader\ReflectionMethodWrapper;
use Symfony\Component\Validator\Constraint;

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
Expand Down
13 changes: 4 additions & 9 deletions src/DependencyInjection/PayseraApiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.xml');

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/services'));
if (class_exists(AttributeRouteControllerLoader::class)) {
$loader->load('annotations.xml');

if (PHP_VERSION_ID >= 80000) {
$loader->load('attributes.xml');
}
} else {
$loader->load('annotations_legacy.xml');
}
class_exists(AttributeRouteControllerLoader::class)
? $loader->load('attributes.xml')
: $loader->load('annotations.xml')
;

$container->setParameter('paysera_api.locales', $config['locales']);
if (count($config['locales']) === 0) {
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<argument id="paysera_api.rest_request_options_registry" type="service"/>
</service>

<service id="paysera_api.annotations.options_builder"
class="Paysera\Bundle\ApiBundle\Service\RoutingLoader\RestRequestOptionsBuilder">
<argument type="service" id="paysera_api.rest_request_options_validator"/>
</service>

<service class="Paysera\Bundle\ApiBundle\Service\ResponseBuilder" id="paysera_api.response_builder"/>
<service class="\Paysera\Bundle\ApiBundle\Service\ErrorBuilder" id="paysera_api.error_builder">
<call method="configureError">
Expand Down
15 changes: 5 additions & 10 deletions src/Resources/config/services/annotations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
<services>

<service decorates="routing.loader.attribute"
parent="routing.loader.attribute"
id="paysera_api.loader.attribute"
class="Paysera\Bundle\ApiBundle\Service\Annotation\RoutingAnnotationLoader">
<service decorates="routing.loader.annotation"
parent="routing.loader.annotation"
id="paysera_api.annotations.loader"
class="Paysera\Bundle\ApiBundle\Service\RoutingLoader\RoutingAnnotationLoader">
<call method="setRequestHelper">
<argument type="service" id="paysera_api.rest_request_helper"/>
</call>
<call method="setRestRequestOptionsBuilder">
<argument type="service" id="paysera_api.annotations.options_builder"/>
</call>
</service>

<service id="paysera_api.annotations.options_builder"
class="Paysera\Bundle\ApiBundle\Service\Annotation\RestRequestOptionsBuilder">
<argument type="service" id="paysera_api.rest_request_options_validator"/>
</service>
</services>
</container>
25 changes: 0 additions & 25 deletions src/Resources/config/services/annotations_legacy.xml

This file was deleted.

18 changes: 11 additions & 7 deletions src/Resources/config/services/attributes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<!-- <service id="paysera_api.attribute.loader"-->
<!-- class="Paysera\Bundle\ApiBundle\Service\Attribute\RoutingAttributeLoader">-->
<!-- <tag name="routing.loader"/>-->

<!-- <argument type="service" id="paysera_api.rest_request_helper"/>-->
<!-- <argument type="service" id="paysera_api.rest_request_options_validator"/>-->
<!-- <argument type="string">%kernel.environment%</argument>-->
<!-- </service>-->
<service decorates="routing.loader.attribute"
parent="routing.loader.attribute"
id="paysera_api.loader.attribute"
class="Paysera\Bundle\ApiBundle\Service\RoutingLoader\RoutingAnnotationLoader">
<call method="setRequestHelper">
<argument type="service" id="paysera_api.rest_request_helper"/>
</call>
<call method="setRestRequestOptionsBuilder">
<argument type="service" id="paysera_api.annotations.options_builder"/>
</call>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Paysera\Bundle\ApiBundle\Service\Annotation;
namespace Paysera\Bundle\ApiBundle\Service\RoutingLoader;

use Paysera\Bundle\ApiBundle\Exception\ConfigurationException;
use ReflectionMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Paysera\Bundle\ApiBundle\Service\Annotation;
namespace Paysera\Bundle\ApiBundle\Service\RoutingLoader;

use Paysera\Bundle\ApiBundle\Exception\ConfigurationException;
use Paysera\Bundle\ApiBundle\Service\RestRequestOptionsValidator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Paysera\Bundle\ApiBundle\Service\Annotation;
namespace Paysera\Bundle\ApiBundle\Service\RoutingLoader;

use Paysera\Bundle\ApiBundle\Annotation\RestAnnotationInterface;
use Paysera\Bundle\ApiBundle\Service\RestRequestHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Paysera\Bundle\ApiBundle\Service\Attribute;
namespace Paysera\Bundle\ApiBundle\Service\RoutingLoader;

use Paysera\Bundle\ApiBundle\Attribute\RestAttributeInterface;
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use DateTime;
use Paysera\Bundle\ApiBundle\Exception\ConfigurationException;
use Paysera\Bundle\ApiBundle\Service\Annotation\ReflectionMethodWrapper;
use Paysera\Bundle\ApiBundle\Service\RoutingLoader\ReflectionMethodWrapper;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Paysera\Bundle\ApiBundle\Annotation\RestAnnotationInterface;
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
use Paysera\Bundle\ApiBundle\Exception\ConfigurationException;
use Paysera\Bundle\ApiBundle\Service\Annotation\RestRequestOptionsBuilder;
use Paysera\Bundle\ApiBundle\Service\RoutingLoader\RestRequestOptionsBuilder;
use Paysera\Bundle\ApiBundle\Service\RestRequestOptionsValidator;
use ReflectionMethod;

Expand Down

0 comments on commit 3269aa9

Please sign in to comment.