‪TYPO3CMS  10.4
VariablesContext.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 {
22  private ‪$variables;
23 
28 
29  public static function ‪create(‪Variables ‪$variables): self
30  {
31  return new static(‪$variables);
32  }
33 
34  private function ‪__construct(‪Variables ‪$variables)
35  {
36  $this->variables = ‪$variables;
37  }
38 
42  public function ‪getVariables(): ‪Variables
43  {
44  return ‪$this->variables;
45  }
46 
47  public function ‪matchesRequiredApplicables(‪Applicable ...$applicables): bool
48  {
49  if ($this->requiredApplicables === null || $this->requiredApplicables === []) {
50  return true;
51  }
52  $missingApplicables = array_udiff(
53  $this->requiredApplicables,
54  $applicables,
55  [$this, 'compareApplicables']
56  );
57  return count($missingApplicables) === 0;
58  }
59 
61  {
62  $target = clone $this;
63  $target->requiredApplicables = ‪$requiredApplicables;
64  return $target;
65  }
66 
67  public function ‪describe(): string
68  {
69  $items = [];
70  foreach ($this->variables->getArrayCopy() as $key => $value) {
71  $items[] = sprintf('$%s=%s', $key, $this->‪asHumanReadable($value));
72  }
73  return implode(', ', $items);
74  }
75 
76  private function ‪asHumanReadable($value)
77  {
78  if ($value === null) {
79  return '<null>';
80  }
81  if ($value === '') {
82  return '<empty>';
83  }
84  return $value;
85  }
86 
87  private function ‪compareApplicables(‪Applicable $a, ‪Applicable $b): int
88  {
89  if ($a === $b) {
90  return 0;
91  }
92  return 1;
93  }
94 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\getVariables
‪Variables getVariables()
Definition: VariablesContext.php:41
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\$variables
‪$variables
Definition: VariablesContext.php:22
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables
Definition: Variables.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\create
‪static create(Variables $variables)
Definition: VariablesContext.php:28
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext
Definition: VariablesContext.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\matchesRequiredApplicables
‪matchesRequiredApplicables(Applicable ... $applicables)
Definition: VariablesContext.php:46
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\$requiredApplicables
‪Applicable[] $requiredApplicables
Definition: VariablesContext.php:26
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Applicable
Definition: Applicable.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\describe
‪describe()
Definition: VariablesContext.php:66
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\asHumanReadable
‪asHumanReadable($value)
Definition: VariablesContext.php:75
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder
Definition: Applicable.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\__construct
‪__construct(Variables $variables)
Definition: VariablesContext.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\compareApplicables
‪compareApplicables(Applicable $a, Applicable $b)
Definition: VariablesContext.php:86
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariablesContext\withRequiredApplicables
‪withRequiredApplicables(Applicable ... $requiredApplicables)
Definition: VariablesContext.php:59