-
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
1 changed file
with
318 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,318 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Laminas\View\Model; | ||
|
||
use ArrayAccess; | ||
use Laminas\View\Exception\InvalidArgumentException; | ||
use ReturnTypeWillChange; | ||
// phpcs:ignore | ||
use Traversable; | ||
|
||
final class ViewModel implements ModelInterface, ClearableModelInterface, RetrievableChildrenInterface | ||
{ | ||
/** | ||
* What variable a parent model should capture this model to | ||
*/ | ||
protected string $captureTo = 'content'; | ||
|
||
/** | ||
* Child models | ||
* | ||
* @var list<ModelInterface> | ||
*/ | ||
protected array $children = []; | ||
|
||
/** | ||
* Renderer options | ||
* | ||
* @var array<string, mixed> | ||
*/ | ||
protected array $options = []; | ||
|
||
/** | ||
* Template to use when rendering this model | ||
*/ | ||
protected string $template = ''; | ||
|
||
/** | ||
* Is this a standalone, or terminal, model? | ||
*/ | ||
protected bool $terminate = false; | ||
|
||
/** | ||
* View variables | ||
* | ||
* @var array<string, mixed>|ArrayAccess|Traversable<string, mixed> | ||
* @psalm-var array<string, mixed>|ArrayAccess&Traversable<string, mixed> | ||
* @phpstan-var array<string, mixed>|ArrayAccess&Traversable<string, mixed> | ||
*/ | ||
protected array | ArrayAccess | Traversable $variables = []; | ||
|
||
/** | ||
* Is this append to child with the same capture? | ||
*/ | ||
protected bool $append = false; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param array<string, mixed>|Traversable<string, mixed>|ArrayAccess<string, mixed>|null $variables | ||
* @param array<string, mixed>|Traversable<string, mixed>|null $options | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function __construct( | ||
array | Traversable | ArrayAccess | null $variables = null, | ||
array | Traversable | null $options = null, | ||
); | ||
|
||
/** | ||
* Property overloading: set variable value | ||
* | ||
* @throws void | ||
*/ | ||
public function __set(string $name, mixed $value): void; | ||
|
||
/** | ||
* Property overloading: get variable value | ||
* | ||
* @throws void | ||
*/ | ||
public function __get(string $name): mixed; | ||
|
||
/** | ||
* Property overloading: do we have the requested variable value? | ||
* | ||
* @throws void | ||
*/ | ||
public function __isset(string $name): bool; | ||
|
||
/** | ||
* Property overloading: unset the requested variable | ||
* | ||
* @throws void | ||
*/ | ||
public function __unset(string $name): void; | ||
|
||
/** | ||
* Called after this view model is cloned. | ||
* | ||
* Clones $variables property so changes done to variables in the new | ||
* instance don't change the current one. | ||
* | ||
* @return void | ||
* | ||
* @throws void | ||
*/ | ||
public function __clone(); | ||
|
||
/** | ||
* Set a single option | ||
* | ||
* @throws void | ||
*/ | ||
public function setOption(string $name, mixed $value): self; | ||
|
||
/** | ||
* Get a single option | ||
* | ||
* @param string $name The option to get. | ||
* @param mixed|null $default (optional) A default value if the option is not yet set. | ||
* | ||
* @throws void | ||
*/ | ||
public function getOption(string $name, mixed $default = null): mixed; | ||
|
||
/** | ||
* Set renderer options/hints en masse | ||
* | ||
* @param array<string, mixed>|Traversable<string, mixed> $options | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function setOptions(array | Traversable $options): self; | ||
|
||
/** | ||
* Get renderer options/hints | ||
* | ||
* @return array<string, mixed> | ||
* | ||
* @throws void | ||
*/ | ||
public function getOptions(): array; | ||
|
||
/** | ||
* Clear any existing renderer options/hints | ||
* | ||
* @throws void | ||
*/ | ||
public function clearOptions(): self; | ||
|
||
/** | ||
* Get a single view variable | ||
* | ||
* @param mixed|null $default (optional) default value if the variable is not present. | ||
* | ||
* @throws void | ||
*/ | ||
public function getVariable(string $name, mixed $default = null): mixed; | ||
|
||
/** | ||
* Set view variable | ||
* | ||
* @throws void | ||
*/ | ||
public function setVariable(string $name, mixed $value): self; | ||
|
||
/** | ||
* Set view variables en masse | ||
* | ||
* Can be an array or a Traversable + ArrayAccess object. | ||
* | ||
* @param bool $overwrite Whether or not to overwrite the internal container with $variables | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function setVariables(array | ArrayAccess | Traversable $variables, bool $overwrite = false): self; | ||
|
||
/** | ||
* Get view variables | ||
* | ||
* @psalm-return array|ArrayAccess&Traversable | ||
* @phpstan-return array|ArrayAccess&Traversable | ||
* | ||
* @throws void | ||
*/ | ||
public function getVariables(): array | ArrayAccess | Traversable; | ||
|
||
/** | ||
* Clear all variables | ||
* | ||
* Resets the internal variable container to an empty container. | ||
* | ||
* @throws void | ||
*/ | ||
public function clearVariables(): self; | ||
|
||
/** | ||
* Set the template to be used by this model | ||
* | ||
* @throws void | ||
*/ | ||
public function setTemplate(string $template): self; | ||
|
||
/** | ||
* Get the template to be used by this model | ||
* | ||
* @throws void | ||
*/ | ||
public function getTemplate(): string; | ||
|
||
/** | ||
* Add a child model | ||
* | ||
* @param string|null $captureTo Optional; if specified, the "capture to" value to set on the child | ||
* @param bool|null $append Optional; if specified, append to child with the same capture | ||
* | ||
* @throws void | ||
*/ | ||
public function addChild(ModelInterface $child, string | null $captureTo = null, bool | null $append = null): self; | ||
|
||
/** | ||
* Return all children. | ||
* | ||
* Return specifies an array, but may be any iterable object. | ||
* | ||
* @return list<ModelInterface> | ||
* | ||
* @throws void | ||
*/ | ||
public function getChildren(): array; | ||
|
||
/** | ||
* Does the model have any children? | ||
* | ||
* @throws void | ||
*/ | ||
public function hasChildren(): bool; | ||
|
||
/** | ||
* Clears out all child models | ||
* | ||
* @throws void | ||
*/ | ||
public function clearChildren(): self; | ||
|
||
/** | ||
* Returns an array of Viewmodels with captureTo value $capture | ||
* | ||
* @param bool $recursive search recursive through children, default true | ||
* | ||
* @return list<ModelInterface> | ||
* | ||
* @throws void | ||
*/ | ||
public function getChildrenByCaptureTo(string $capture, bool $recursive = true): array; | ||
|
||
/** | ||
* Set the name of the variable to capture this model to, if it is a child model | ||
* | ||
* @throws void | ||
*/ | ||
public function setCaptureTo(string $capture): self; | ||
|
||
/** | ||
* Get the name of the variable to which to capture this model | ||
* | ||
* @throws void | ||
*/ | ||
public function captureTo(): string; | ||
|
||
/** | ||
* Set flag indicating whether or not this is considered a terminal or standalone model | ||
* | ||
* @throws void | ||
*/ | ||
public function setTerminal(bool $terminate): self; | ||
|
||
/** | ||
* Is this considered a terminal or standalone model? | ||
* | ||
* @throws void | ||
*/ | ||
public function terminate(): bool; | ||
|
||
/** | ||
* Set flag indicating whether or not append to child with the same capture | ||
* | ||
* @throws void | ||
*/ | ||
public function setAppend(bool $append): self; | ||
|
||
/** | ||
* Is this append to child with the same capture? | ||
* | ||
* @throws void | ||
*/ | ||
public function isAppend(): bool; | ||
|
||
/** | ||
* Return count of children | ||
* | ||
* @throws void | ||
*/ | ||
#[ReturnTypeWillChange] | ||
public function count(): int; | ||
|
||
/** | ||
* Get iterator of children | ||
* | ||
* @return Traversable<int, ModelInterface> | ||
* | ||
* @throws void | ||
*/ | ||
#[ReturnTypeWillChange] | ||
public function getIterator(): Traversable; | ||
} |