-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: add properties controller, hydradtors, services etc.
- Loading branch information
Showing
19 changed files
with
815 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
# controllers are imported separately to make sure they're public | ||
# and have a tag that allows actions to type-hint services | ||
Pimcore\Bundle\StudioBackendBundle\Property\Controller\: | ||
resource: '../src/Property/Controller' | ||
public: true | ||
tags: [ 'controller.service_arguments' ] | ||
|
||
|
||
Pimcore\Bundle\StudioBackendBundle\Property\RepositoryInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Property\Repository | ||
|
||
|
||
Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorServiceInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorService | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\DataPropertyHydratorInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\DataPropertyHydrator | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\PredefinedPropertyHydratorInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\PredefinedPropertyHydrator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/OpenApi/Attributes/Parameters/Path/ElementTypeParameter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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\StudioBackendBundle\OpenApi\Attributes\Parameters\Path; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\PathParameter; | ||
use OpenApi\Attributes\Schema; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class ElementTypeParameter extends PathParameter | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
name: 'elementType', | ||
description: 'Filter elements by matching element type.', | ||
in: 'path', | ||
required: true, | ||
schema: new Schema( | ||
type: 'string', | ||
enum: [ | ||
ElementTypes::TYPE_ASSET, | ||
ElementTypes::TYPE_DOCUMENT, | ||
ElementTypes::TYPE_DATA_OBJECT, | ||
], | ||
example: ElementTypes::TYPE_DATA_OBJECT, | ||
), | ||
); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/OpenApi/Attributes/Parameters/Query/QueryParameter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?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\StudioBackendBundle\OpenApi\Attributes\Parameters\Query; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\QueryParameter as OpenApiQueryParameter; | ||
use OpenApi\Attributes\Schema; | ||
use Pimcore\Model\DataObject\ClassDefinition; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class QueryParameter extends OpenApiQueryParameter | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
name: 'query', | ||
description: 'Query for properties', | ||
in: 'query', | ||
required: false, | ||
schema: new Schema(type: 'string', example: null), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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\StudioBackendBundle\OpenApi\Attributes\Response\Content; | ||
|
||
use OpenApi\Attributes\Items; | ||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\Property; | ||
use Pimcore\Bundle\StudioBackendBundle\Property\Schema\PredefinedProperty as PropertySchema; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ItemsJson extends JsonContent | ||
{ | ||
public function __construct(string $schema) | ||
{ | ||
parent::__construct( | ||
properties: [ | ||
new Property('items', type: 'array', items: new Items(ref:$schema)) | ||
], | ||
type: 'object', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?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\StudioBackendBundle\Property\Controller; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\InvalidQueryTypeException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\ElementTypeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\ItemsJson; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\BadRequestResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\MethodNotAllowedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnauthorizedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnsupportedMediaTypeResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Property\Request\PropertiesParameters; | ||
use Pimcore\Bundle\StudioBackendBundle\Property\Schema\PredefinedProperty; | ||
use Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\PaginatedResponseTrait; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapQueryString; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CollectionController extends AbstractApiController | ||
{ | ||
use PaginatedResponseTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly PropertyHydratorServiceInterface $hydratorService, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws InvalidQueryTypeException | ||
*/ | ||
#[Route('/properties', name: 'pimcore_studio_api_properties', methods: ['GET'])] | ||
//#[IsGranted('STUDIO_API')] | ||
#[GET( | ||
path: self::API_PATH . '/properties', | ||
operationId: 'getProperties', | ||
description: 'Get paginated predefined properties', | ||
summary: 'Get all properties for element type', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Properties->name] | ||
)] | ||
#[ElementTypeParameter] | ||
#[SuccessResponse( | ||
description: 'Paginated properties with total count as header param', | ||
content: new ItemsJson(PredefinedProperty::class) | ||
)] | ||
#[BadRequestResponse] | ||
#[UnauthorizedResponse] | ||
#[MethodNotAllowedResponse] | ||
#[UnsupportedMediaTypeResponse] | ||
#[UnprocessableContentResponse] | ||
public function getProperties(#[MapQueryString] PropertiesParameters $parameters): JsonResponse | ||
{ | ||
return $this->jsonResponse($this->hydratorService->getHydratedProperties($parameters)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?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\StudioBackendBundle\Property\Controller; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\ElementTypeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\OneOfVersionJson; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\MethodNotAllowedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\NotFoundResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnauthorizedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnsupportedMediaTypeResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class GetController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
#[Route('/properties/{elementType}/{id}', name: 'pimcore_studio_api_get_properties', methods: ['GET'])] | ||
//#[IsGranted('STUDIO_API')] | ||
#[GET( | ||
path: self::API_PATH . '/properties/{elementType}/{id}', | ||
operationId: 'getPropertiesByTypeAndId', | ||
description: 'Get properties based on the type and the id', | ||
summary: 'Get properties by type and ID', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Properties->name] | ||
)] | ||
#[IdParameter(type: 'element')] | ||
#[ElementTypeParameter] | ||
#[SuccessResponse( | ||
description: 'Version data as json', | ||
content: new OneOfVersionJson() | ||
)] | ||
#[UnauthorizedResponse] | ||
#[NotFoundResponse] | ||
#[MethodNotAllowedResponse] | ||
#[UnsupportedMediaTypeResponse] | ||
#[UnprocessableContentResponse] | ||
public function getProperties(string $elementType, int $id): JsonResponse | ||
Check notice on line 67 in src/Property/Controller/GetController.php GitHub Actions / Qodana for PHPUnused parameter
|
||
{ | ||
|
||
return $this->jsonResponse([]); | ||
} | ||
} |
Oops, something went wrong.