Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"minimum-stability": "dev",
"require": {
"php": "~8.4.0 || ~8.5.0",
"pimcore/pimcore": "^2026.1",
"pimcore/pimcore": "^2026.4",
"friendsofphp/proxy-manager-lts": "^1"
},
"require-dev": {
Expand Down
4 changes: 4 additions & 0 deletions doc/02_Upgrade_Notes/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade notes

## Upgrade to 2026.4.0
- Requires Pimcore 2026.4 (`pimcore/pimcore: ^2026.4`).
- Added `useInheritedProperties()` to the element, asset, document and data object service resolver contracts, it calls `Pimcore\Model\Element\Service::useInheritedProperties()`. The method is not part of the `*ServiceResolverContractInterface` interfaces yet, as adding it there would break other implementations of them.

## Upgrade to 2026.1.0
- Added support to `PHP` `8.5`.
- Removed support to `PHP` `8.3` and Symfony `v6`.
Expand Down
8 changes: 8 additions & 0 deletions src/Contract/Models/Asset/AssetServiceResolverContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,12 @@ public function locateDaoClass(string $modelClass): ?string
{
return Service::locateDaoClass($modelClass);
}

/**
* @param array<int|string, mixed> $fnArgs
*/
public function useInheritedProperties(bool $inheritProperties, callable $fn, array $fnArgs = []): mixed
{
return Service::useInheritedProperties($inheritProperties, $fn, $fnArgs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,12 @@ public function locateDaoClass(string $modelClass): ?string
{
return Service::locateDaoClass($modelClass);
}

/**
* @param array<int|string, mixed> $fnArgs
*/
public function useInheritedProperties(bool $inheritProperties, callable $fn, array $fnArgs = []): mixed
{
return Service::useInheritedProperties($inheritProperties, $fn, $fnArgs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,12 @@ public function locateDaoClass(string $modelClass): ?string
{
return Service::locateDaoClass($modelClass);
}

/**
* @param array<int|string, mixed> $fnArgs
*/
public function useInheritedProperties(bool $inheritProperties, callable $fn, array $fnArgs = []): mixed
{
return Service::useInheritedProperties($inheritProperties, $fn, $fnArgs);
}
}
8 changes: 8 additions & 0 deletions src/Contract/Models/Element/ServiceResolverContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,12 @@ public function locateDaoClass(string $modelClass): ?string
{
return Service::locateDaoClass($modelClass);
}

/**
* @param array<int|string, mixed> $fnArgs
*/
public function useInheritedProperties(bool $inheritProperties, callable $fn, array $fnArgs = []): mixed
{
return Service::useInheritedProperties($inheritProperties, $fn, $fnArgs);
}
}
5 changes: 5 additions & 0 deletions src/Models/Asset/AssetServiceResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@
interface AssetServiceResolverInterface extends AssetServiceResolverContractInterface
{
public function rewriteIds(Asset $asset, array $rewriteConfig): Asset;

/**
* @param array<int|string, mixed> $fnArgs
*/
public function useInheritedProperties(bool $inheritProperties, callable $fn, array $fnArgs = []): mixed;
}
5 changes: 5 additions & 0 deletions src/Models/DataObject/DataObjectServiceResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public function getCalculatedFieldValueForEditMode(
array $params,
?CalculatedValue $data,
): ?string;

/**
* @param array<int|string, mixed> $fnArgs
*/
public function useInheritedProperties(bool $inheritProperties, callable $fn, array $fnArgs = []): mixed;
}
5 changes: 5 additions & 0 deletions src/Models/Document/DocumentServiceResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public function rewriteIds(
array $rewriteConfig,
array $params = []
): Document|PageSnippet;

/**
* @param array<int|string, mixed> $fnArgs
*/
public function useInheritedProperties(bool $inheritProperties, callable $fn, array $fnArgs = []): mixed;
}
5 changes: 5 additions & 0 deletions src/Models/Element/ServiceResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public function isPublished(?ElementInterface $element = null): bool;
public function escapeCsvRecord(array $rowData): array;

public function unEscapeCsvRecord(array $rowData): array;

/**
* @param array<int|string, mixed> $fnArgs
*/
public function useInheritedProperties(bool $inheritProperties, callable $fn, array $fnArgs = []): mixed;
}
76 changes: 76 additions & 0 deletions tests/Unit/Models/Element/UseInheritedPropertiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);

namespace Pimcore\Bundle\StaticResolverBundle\Tests\Unit\Models\Element;
Comment thread
mcop1 marked this conversation as resolved.
Resolved

use Codeception\Test\Unit;
use Pimcore\Bundle\StaticResolverBundle\Contract\Models\Asset\AssetServiceResolverContract;
use Pimcore\Bundle\StaticResolverBundle\Contract\Models\DataObject\DataObjectServiceResolverContract;
use Pimcore\Bundle\StaticResolverBundle\Contract\Models\Document\DocumentServiceResolverContract;
use Pimcore\Bundle\StaticResolverBundle\Contract\Models\Element\ServiceResolverContract;
use Pimcore\Model\Element\AbstractElement;
use RuntimeException;

final class UseInheritedPropertiesTest extends Unit
{
private bool $initialSetting;

protected function _before(): void
{
$this->initialSetting = AbstractElement::getGetInheritedProperties();
}

protected function _after(): void
{
AbstractElement::setGetInheritedProperties($this->initialSetting);
}

/**
* @return iterable<string, array{object}>
*/
public static function resolverProvider(): iterable
{
yield 'element' => [new ServiceResolverContract()];
yield 'asset' => [new AssetServiceResolverContract()];
yield 'document' => [new DocumentServiceResolverContract()];
yield 'data object' => [new DataObjectServiceResolverContract()];
}

/**
* @dataProvider resolverProvider
*/
public function testRunsTheCallableWithTheSettingAndRestoresIt(object $resolver): void
{
foreach ([true, false] as $before) {
AbstractElement::setGetInheritedProperties($before);

$result = $resolver->useInheritedProperties(
!$before,
static fn (string $prefix): string => $prefix . (AbstractElement::getGetInheritedProperties() ? 'on' : 'off'),
['inherited: ']
);

self::assertSame('inherited: ' . (!$before ? 'on' : 'off'), $result);
self::assertSame($before, AbstractElement::getGetInheritedProperties());
}
}

/**
* @dataProvider resolverProvider
*/
public function testRestoresTheSettingWhenTheCallableThrows(object $resolver): void
{
AbstractElement::setGetInheritedProperties(true);

try {
$resolver->useInheritedProperties(false, static function (): never {
throw new RuntimeException('failed');
});
self::fail('The exception was not rethrown.');
} catch (RuntimeException $exception) {
self::assertSame('failed', $exception->getMessage());
}

self::assertTrue(AbstractElement::getGetInheritedProperties());
}
}
Loading