-
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.
- Loading branch information
Showing
11 changed files
with
416 additions
and
1 deletion.
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,31 @@ | ||
resources: | ||
Pimcore\Model\Asset: | ||
provider: Pimcore\Bundle\StudioApiBundle\State\AssetProvider | ||
normalizationContext: | ||
groups: ['get'] | ||
denormalizationContext: | ||
groups: ['set'] | ||
properties: | ||
id: | ||
identifier: true | ||
parentId: ~ | ||
type: ~ | ||
data: ~ | ||
fullPath: ~ | ||
|
||
Pimcore\Model\Asset\Image: | ||
provider: Pimcore\Bundle\StudioApiBundle\State\AssetProvider | ||
properties: | ||
id: | ||
identifier: true | ||
normalizationContext: | ||
groups: ['get'] | ||
denormalizationContext: | ||
groups: ['set'] | ||
|
||
Pimcore\Model\Asset\Image\Thumbnail: | ||
provider: Pimcore\Bundle\StudioApiBundle\State\AssetProvider | ||
normalizationContext: | ||
groups: ['get'] | ||
denormalizationContext: | ||
groups: ['set'] |
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,19 @@ | ||
resources: | ||
Pimcore\Model\User: | ||
operations: | ||
ApiPlatform\Metadata\Post: | ||
status: 202 | ||
processor: Pimcore\Bundle\StudioApiBundle\State\ResetPasswordProcessor | ||
input: Pimcore\Bundle\StudioApiBundle\Dto\ResetPasswordRequest | ||
output: false | ||
uriTemplate: '/users/reset-password' | ||
# ApiPlatform\Metadata\Get: | ||
# controller: ApiPlatform\Action\NotFoundAction | ||
# read: false | ||
# output: false | ||
|
||
|
||
normalizationContext: | ||
groups: [ 'get' ] | ||
denormalizationContext: | ||
groups: [ 'set' ] |
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,4 @@ | ||
api_platform: | ||
resource: . | ||
type: api_platform | ||
prefix: /api |
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,64 @@ | ||
Pimcore\Model\Asset: | ||
attributes: | ||
id: | ||
groups: ['get', 'bla:read'] | ||
parentId: | ||
groups: ['get'] | ||
type: | ||
groups: ['get'] | ||
filename: | ||
groups: ['get'] | ||
path: | ||
groups: ['get'] | ||
mimetype: | ||
groups: ['get'] | ||
creationDate: | ||
groups: ['get'] | ||
modificationDate: | ||
groups: ['get'] | ||
userOwner: | ||
groups: ['get'] | ||
userModification: | ||
groups: ['get'] | ||
properties: | ||
groups: ['get'] | ||
versions: | ||
groups: ['get'] | ||
metadata: | ||
groups: ['get'] | ||
locked: | ||
groups: ['get'] | ||
customSettings: | ||
groups: ['get'] | ||
hasMetaData: | ||
groups: ['get'] | ||
dependencies: | ||
groups: ['get'] | ||
scheduledTasks: | ||
groups: ['get'] | ||
versionCount: | ||
groups: ['get'] | ||
fullPath: | ||
groups: ['get'] | ||
|
||
Pimcore\Model\Asset\Image: | ||
attributes: | ||
thumbnail: | ||
groups: ['get'] | ||
format: | ||
groups: ['get'] | ||
dimensions: | ||
groups: ['get'] | ||
width: | ||
groups: [ 'get' ] | ||
height: | ||
groups: [ 'get' ] | ||
|
||
Pimcore\Model\Asset\Image\Thumbnail: | ||
attributes: | ||
path: | ||
groups: ['get'] | ||
imageTag: | ||
groups: ['get'] | ||
media: | ||
groups: ['get'] |
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,4 @@ | ||
Pimcore\Bundle\StudioApiBundle\Dto\ResetPasswordRequest: | ||
attributes: | ||
username: | ||
groups: ['get', 'set'] |
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,69 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under following license: | ||
* - Pimcore Commercial License (PCL) | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioApiBundle\DependencyInjection; | ||
|
||
use Exception; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
|
||
/** | ||
* This is the class that loads and manages your bundle configuration. | ||
* | ||
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html | ||
*/ | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class PimcoreStudioApiExtension extends Extension implements PrependExtensionInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws Exception | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
// Load services and configuration | ||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config')); | ||
$loader->load('services.yaml'); | ||
|
||
// Set default serializer mapping if not provided in the app's config | ||
if (!isset($config['serializer']['mapping']['paths'])) { | ||
$config['serializer']['mapping']['paths'] = [__DIR__ . '/../../config/serialization']; | ||
} | ||
|
||
// Pass the configuration to the custom normalizer | ||
$container->setParameter('pimcore_studio_api.serializer.mapping.paths', $config['serializer']['mapping']['paths']); | ||
Check warning on line 55 in src/DependencyInjection/PimcoreStudioApiExtension.php GitHub Actions / Qodana for PHPLine is longer than allowed by code style
|
||
} | ||
|
||
public function prepend(ContainerBuilder $container): void | ||
{ | ||
$apiPlatformConfig = [ | ||
"mapping"=>[ | ||
"paths"=> [ | ||
__DIR__ . '/../../config/api_platform/' | ||
] | ||
] | ||
]; | ||
$container->prependExtensionConfig('api_platform', $apiPlatformConfig); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Pimcore\Bundle\StudioApiBundle\Dto; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class ResetPasswordRequest | ||
{ | ||
#[Assert\NotBlank] | ||
public string $username; | ||
|
||
public function getUsername(): string | ||
{ | ||
return $this->username; | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace Pimcore\Bundle\StudioApiBundle\Serializer; | ||
|
||
use Pimcore\Model\Asset; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
final class AssetNormalizer implements NormalizerInterface, NormalizerAwareInterface | ||
{ | ||
use NormalizerAwareTrait; | ||
|
||
private const ALREADY_CALLED = 'ASSET_NORMALIZER_ALREADY_CALLED'; | ||
|
||
public function __construct(private RequestStack $requestStack) | ||
Check failure on line 17 in src/Serializer/AssetNormalizer.php GitHub Actions / Static Analysis with PHPStan (8.2, highest, 11.x-dev as 11.99.9, true)
Check failure on line 17 in src/Serializer/AssetNormalizer.php GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)
|
||
{ | ||
} | ||
|
||
public function normalize($object, $format = null, array $context = array()): array | ||
{ | ||
$context[self::ALREADY_CALLED] = true; | ||
|
||
$data = $this->normalizer->normalize($object, $format, $context); | ||
|
||
if (isset($data['data']) && $data['data']) { | ||
$data['data'] = base64_encode($data['data']); | ||
} | ||
|
||
if ($object instanceof Asset\Image) { | ||
$data['thumbnail'] = $object->getThumbnail()->getPath(['frontend' => true]); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function supportsNormalization($data, $format = null, array $context = []): bool | ||
{ | ||
if (isset($context[self::ALREADY_CALLED])) { | ||
return false; | ||
} | ||
|
||
return $data instanceof Asset; | ||
} | ||
|
||
public function getSupportedTypes(?string $format): array | ||
{ | ||
return [ | ||
Asset::class => false, | ||
]; | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Pimcore\Bundle\StudioApiBundle\State; | ||
|
||
use ApiPlatform\Metadata\CollectionOperationInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\State\ProviderInterface; | ||
use Pimcore\Model\Asset; | ||
use Pimcore\Model\Element\Tag; | ||
|
||
final class AssetProvider implements ProviderInterface | ||
{ | ||
|
||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null | ||
{ | ||
// collection of assets, needs to be further investigated | ||
if ($operation instanceof CollectionOperationInterface) { | ||
$assetListing = new Asset\Listing(); | ||
$assetListing->setLimit(10); | ||
|
||
if (isset($context['filters']['page'])) { | ||
$assetListing->setOffset(10 * $context['filters']['page']); | ||
} | ||
return $assetListing; | ||
} | ||
// getting a single asset by id | ||
$test = Asset::getById($uriVariables['id']); | ||
Check warning on line 28 in src/State/AssetProvider.php GitHub Actions / Qodana for PHPOne-time use variables
|
||
|
||
//$tag = Tag::getTagsForElement('asset', $test->getId()); | ||
return $test; | ||
} | ||
} |
Oops, something went wrong.