Skip to content

Commit

Permalink
Split parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed Apr 23, 2024
1 parent 3affb80 commit 7a92af0
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Api/Assets/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController;
use Pimcore\Bundle\StudioApiBundle\Controller\Trait\PaginatedResponseTrait;
use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\Parameters;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParameters;
use Pimcore\Bundle\StudioApiBundle\Service\AssetSearchServiceInterface;
use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -90,7 +90,7 @@ public function __construct(
#[MethodNotAllowedResponse]
#[UnsupportedMediaTypeResponse]
#[UnprocessableContentResponse]
public function getAssets(#[MapQueryString] Parameters $parameters): JsonResponse
public function getAssets(#[MapQueryString] ElementParameters $parameters): JsonResponse
{
$assetQuery = $this->filterService->applyFilters(
$parameters,
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/DataObject/ClassNameFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

use Exception;
use Pimcore\Bundle\StudioApiBundle\Filter\FilterInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\DataObjectParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

Expand All @@ -31,7 +31,7 @@ final class ClassNameFilter implements FilterInterface
/**
* @throws Exception
*/
public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface
public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface
{
if(
!$parameters instanceof DataObjectParametersInterface ||
Expand Down
9 changes: 7 additions & 2 deletions src/Filter/ExcludeFolderFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@

namespace Pimcore\Bundle\StudioApiBundle\Filter;

use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

/**
* @internal
*/
final class ExcludeFolderFilter implements FilterInterface
{
public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface
public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface
{
if (!$parameters instanceof ElementParametersInterface) {
return $query;
}

$excludeFolders = $parameters->getExcludeFolders();
if(!$excludeFolders) {
return $query;
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/FilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

namespace Pimcore\Bundle\StudioApiBundle\Filter;

use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

/**
* @internal
*/
interface FilterInterface
{
public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface;
public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface;
}
9 changes: 7 additions & 2 deletions src/Filter/IdSearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@

namespace Pimcore\Bundle\StudioApiBundle\Filter;

use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

/**
* @internal
*/
final class IdSearchFilter implements FilterInterface
{
public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface
public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface
{
if (!$parameters instanceof ElementParametersInterface) {
return $query;
}

$idSearchTerm = $parameters->getIdSearchTerm();

if(!$idSearchTerm) {
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/PageFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

namespace Pimcore\Bundle\StudioApiBundle\Filter;

use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

/**
* @internal
*/
final class PageFilter implements FilterInterface
{
public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface
public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface
{
return $query->setPage($parameters->getPage());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/PageSizeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

namespace Pimcore\Bundle\StudioApiBundle\Filter;

use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

/**
* @internal
*/
final class PageSizeFilter implements FilterInterface
{
public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface
public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface
{
return $query->setPageSize($parameters->getPageSize());
}
Expand Down
9 changes: 7 additions & 2 deletions src/Filter/ParentIdFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@

namespace Pimcore\Bundle\StudioApiBundle\Filter;

use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

/**
* @internal
*/
final class ParentIdFilter implements FilterInterface
{
public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface
public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface
{
if (!$parameters instanceof ElementParametersInterface) {
return $query;
}

$parentId = $parameters->getParentId();

if(!$parentId) {
Expand Down
9 changes: 7 additions & 2 deletions src/Filter/PathFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@

namespace Pimcore\Bundle\StudioApiBundle\Filter;

use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ElementParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

/**
* @internal
*/
final class PathFilter implements FilterInterface
{
public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface
public function apply(CollectionParametersInterface $parameters, QueryInterface $query): QueryInterface
{
if (!$parameters instanceof ElementParametersInterface) {
return $query;
}

$path = $parameters->getPath();
$includeParent = $parameters->getPathIncludeParent();
$includeDescendants = $parameters->getPathIncludeDescendants();
Expand Down
54 changes: 54 additions & 0 deletions src/Request/Query/Filter/CollectionParameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\Request\Query\Filter;

use Pimcore\ValueObject\Integer\PositiveInteger;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Positive;

/**
* @internal
*/
readonly class CollectionParameters implements CollectionParametersInterface
{
public function __construct(
#[NotBlank]

Check notice on line 29 in src/Request/Query/Filter/CollectionParameters.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Attribute can be added to overriding member

Attribute can be added to overriding parameter

Check notice on line 29 in src/Request/Query/Filter/CollectionParameters.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Attribute can be added to overriding member

Attribute can be added to overriding parameter
#[Positive]

Check notice on line 30 in src/Request/Query/Filter/CollectionParameters.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Attribute can be added to overriding member

Attribute can be added to overriding parameter

Check notice on line 30 in src/Request/Query/Filter/CollectionParameters.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Attribute can be added to overriding member

Attribute can be added to overriding parameter
private int $page = 1,
#[NotBlank]

Check notice on line 32 in src/Request/Query/Filter/CollectionParameters.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Attribute can be added to overriding member

Attribute can be added to overriding parameter

Check notice on line 32 in src/Request/Query/Filter/CollectionParameters.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Attribute can be added to overriding member

Attribute can be added to overriding parameter
#[Positive]

Check notice on line 33 in src/Request/Query/Filter/CollectionParameters.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Attribute can be added to overriding member

Attribute can be added to overriding parameter

Check notice on line 33 in src/Request/Query/Filter/CollectionParameters.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Attribute can be added to overriding member

Attribute can be added to overriding parameter
private int $pageSize = 10,
) {
$this->validate();
}

public function getPage(): int
{
return $this->page;
}

public function getPageSize(): int
{
return $this->pageSize;
}

private function validate(): void
{
new PositiveInteger($this->page);
new PositiveInteger($this->pageSize);
}
}
27 changes: 27 additions & 0 deletions src/Request/Query/Filter/CollectionParametersInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\Request\Query\Filter;

/**
* @internal
*/
interface CollectionParametersInterface
{
public function getPage(): int;

public function getPageSize(): int;
}
2 changes: 1 addition & 1 deletion src/Request/Query/Filter/DataObjectParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @internal
*/
final readonly class DataObjectParameters extends Parameters implements DataObjectParametersInterface
final readonly class DataObjectParameters extends ElementParameters implements DataObjectParametersInterface
{
public function __construct(
int $page = 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Request/Query/Filter/DataObjectParametersInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @internal
*/
interface DataObjectParametersInterface extends ParametersInterface
interface DataObjectParametersInterface extends ElementParametersInterface
{
public function getClassName(): ?string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,23 @@

namespace Pimcore\Bundle\StudioApiBundle\Request\Query\Filter;

use Pimcore\ValueObject\Integer\PositiveInteger;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Positive;

/**
* @internal
*/
readonly class Parameters implements ParametersInterface
readonly class ElementParameters extends CollectionParameters implements ElementParametersInterface
{
public function __construct(
#[NotBlank]
#[Positive]
private int $page = 1,
#[NotBlank]
#[Positive]
private int $pageSize = 10,
int $page = 1,
int $pageSize = 10,
private ?int $parentId = null,
private ?string $idSearchTerm = null,
private ?string $excludeFolders = null,
private ?string $path = null,
private ?string $pathIncludeParent = null,
private ?string $pathIncludeDescendants = null
) {
$this->validate();
}

public function getPage(): int
{
return $this->page;
}

public function getPageSize(): int
{
return $this->pageSize;
parent::__construct($page, $pageSize);
}

public function getParentId(): ?int
Expand Down Expand Up @@ -81,10 +64,4 @@ public function getPathIncludeDescendants(): ?bool
{
return $this->pathIncludeDescendants === 'true'; // TODO: symfony 7.1 will support bool type
}

private function validate(): void
{
new PositiveInteger($this->page);
new PositiveInteger($this->pageSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @internal
*/
interface ParametersInterface
interface ElementParametersInterface
{
public function getPage(): int;

Expand Down
5 changes: 3 additions & 2 deletions src/Service/Filter/FilterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
use Pimcore\Bundle\StudioApiBundle\Exception\InvalidFilterTypeException;
use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException;
use Pimcore\Bundle\StudioApiBundle\Factory\QueryFactoryInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\Parameters;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParameters;

Check notice on line 22 in src/Service/Filter/FilterService.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Unused import

Import 'Pimcore\\Bundle\\StudioApiBundle\\Request\\Query\\Filter\\CollectionParameters' is never used

Check notice on line 22 in src/Service/Filter/FilterService.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Unused import

Import 'Pimcore\\Bundle\\StudioApiBundle\\Request\\Query\\Filter\\CollectionParameters' is never used
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

/**
Expand All @@ -37,7 +38,7 @@ public function __construct(
* @throws InvalidQueryTypeException
* @throws InvalidFilterTypeException
*/
public function applyFilters(Parameters $parameters, string $type): QueryInterface
public function applyFilters(CollectionParametersInterface $parameters, string $type): QueryInterface
{
$query = $this->queryFactory->create($type);
// apply default filters
Expand Down
5 changes: 3 additions & 2 deletions src/Service/Filter/FilterServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
namespace Pimcore\Bundle\StudioApiBundle\Service\Filter;

use Pimcore\Bundle\StudioApiBundle\Exception\InvalidQueryTypeException;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\Parameters;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParameters;

Check notice on line 20 in src/Service/Filter/FilterServiceInterface.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Unused import

Import 'Pimcore\\Bundle\\StudioApiBundle\\Request\\Query\\Filter\\CollectionParameters' is never used

Check notice on line 20 in src/Service/Filter/FilterServiceInterface.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Unused import

Import 'Pimcore\\Bundle\\StudioApiBundle\\Request\\Query\\Filter\\CollectionParameters' is never used
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\CollectionParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface;

/**
Expand All @@ -34,5 +35,5 @@ interface FilterServiceInterface
/**
* @throws InvalidQueryTypeException
*/
public function applyFilters(Parameters $parameters, string $type): QueryInterface;
public function applyFilters(CollectionParametersInterface $parameters, string $type): QueryInterface;
}

0 comments on commit 7a92af0

Please sign in to comment.