‪TYPO3CMS  10.4
JsConfirmation.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
24 final class ‪JsConfirmation extends ‪Enumeration
25 {
29  const ‪TYPE_CHANGE = 0b00000001;
30 
34  const ‪COPY_MOVE_PASTE = 0b00000010;
35 
39  const ‪DELETE = 0b00000100;
40 
44  const ‪FE_EDIT = 0b00001000;
45 
49  const ‪OTHER = 0b10000000;
50 
54  const ‪ALL = 255;
55 
60 
66  protected static ‪$allowedValues = self::TYPE_CHANGE | self::COPY_MOVE_PASTE | self::DELETE | self::FE_EDIT | ‪self::OTHER;
67 
74  public function ‪matches(‪JsConfirmation ‪$value)
75  {
76  ‪$value = (int)(string)‪$value;
77  $thisValue = (int)(string)$this;
78 
79  return (‪$value & $thisValue) == $thisValue;
80  }
81 
89  protected function ‪setValue(‪$value)
90  {
91  if ($this->‪isValid(‪$value)) {
92  $this->value = ‪$value;
93  } else {
94  parent::setValue(‪$value);
95  }
96  }
97 
104  protected function ‪isValid(‪$value)
105  {
106  if (‪$value < 255) {
107  // Check for combined bitmask or bitmask with bits unset from self::ALL
108  $unsetValues = (self::ALL ^ ‪$value);
109  return (‪$value & self::$allowedValues) === ‪$value || $unsetValues === ($unsetValues & ‪self::$allowedValues);
110  }
111  return parent::isValid(‪$value);
112  }
113 }
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\matches
‪bool matches(JsConfirmation $value)
Definition: JsConfirmation.php:73
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\__default
‪const __default
Definition: JsConfirmation.php:59
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\setValue
‪setValue($value)
Definition: JsConfirmation.php:88
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\COPY_MOVE_PASTE
‪const COPY_MOVE_PASTE
Definition: JsConfirmation.php:34
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\FE_EDIT
‪const FE_EDIT
Definition: JsConfirmation.php:44
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\isValid
‪bool isValid($value)
Definition: JsConfirmation.php:103
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\DELETE
‪const DELETE
Definition: JsConfirmation.php:39
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\OTHER
‪const OTHER
Definition: JsConfirmation.php:49
‪TYPO3\CMS\Core\Type\Exception
Definition: InvalidEnumerationDefinitionException.php:16
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\ALL
‪const ALL
Definition: JsConfirmation.php:54
‪TYPO3\CMS\Core\Type\Enumeration\$value
‪mixed $value
Definition: Enumeration.php:32
‪TYPO3\CMS\Core\Type\Enumeration
Definition: Enumeration.php:29
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\TYPE_CHANGE
‪const TYPE_CHANGE
Definition: JsConfirmation.php:29
‪TYPO3\CMS\Core\Type\Bitmask
Definition: JsConfirmation.php:16
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation
Definition: JsConfirmation.php:25
‪TYPO3\CMS\Core\Type\Bitmask\JsConfirmation\$allowedValues
‪static int $allowedValues
Definition: JsConfirmation.php:65