Skip to content

Commit

Permalink
Initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed Mar 12, 2024
1 parent e83cd27 commit ba4dbab
Show file tree
Hide file tree
Showing 16 changed files with 258 additions and 53 deletions.
8 changes: 3 additions & 5 deletions config/api_platform/resources/asset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ resources:
ApiPlatform\Metadata\Get:
normalizationContext:
groups: [ 'asset:read', 'asset:item:get', 'dependency:read', 'property:read', 'element:read', 'element:item:get']
ApiPlatform\Metadata\Put:
ApiPlatform\Metadata\Post:
ApiPlatform\Metadata\Delete:
ApiPlatform\Metadata\Patch:
provider: Pimcore\Bundle\StudioApiBundle\State\AssetProvider
provider: Pimcore\Bundle\StudioApiBundle\State\Asset\Provider
processor: Pimcore\Bundle\StudioApiBundle\State\Asset\Processor
normalizationContext:
groups: ['asset:read', 'dependency:read', 'property:read', 'element:read']
denormalizationContext:
groups: ['asset:write']
groups: ['asset:write', 'element:write']
properties:
id:
identifier: true
Expand Down
6 changes: 4 additions & 2 deletions config/api_platform/resources/asset/image.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
resources:
Pimcore\Bundle\StudioApiBundle\Dto\Asset\Image:
provider: Pimcore\Bundle\StudioApiBundle\State\AssetProvider
provider: Pimcore\Bundle\StudioApiBundle\State\Asset\Provider
processor: Pimcore\Bundle\StudioApiBundle\State\Asset\Processor
operations:
ApiPlatform\Metadata\Get:
normalizationContext:
groups: ['image:read', 'asset:read', 'asset:item:get', 'dependency:read', 'property:read', 'element:read', 'element:item:get' ]
ApiPlatform\Metadata\Put:
properties:
id:
identifier: true
normalizationContext:
groups: ['image:read', 'asset:read', 'dependency:read', 'property:read', 'element:read']
denormalizationContext:
groups: ['image:write', 'asset:write']
groups: ['image:write', 'asset:write', 'element:write']
18 changes: 9 additions & 9 deletions config/serialization/asset.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
Pimcore\Bundle\StudioApiBundle\Dto\Asset:
attributes:
type:
groups: ['asset:read']
groups: ['asset:read', 'asset:write']
iconName:
groups: [ 'asset:read' ]
groups: [ 'asset:read' , 'asset:write']
children:
groups: ['asset:read']
groups: ['asset:read', 'asset:write']
filename:
groups: ['asset:read']
groups: ['asset:read', 'asset:write']
mimetype:
groups: ['asset:read']
groups: ['asset:read', 'asset:write']
metadata:
groups: ['asset:read']
groups: ['asset:read', 'asset:write']
customSettings:
groups: ['asset:item:get']
groups: ['asset:item:get', 'asset:write']
hasMetaData:
groups: ['asset:read']
groups: ['asset:read', 'asset:write']
userPermissions:
groups: ['asset:read']
groups: ['asset:read', 'asset:write']
14 changes: 4 additions & 10 deletions config/serialization/asset/image.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
Pimcore\Bundle\StudioApiBundle\Dto\Asset\Image:
attributes:
thumbnail:
groups: ['image:read', 'asset:read']
format:
groups: ['image:read', 'asset:read']
groups: ['image:read', 'asset:read', 'image:write']
dimensions:
groups: ['image:read', 'asset:read']
groups: ['image:read', 'asset:read', 'image:write']
width:
groups: ['image:read', 'asset:read']
groups: ['image:read', 'asset:read', 'image:write']
height:
groups: ['image:read', 'asset:read']
animated:
groups: ['image:read', 'asset:read']
vectorGraphic:
groups: ['image:read', 'asset:read']
groups: ['image:read', 'asset:read', 'image:write']
# lowQualityPreviewDataUri:
# groups: ['image:read']
# lowQualityPreviewPath:
Expand Down
34 changes: 17 additions & 17 deletions config/serialization/element.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
Pimcore\Bundle\StudioApiBundle\Dto\Element:
attributes:
id:
groups: ['element:read']
groups: ['element:read', 'element:write']
parentId:
groups: ['element:read']
groups: ['element:read', 'element:write']
permissions:
groups: ['element:read']
groups: ['element:read', 'element:write']
path:
groups: ['element:read']
groups: ['element:read', 'element:write']
creationDate:
groups: ['element:read']
groups: ['element:read', 'element:write']
modificationDate:
groups: ['element:read']
groups: ['element:read', 'element:write']
userOwner:
groups: ['element:read']
groups: ['element:read', 'element:write']
userModification:
groups: ['element:read']
groups: ['element:read', 'element:write']
properties:
groups: ['element:item:get']
groups: ['element:item:get', 'element:write']
versions:
groups: ['element:read']
groups: ['element:read', 'element:write']
locked:
groups: ['element:read']
groups: ['element:read', 'element:write']
lock:
groups: ['element:read']
groups: ['element:read', 'element:write']
dependencies:
groups: ['element:item:get']
groups: ['element:item:get', 'element:write']
scheduledTasks:
groups: ['element:item:get']
groups: ['element:item:get', 'element:write']
versionCount:
groups: ['element:item:get']
groups: ['element:item:get', 'element:write']
fullPath:
groups: ['element:read']
groups: ['element:read', 'element:write']
userPermissions:
groups: ['element:read']
groups: ['element:read', 'element:write']
19 changes: 18 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ services:
tags: [ 'controller.service_arguments' ]

# Providers
Pimcore\Bundle\StudioApiBundle\State\AssetProvider: ~
Pimcore\Bundle\StudioApiBundle\State\Asset\Provider: ~
Pimcore\Bundle\StudioApiBundle\State\UserProvider: ~
Pimcore\Bundle\StudioApiBundle\State\ScheduledTaskProvider: ~
Pimcore\Bundle\StudioApiBundle\State\VersionProvider: ~

# Processors

Pimcore\Bundle\StudioApiBundle\State\ResetPasswordProcessor: ~
Pimcore\Bundle\StudioApiBundle\State\Token\Create\Processor: ~
Pimcore\Bundle\StudioApiBundle\State\Token\Refresh\Processor: ~
Expand Down Expand Up @@ -70,12 +71,23 @@ services:
Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Hydrator\PermissionsHydratorInterface:
class: Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Hydrator\PermissionsHydrator

Pimcore\Bundle\StudioApiBundle\Service\CoreData\V1\Hydrator\Asset\ImageHydratorInterface:
class: Pimcore\Bundle\StudioApiBundle\Service\CoreData\V1\Hydrator\Asset\ImageHydrator

# Services
Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Hydrator\AssetHydratorServiceInterface:
class: Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Hydrator\AssetHydratorService
arguments:
$assetHydratorLocator: '@generic_data_index.asset_hydrator.service_locator'

Pimcore\Bundle\StudioApiBundle\Service\CoreData\V1\Hydrator\AssetHydratorServiceInterface:
class: Pimcore\Bundle\StudioApiBundle\Service\CoreData\V1\Hydrator\AssetHydratorService
arguments:
$assetHydratorLocator: '@pimcore_model_data.asset_hydrator.service_locator'

Pimcore\Bundle\StudioApiBundle\Service\AssetServiceInterface:
class: Pimcore\Bundle\StudioApiBundle\Service\AssetService

Pimcore\Bundle\StudioApiBundle\Service\AssetSearchServiceInterface:
class: Pimcore\Bundle\StudioApiBundle\Service\AssetSearchService

Expand Down Expand Up @@ -126,3 +138,8 @@ services:
Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\SearchResultItem\Text: '@Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Hydrator\Asset\TextHydratorInterface'
Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\SearchResultItem\Unknown: '@Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Hydrator\Asset\UnknownHydratorInterface'
Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\SearchResultItem\Video: '@Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\Hydrator\Asset\VideoHydratorInterface'

pimcore_model_data.asset_hydrator.service_locator:
class: Symfony\Component\DependencyInjection\ServiceLocator
arguments:
- Pimcore\Model\Asset\Image: '@Pimcore\Bundle\StudioApiBundle\Service\CoreData\V1\Hydrator\Asset\ImageHydratorInterface'
5 changes: 1 addition & 4 deletions src/Dto/Asset/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;

class Image extends Asset
final class Image extends Asset
{
//use MetaData\EmbeddedMetaDataTrait;

public function __construct(
private readonly string $format,
private readonly int $width,
private readonly int $height,
private readonly bool $vectorGraphic,
private readonly bool $animated,
private readonly string $thumbnailPath,
string $iconName,
bool $hasChildren,
Expand Down
40 changes: 40 additions & 0 deletions src/Service/AssetService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\Service;

use Pimcore\Bundle\StaticResolverBundle\Models\Asset\AssetResolverInterface;
use Pimcore\Bundle\StudioApiBundle\Dto\Asset;
use Pimcore\Model\Asset as CoreAsset;
use Pimcore\Model\Exception\NotFoundException;

final readonly class AssetService implements AssetServiceInterface
{
public function __construct(private AssetResolverInterface $assetResolver)
{
}

public function processAsset(int $id, Asset $data): CoreAsset
{
$asset = $this->assetResolver->getById($id);

if(!$asset) {
throw new NotFoundException('Asset not found');
}

return $asset;
}
}
24 changes: 24 additions & 0 deletions src/Service/AssetServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* 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\Service;

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;
use Pimcore\Model\Asset as CoreAsset;

interface AssetServiceInterface
{
public function processAsset(int $id, Asset $data): CoreAsset;
}
43 changes: 43 additions & 0 deletions src/Service/CoreData/V1/Hydrator/Asset/ImageHydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Pimcore\Bundle\StudioApiBundle\Service\CoreData\V1\Hydrator\Asset;

use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Image;
use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Permissions;
use Pimcore\Bundle\StudioApiBundle\Service\IconServiceInterface;
use Pimcore\Model\Asset\Image as CoreImage;

final readonly class ImageHydrator implements ImageHydratorInterface
{
public function __construct(
private IconServiceInterface $iconService
) {
}

public function hydrate(CoreImage $item): Image
{
return new Image(
$item->getWidth(),
$item->getHeight(),
'',
$this->iconService->getIconForAsset($item->getType(), $item->getMimeType()),
false,
$item->getType(),
$item->getFilename(),
$item->getMimeType(),
[],
false,
$item->getFullPath(),
$item->getId(),
$item->getParentId(),
$item->getPath(),
$item->getUserOwner(),
$item->getUserModification(),
$item->getLocked(),
$item->isLocked(),
$item->getCreationDate(),
$item->getModificationDate(),
new Permissions()
);
}
}
11 changes: 11 additions & 0 deletions src/Service/CoreData/V1/Hydrator/Asset/ImageHydratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Pimcore\Bundle\StudioApiBundle\Service\CoreData\V1\Hydrator\Asset;

use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Image;
use Pimcore\Model\Asset\Image as CoreImage;

interface ImageHydratorInterface
{
public function hydrate(CoreImage $item): Image;
}
30 changes: 30 additions & 0 deletions src/Service/CoreData/V1/Hydrator/AssetHydratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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\Service\CoreData\V1\Hydrator;

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;
use Pimcore\Model\Asset as CoreAsset;

interface AssetHydratorInterface
{
/**
* @param CoreAsset $item
*
* @return Asset
*/
public function hydrate(CoreAsset $item): ?Asset;
}
26 changes: 26 additions & 0 deletions src/Service/CoreData/V1/Hydrator/AssetHydratorService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Pimcore\Bundle\StudioApiBundle\Service\CoreData\V1\Hydrator;

use Pimcore\Bundle\StudioApiBundle\Dto\Asset;
use Pimcore\Model\Asset as CoreAsset;
use Symfony\Contracts\Service\ServiceProviderInterface;

final readonly class AssetHydratorService implements AssetHydratorInterface
{
public function __construct(
private ServiceProviderInterface $assetHydratorLocator,
) {
}

public function hydrate(CoreAsset $item): ?Asset
{
$class = get_class($item);
if($this->assetHydratorLocator->has($class)) {
return $this->assetHydratorLocator->get($class)->hydrate($item);
}

return null;
//return new Asset($item->getId());
}
}
Loading

0 comments on commit ba4dbab

Please sign in to comment.