Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Doctrine filters moved below filters namespace #13495

Merged
merged 2 commits into from Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/packages.yml
Expand Up @@ -97,10 +97,18 @@ jobs:
env:
COMPOSER_ROOT_VERSION: dev-master
working-directory: "src/Sylius/${{ matrix.package }}"
id: end-of-setup

-
name: Test package
run: bin/test-package src/Sylius/${{ matrix.package }}
if: always() && steps.end-of-setup.outcome == 'success'

-
name: Run PHPArkitect
working-directory: "src/Sylius/${{ matrix.package }}"
run: vendor/phparkitect/phparkitect/bin-stub/phparkitect check
if: always() && steps.end-of-setup.outcome == 'success' && matrix.package == 'Bundle/ApiBundle'

notify-about-build-failure:
runs-on: ubuntu-latest
Expand Down
8 changes: 7 additions & 1 deletion UPGRADE-API-1.11.md
Expand Up @@ -317,7 +317,7 @@
* `sylius.api.item_data_provider.reset_password_item` => `Sylius\Bundle\ApiBundle\DataProvider\ResetPasswordItemDataProvider`
* `sylius.api.kerner_request_event_subscriber` => `Sylius\Bundle\ApiBundle\EventSubscriber\KernelRequestEventSubscriber`
* `sylius.api.product_slug_event_subscriber` => `Sylius\Bundle\ApiBundle\EventSubscriber\ProductSlugEventSubscriber`
* `sylius.api.product_taxon_filter` => `Sylius\Bundle\ApiBundle\Filter\TaxonFilter`
* `sylius.api.product_taxon_filter` => `Sylius\Bundle\ApiBundle\Filter\Doctrine\TaxonFilter`
* `sylius.api.exchange_rate_filter` => `Sylius\Bundle\ApiBundle\Doctrine\Filter\ExchangeRateFilter`
* `sylius.api.translation_order_name_and_locale_filter` => `Sylius\Bundle\ApiBundle\Doctrine\Filter\TranslationOrderNameAndLocaleFilter`
* `sylius.api.product_variant_option_value_filter` => `Sylius\Bundle\ApiBundle\Doctrine\Filter\ProductVariantOptionValueFilter`
Expand Down Expand Up @@ -369,6 +369,12 @@
* `Sylius\Bundle\ApiBundle\DataProvider\LocaleCollectionDataProvider` => `Sylius\Bundle\ApiBundle\Doctrine\QueryCollectionExtension\LocaleCollectionExtension`
* `Sylius\Bundle\ApiBundle\DataProvider\TaxonCollectionDataProvider` => `Sylius\Bundle\ApiBundle\Doctrine\QueryCollectionExtension\TaxonCollectionExtension`

1. The following filters have been moved to new namespace:
* `Sylius\Bundle\ApiBundle\Doctrine\Filter\ExchangeRateFilter` service has been moved and renamed to `Sylius\Bundle\ApiBundle\Filter\Doctrine\ExchangeRateFilter`
* `Sylius\Bundle\ApiBundle\Doctrine\Filter\TranslationOrderNameAndLocaleFilter` service has been moved and renamed to `Sylius\Bundle\ApiBundle\Filter\Doctrine\TranslationOrderNameAndLocaleFilter`
* `Sylius\Bundle\ApiBundle\Doctrine\Filter\ProductVariantOptionValueFilter` service has been moved and renamed to `Sylius\Bundle\ApiBundle\Filter\Doctrine\ProductVariantOptionValueFilter`
* `Sylius\Bundle\ApiBundle\Doctrine\Filter\ProductPriceOrderFilter` service has been moved and renamed to `Sylius\Bundle\ApiBundle\Filter\Doctrine\ProductPriceOrderFilter`

1. `Sylius\Bundle\ApiBundle\Command\Cart\ApplyCouponToCart` and `Sylius\Bundle\ApiBundle\Command\Checkout\AddressOrder` commands have been replaced with `Sylius\Bundle\ApiBundle\Command\Checkout\UpdateCart`.

1. `Sylius\Bundle\ApiBundle\CommandHandler\Cart\ApplyCouponToCartHandler` and `Sylius\Bundle\ApiBundle\CommandHandler\Checkout\AddressOrderHandler` command handlers have been replaced with `Sylius\Bundle\ApiBundle\CommandHandler\Checkout\UpdateCartHandler`.
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace Sylius\Bundle\ApiBundle\Doctrine\Filter;
namespace Sylius\Bundle\ApiBundle\Filter\Doctrine;

use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
Expand Down
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace Sylius\Bundle\ApiBundle\Doctrine\Filter;
namespace Sylius\Bundle\ApiBundle\Filter\Doctrine;

use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\OrderFilterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
Expand Down
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace Sylius\Bundle\ApiBundle\Doctrine\Filter;
namespace Sylius\Bundle\ApiBundle\Filter\Doctrine;

use ApiPlatform\Core\Api\IriConverterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
Expand Down
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace Sylius\Bundle\ApiBundle\Filter;
namespace Sylius\Bundle\ApiBundle\Filter\Doctrine;

use ApiPlatform\Core\Api\IriConverterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
Expand Down
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace Sylius\Bundle\ApiBundle\Doctrine\Filter;
namespace Sylius\Bundle\ApiBundle\Filter\Doctrine;

use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\OrderFilterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
Expand Down
Expand Up @@ -24,7 +24,7 @@
<collectionOperation name="admin_get">
<attribute name="method">GET</attribute>
<attribute name="filters">
<attribute>Sylius\Bundle\ApiBundle\Doctrine\Filter\ExchangeRateFilter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Filter\Doctrine\ExchangeRateFilter</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:exchange_rate:read</attribute>
Expand Down
Expand Up @@ -30,7 +30,7 @@
<attribute>sylius.api.product_name_filter</attribute>
<attribute>sylius.api.product_order_filter</attribute>
<attribute>sylius.api.product_taxon_code_filter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Doctrine\Filter\TranslationOrderNameAndLocaleFilter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Filter\Doctrine\TranslationOrderNameAndLocaleFilter</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:product:read</attribute>
Expand All @@ -44,9 +44,9 @@
<attribute>sylius.api.product_name_filter</attribute>
<attribute>sylius.api.product_order_filter</attribute>
<attribute>sylius.api.product_taxon_code_filter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Doctrine\Filter\ProductPriceOrderFilter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Doctrine\Filter\TranslationOrderNameAndLocaleFilter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Filter\TaxonFilter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Filter\Doctrine\ProductPriceOrderFilter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Filter\Doctrine\TranslationOrderNameAndLocaleFilter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Filter\Doctrine\TaxonFilter</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">shop:product:read</attribute>
Expand Down
Expand Up @@ -72,7 +72,7 @@
<attribute name="path">/shop/product-variants</attribute>
<attribute name="filters">
<attribute>sylius.api.product_variant_product_filter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Doctrine\Filter\ProductVariantOptionValueFilter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Filter\Doctrine\ProductVariantOptionValueFilter</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">shop:product_variant:read</attribute>
Expand Down
Expand Up @@ -84,7 +84,7 @@
<attribute name="filters">
<attribute>sylius.api.filter_archived_shipping_methods</attribute>
<attribute>sylius.api.shipping_method_order_filter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Doctrine\Filter\TranslationOrderNameAndLocaleFilter</attribute>
<attribute>Sylius\Bundle\ApiBundle\Filter\Doctrine\TranslationOrderNameAndLocaleFilter</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:shipping_method:read</attribute>
Expand Down
Expand Up @@ -40,7 +40,7 @@
<tag name="api_platform.filter" />
</service>

<service id="Sylius\Bundle\ApiBundle\Filter\TaxonFilter" public="true">
<service id="Sylius\Bundle\ApiBundle\Filter\Doctrine\TaxonFilter" public="true">
<argument type="service" id="doctrine" />
<argument type="service" id="api_platform.iri_converter" />
<tag name="api_platform.filter" />
Expand Down Expand Up @@ -104,23 +104,23 @@
<tag name="api_platform.filter" />
</service>

<service id="Sylius\Bundle\ApiBundle\Doctrine\Filter\ExchangeRateFilter" public="true">
<service id="Sylius\Bundle\ApiBundle\Filter\Doctrine\ExchangeRateFilter" public="true">
<argument type="service" id="doctrine" />
<tag name="api_platform.filter" />
</service>

<service id="Sylius\Bundle\ApiBundle\Doctrine\Filter\TranslationOrderNameAndLocaleFilter" public="true">
<service id="Sylius\Bundle\ApiBundle\Filter\Doctrine\TranslationOrderNameAndLocaleFilter" public="true">
<argument type="service" id="doctrine" />
<tag name="api_platform.filter" />
</service>

<service id="Sylius\Bundle\ApiBundle\Doctrine\Filter\ProductVariantOptionValueFilter" public="true">
<service id="Sylius\Bundle\ApiBundle\Filter\Doctrine\ProductVariantOptionValueFilter" public="true">
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="doctrine" />
<tag name="api_platform.filter" />
</service>

<service id="Sylius\Bundle\ApiBundle\Doctrine\Filter\ProductPriceOrderFilter" public="true">
<service id="Sylius\Bundle\ApiBundle\Filter\Doctrine\ProductPriceOrderFilter" public="true">
<argument type="service" id="doctrine" />
<tag name="api_platform.filter" />
</service>
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Bundle/ApiBundle/composer.json
Expand Up @@ -34,6 +34,7 @@
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"nelmio/alice": "^3.8",
"phparkitect/phparkitect": "^0.2.9",
"phpspec/phpspec": "^7.1",
"phpunit/phpunit": "^8.5",
"symfony/browser-kit": "^4.4 || ^5.4",
Expand Down
46 changes: 46 additions & 0 deletions src/Sylius/Bundle/ApiBundle/phparkitect.php
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\Extend;
use Arkitect\Expression\ForClasses\NotExtend;
use Arkitect\Expression\ForClasses\NotResideInTheseNamespaces;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;

return static function (Config $config): void
{
$classSet = ClassSet::fromDir(__DIR__.'/');
$classSet->excludePath('vendor/**');
$classSet->excludePath('test/**');

$rules = [];

/** Filtration rules */

$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle\ApiBundle\Filter\Doctrine'))
->should(new Extend(AbstractContextAwareFilter::class))
->because('All ORM Api Platform filters should be placed in one namespace')
;

$rules[] = Rule::allClasses()
->that(new NotResideInTheseNamespaces('Sylius\Bundle\ApiBundle\Filter\Doctrine'))
->should(new NotExtend(AbstractContextAwareFilter::class))
->because('All ORM Api Platform filters should be placed in one namespace')
;

$config->add($classSet, ...$rules);
};
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace spec\Sylius\Bundle\ApiBundle\Filter;
namespace spec\Sylius\Bundle\ApiBundle\Filter\Doctrine;

use ApiPlatform\Core\Api\IriConverterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
Expand Down