-
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.
* Introduce asset service * Apply php-cs-fixer changes * Consistency check * Refactor controllers and add custom settings event * Apply php-cs-fixer changes * Add new lines --------- Co-authored-by: mattamon <mattamon@users.noreply.github.com>
- Loading branch information
Showing
15 changed files
with
399 additions
and
47 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
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
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,39 @@ | ||
<?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\Event; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Asset; | ||
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; | ||
|
||
final class AssetEvent extends AbstractPreResponseEvent | ||
{ | ||
public const EVENT_NAME = 'pre_response.asset'; | ||
public function __construct( | ||
private readonly Asset $asset | ||
) | ||
{ | ||
parent::__construct($asset); | ||
} | ||
|
||
/** | ||
* Use this to get additional infos out of the response object | ||
*/ | ||
public function getAsset(): Asset | ||
{ | ||
return $this->asset; | ||
} | ||
} |
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,39 @@ | ||
<?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\Event; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomSettings; | ||
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; | ||
|
||
final class CustomSettingsEvent extends AbstractPreResponseEvent | ||
{ | ||
public const EVENT_NAME = 'pre_response.asset_custom_settings'; | ||
public function __construct( | ||
private readonly CustomSettings $customSettings | ||
) | ||
{ | ||
parent::__construct($customSettings); | ||
} | ||
|
||
/** | ||
* Use this to get additional infos out of the response object | ||
*/ | ||
public function getCustomSettings(): CustomSettings | ||
{ | ||
return $this->customSettings; | ||
} | ||
} |
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
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,88 @@ | ||
<?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\Service; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Asset\Event\AssetEvent; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Asset; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Archive; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Audio; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Document; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Folder; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Image; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Text; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Unknown; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Video; | ||
use Pimcore\Bundle\StudioBackendBundle\DataIndex\AssetSearchServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\DataIndex\OpenSearchFilterInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Request\ElementParameters; | ||
use Pimcore\Bundle\StudioBackendBundle\Filter\Service\FilterServiceProviderInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Response\Collection; | ||
use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; | ||
use Pimcore\Model\Element\ElementInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class AssetService implements AssetServiceInterface | ||
{ | ||
public function __construct( | ||
private AssetSearchServiceInterface $assetSearchService, | ||
private FilterServiceProviderInterface $filterServiceProvider, | ||
private EventDispatcherInterface $eventDispatcher | ||
) | ||
{ | ||
} | ||
|
||
|
||
public function getAssets(ElementParameters $parameters): Collection | ||
{ | ||
$filterService = $this->filterServiceProvider->create(OpenSearchFilterInterface::SERVICE_TYPE); | ||
|
||
$assetQuery = $filterService->applyFilters( | ||
$parameters, | ||
ElementTypes::TYPE_ASSET | ||
); | ||
|
||
$result = $this->assetSearchService->searchAssets($assetQuery); | ||
|
||
$items = $result->getItems(); | ||
|
||
foreach ($items as $item) { | ||
$this->eventDispatcher->dispatch( | ||
new AssetEvent($item), | ||
AssetEvent::EVENT_NAME | ||
); | ||
|
||
} | ||
|
||
return new Collection($result->getTotalItems(), $items); | ||
} | ||
|
||
public function getAsset(int $id): Asset|Archive|Audio|Document|Folder|Image|Text|Unknown|Video | ||
{ | ||
$asset = $this->assetSearchService->getAssetById($id); | ||
|
||
$this->eventDispatcher->dispatch( | ||
new AssetEvent($asset), | ||
AssetEvent::EVENT_NAME | ||
); | ||
|
||
return $asset; | ||
} | ||
} |
Oops, something went wrong.