-
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.
Merge remote-tracking branch 'origin/1.x' into 156-dependencies
# Conflicts: # qodana.sarif.json # src/OpenApi/Config/Tags.php
- Loading branch information
Showing
45 changed files
with
2,467 additions
and
17 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
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,23 @@ | ||
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\Repository\PropertyRepositoryInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Property\Repository\PropertyRepository | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyServiceInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyService | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\PropertyHydratorInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\PropertyHydrator | ||
|
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,79 @@ | ||
<?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\Asset\Controller\Data; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Encoder\TextEncoderInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\DataJson; | ||
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 Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class TextController extends AbstractApiController | ||
{ | ||
use ElementProviderTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly ServiceResolverInterface $serviceResolver, | ||
private readonly TextEncoderInterface $textEncoder, | ||
|
||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
#[Route('/assets/{id}/text', name: 'pimcore_studio_api_get_asset_data_text', methods: ['GET'])] | ||
//#[IsGranted('STUDIO_API')] | ||
//#[IsGranted(UserPermissions::ASSETS->value)] | ||
#[Get( | ||
path: self::API_PATH . '/assets/{id}/text', | ||
operationId: 'getAssetDataTextById', | ||
summary: 'Get asset data in text UTF8 representation by id', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Assets->name] | ||
)] | ||
#[IdParameter(type: 'asset')] | ||
#[SuccessResponse( | ||
description: 'UTF8 encoded text data', | ||
content: new DataJson('UTF 8 encoded text data') | ||
)] | ||
#[UnauthorizedResponse] | ||
#[NotFoundResponse] | ||
#[MethodNotAllowedResponse] | ||
#[UnsupportedMediaTypeResponse] | ||
#[UnprocessableContentResponse] | ||
public function getTextData(int $id): JsonResponse | ||
{ | ||
$element = $this->getElement($this->serviceResolver, 'asset', $id); | ||
|
||
return $this->jsonResponse(['data' => $this->textEncoder->encodeUTF8($element)]); | ||
} | ||
} |
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,44 @@ | ||
<?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\Asset\Encoder; | ||
|
||
use ForceUTF8\Encoding; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\InvalidElementTypeException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\MaxFileSizeExceededException; | ||
use Pimcore\Model\Asset\Text; | ||
use Pimcore\Model\Element\ElementInterface; | ||
|
||
final class TextEncoder implements TextEncoderInterface | ||
{ | ||
private const MAX_FILE_SIZE = 2000000; | ||
|
||
/** | ||
* @throws InvalidElementTypeException|MaxFileSizeExceededException | ||
*/ | ||
public function encodeUTF8(ElementInterface $element): string | ||
{ | ||
if (!$element instanceof Text) { | ||
throw new InvalidElementTypeException('Element must be an instance of Text'); | ||
} | ||
|
||
if ($element->getFileSize() > self::MAX_FILE_SIZE) { | ||
throw new MaxFileSizeExceededException(self::MAX_FILE_SIZE); | ||
} | ||
|
||
return Encoding::toUTF8($element->getData()); | ||
} | ||
} |
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,29 @@ | ||
<?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\Asset\Encoder; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Exception\InvalidElementTypeException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\MaxFileSizeExceededException; | ||
use Pimcore\Model\Element\ElementInterface; | ||
|
||
interface TextEncoderInterface | ||
{ | ||
/** | ||
* @throws InvalidElementTypeException|MaxFileSizeExceededException | ||
*/ | ||
public function encodeUTF8(ElementInterface $element): string; | ||
} |
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,48 @@ | ||
<?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\Event; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface; | ||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class AbstractPreResponseEvent extends Event | ||
{ | ||
public function __construct(protected readonly AdditionalAttributesInterface $responseObject) | ||
{ | ||
} | ||
|
||
public function hasAdditionalAttribute(string $key): bool { | ||
return $this->responseObject->hasAdditionalAttribute($key); | ||
} | ||
|
||
public function getAdditionalAttribute(string $key): mixed | ||
{ | ||
return $this->responseObject->getAdditionalAttribute($key); | ||
} | ||
|
||
public function addAdditionalAttribute(string $key, mixed $value): void | ||
{ | ||
$this->responseObject->addAdditionalAttribute($key, $value); | ||
} | ||
|
||
public function removeAdditionalAttribute(string $key): void { | ||
$this->responseObject->removeAdditionalAttribute($key); | ||
} | ||
} |
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,32 @@ | ||
<?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\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ElementSavingFailedException extends AbstractApiException | ||
{ | ||
public function __construct(int $id, ?string $error = null) | ||
{ | ||
parent::__construct(500, sprintf( | ||
'Failed to save element with ID %s: %s', | ||
$id, | ||
$error ?? 'Unknown error' | ||
)); | ||
} | ||
} |
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,31 @@ | ||
<?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\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class MaxFileSizeExceededException extends AbstractApiException | ||
{ | ||
public function __construct(int|float $maxFileSize) | ||
{ | ||
parent::__construct( | ||
413, | ||
sprintf('Max file size of %d bytes exceeded', $maxFileSize) | ||
); | ||
} | ||
} |
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,31 @@ | ||
<?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\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class NotWriteableException extends AbstractApiException | ||
{ | ||
public function __construct(string $type) | ||
{ | ||
parent::__construct(500, sprintf( | ||
'Cannot create: %s', | ||
$type | ||
)); | ||
} | ||
} |
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,28 @@ | ||
<?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\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class PropertyNotFoundException extends AbstractApiException | ||
{ | ||
public function __construct(string $id) | ||
{ | ||
parent::__construct(404, 'Property with ID ' . $id . ' not found'); | ||
} | ||
} |
Oops, something went wrong.