TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
JsConfirmation.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Type\Bitmask;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
28  const TYPE_CHANGE = 0b00000001;
29 
33  const COPY_MOVE_PASTE = 0b00000010;
34 
38  const DELETE = 0b00000100;
39 
43  const FE_EDIT = 0b00001000;
44 
48  const OTHER = 0b10000000;
49 
53  const ALL = 255;
54 
55  const __default = self::ALL;
56 
62  protected static $allowedValues = self::TYPE_CHANGE | self::COPY_MOVE_PASTE | self::DELETE | self::FE_EDIT | self::OTHER;
63 
70  public function matches(JsConfirmation $value)
71  {
72  $value = (int)(string)$value;
73  $thisValue = (int)(string)$this;
74 
75  return ($value & $thisValue) == $thisValue;
76  }
77 
85  protected function setValue($value)
86  {
87  if ($value < 255) {
88  if (($value & self::$allowedValues) !== $value) {
89  throw new Exception\InvalidEnumerationValueException(
90  sprintf('Invalid value %s for %s', $value, __CLASS__),
91  1457175152
92  );
93  }
94  $this->value = $value;
95  } else {
96  parent::setValue($value);
97  }
98  }
99 
106  protected function isValid($value)
107  {
108  if ($value < 255) {
109  return ($value & self::$allowedValues) === $value;
110  }
111 
112  $value = (string)$value;
113  foreach (static::$enumConstants[get_class($this)] as $constantValue) {
114  if ($value === (string)$constantValue) {
115  return true;
116  }
117  }
118  return false;
119  }
120 }