TYPO3 CMS  TYPO3_8-7
JsConfirmation.php
Go to the documentation of this file.
1 <?php
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 
58  const __default = self::ALL;
59 
65  protected static $allowedValues = self::TYPE_CHANGE | self::COPY_MOVE_PASTE | self::DELETE | self::FE_EDIT | self::OTHER;
66 
73  public function matches(JsConfirmation $value)
74  {
75  $value = (int)(string)$value;
76  $thisValue = (int)(string)$this;
77 
78  return ($value & $thisValue) == $thisValue;
79  }
80 
88  protected function setValue($value)
89  {
90  if ($this->isValid($value)) {
91  $this->value = $value;
92  } else {
93  parent::setValue($value);
94  }
95  }
96 
103  protected function isValid($value)
104  {
105  if ($value < 255) {
106  // Check for combined bitmask or bitmask with bits unset from self::ALL
107  $unsetValues = (self::ALL ^ $value);
108  return ($value & self::$allowedValues) === $value || $unsetValues === ($unsetValues & self::$allowedValues);
109  }
110  return parent::isValid($value);
111  }
112 }