Skip to content

Commit

Permalink
[Events] Add Deprecation to remove context from ResolveUploadTargetEv…
Browse files Browse the repository at this point in the history
…ent (pimcore#17740)

* Add deprecation for context in ResolveUploadTargetEvent.

* Make $context nullable for deprecation.

* Make null check more strict.

Co-authored-by: Jacob Dreesen <[email protected]>

* Add deprecation to set/get.

* Update php doc

Co-authored-by: Sebastian Blank <[email protected]>

* Override setArgument to handle the deprecated context property.

---------

Co-authored-by: Jacob Dreesen <[email protected]>
Co-authored-by: Sebastian Blank <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent 56f8f15 commit 02298c3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Upgrade Notes
## Pimcore 11.5.0
### [Events]
- `context` property of `ResolveUploadTargetEvent` is deprecated. Use `setArgument()` method instead.

## Pimcore 11.4.0
### General
Expand Down
56 changes: 52 additions & 4 deletions lib/Event/Model/Asset/ResolveUploadTargetEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,32 @@ class ResolveUploadTargetEvent extends Event

protected string $filename;

protected array $context;
/**
* @deprecated Will be removed in Pimcore 12
*/
protected array $context = [];

protected int $parentId;

/**
* ResolveUploadTargetEvent constructor.
*
* @param array $context contextual information
* @param array|null $context contextual information
*/
public function __construct(int $parentId, string $filename, array $context)
public function __construct(int $parentId, string $filename, ?array $context = null)
{
$this->parentId = $parentId;
$this->filename = $filename;
$this->context = $context;
if ($context !== null) {
trigger_deprecation(
'pimcore/pimcore',
'11.5.0',
'The context property is deprecated and will be removed in 12.0.0.
Use setArgument() from the ArgumentsAwareTrait instead.'
);

$this->context = $context;
}
}

public function getFilename(): string
Expand All @@ -51,13 +63,33 @@ public function setFilename(string $filename): void
$this->filename = $filename;
}

/**
* @deprecated Will be removed in Pimcore 12
*/
public function getContext(): array
{
trigger_deprecation(
'pimcore/pimcore',
'11.5.0',
'The context property is deprecated and will be removed in 12.0.0.
Use getArgument() from the ArgumentsAwareTrait instead.'
);

return $this->context;
}

/**
* @deprecated Will be removed in Pimcore 12
*/
public function setContext(array $context): void
{
trigger_deprecation(
'pimcore/pimcore',
'11.5.0',
'The context property is deprecated and will be removed in 12.0.0.
Use setArgument() from the ArgumentsAwareTrait instead.'
);

$this->context = $context;
}

Expand All @@ -70,4 +102,20 @@ public function setParentId(int $parentId): void
{
$this->parentId = $parentId;
}

/**
* Will be removed in Pimcore 12
*
* Override setArgument to handle the deprecated context property.
*/
public function setArgument(string $key, mixed $value): static
{
if ($key === 'context' && is_array($value)) {
$this->context = $value;
}

$this->arguments[$key] = $value;

return $this;
}
}

0 comments on commit 02298c3

Please sign in to comment.