示例#1
0
 /**
  * @inheritdoc
  */
 public function delete($index)
 {
     TypeChecker::getInstance()->check($index, [SimpleTypes::INT, SimpleTypes::STRING], 'index')->throwTypeErrorIfNotValid();
     if (isset($this->objects[$index])) {
         unset($this->objects[$index]);
     }
     return $this;
 }
示例#2
0
 protected function getMessageString($message)
 {
     TypeChecker::getInstance()->isString($message, 'message')->throwTypeErrorIfNotValid();
     if (empty($message)) {
         $message = $this->getDefaultMessage();
     }
     return $this->processMessageTemplate($message);
 }
示例#3
0
 /**
  * @param string $title
  * @param string $value
  *
  * @return $this
  * @throws ArgumentTypeException
  */
 public function option($title, $value = '')
 {
     TypeChecker::getInstance()->isString($title, 'title')->throwTypeErrorIfNotValid();
     TypeChecker::getInstance()->check($value, [SimpleTypes::STRING, SimpleTypes::INT, SimpleTypes::FLOAT, SimpleTypes::NULL], 'title')->throwTypeErrorIfNotValid();
     $option = ['title' => $title, 'value' => $value];
     $this->options()->add($option);
     return $this;
 }
示例#4
0
 /**
  * @param string $value
  *
  * @return $this
  * @throws \Exception
  */
 public function setValue($value)
 {
     $typeChecker = TypeChecker::getInstance();
     if (!$typeChecker->check($value, [SimpleTypes::STRING, SimpleTypes::INT, SimpleTypes::FLOAT, SimpleTypes::NULL], 'value')) {
         $typeChecker->throwTypeError();
     }
     $this->value = $value;
     return $this;
 }
示例#5
0
 public function setValue($value)
 {
     TypeChecker::getInstance()->check($value, [SimpleTypes::STRING, SimpleTypes::ARR, SimpleTypes::BOOL, SimpleTypes::NULL], 'value')->throwTypeErrorIfNotValid();
     if (is_string($value)) {
         parent::setValue(true);
     } else {
         parent::setValue($value);
     }
     return $this;
 }
 /**
  * ArgumentException constructor.
  *
  * @param TypeChecker $checker
  * @param int         $code
  * @param \Exception  $previous
  */
 public function __construct(TypeChecker $checker, $code = 0, \Exception $previous = null)
 {
     parent::__construct($checker->getErrorMessage(), $code, $previous);
 }
示例#7
0
 /** @inheritdoc */
 public function setObjectName($objectName)
 {
     TypeChecker::getInstance()->isString($objectName, 'objectName')->throwTypeErrorIfNotValid();
     $this->objectName = $objectName;
 }
示例#8
0
 /**
  * @param string $value
  * @return $this
  * @throws ArgumentTypeException
  */
 public function setRangeMessage($value)
 {
     TypeChecker::getInstance()->isString($value, 'value')->throwTypeErrorIfNotValid();
     $this->rangeMessage = $value;
     return $this;
 }
 /**
  * @param NamedObjectInterface $object
  * @throws \Exception
  * @return $this
  */
 public function add($object)
 {
     TypeChecker::getInstance()->check($object, $this->getElementClasses(), 'object')->throwTypeErrorIfNotValid();
     $this->objects[$object->getName()] = $object;
     return $this;
 }
示例#10
0
 /**
  * @param int $count
  *
  * @return $this
  *
  * @throws ArgumentTypeException
  */
 public function rows($count)
 {
     TypeChecker::getInstance()->isInt($count, 'count')->throwTypeErrorIfNotValid();
     $this->attribute('rows', $count);
     return $this;
 }
示例#11
0
 /**
  * @inheritdoc
  */
 public function setStatus($status)
 {
     TypeChecker::getInstance()->isInt($status, 'status')->throwTypeErrorIfNotValid();
     $sessionData = $this->getSessionData();
     $sessionData['status'] = $status;
     $this->setSessionData($sessionData);
 }
示例#12
0
 protected function setMaxLength($maxLength)
 {
     TypeChecker::getInstance()->isInt($maxLength, 'maxLength')->throwTypeErrorIfNotValid();
     $this->maxLength = $maxLength;
 }
示例#13
0
 protected function setMin($min)
 {
     TypeChecker::getInstance()->isInt($min, 'minValue')->throwTypeErrorIfNotValid();
     $this->min = $min;
 }
示例#14
0
 public function getSelectorFromSettings($type = '')
 {
     if (empty($type)) {
         return '';
     }
     $selector = Config::get(['renderer', 'repeat', $type], '');
     TypeChecker::getInstance()->isString($selector, 'selector')->throwTypeErrorIfNotValid();
     return $selector;
 }
示例#15
0
 protected function setMax($max)
 {
     TypeChecker::getInstance()->isInt($max, 'maxValue')->throwTypeErrorIfNotValid();
     $this->max = $max;
 }
示例#16
0
 /**
  * @inheritdoc
  */
 public function template($name)
 {
     TypeChecker::getInstance()->isString($name, 'name')->throwTypeErrorIfNotValid();
     $this->templateName = $name;
     return $this;
 }
示例#17
0
 /**
  * @param $value
  * @return $this
  * @throws ArgumentTypeException
  */
 public function setValue($value)
 {
     TypeChecker::getInstance()->check($value, [SimpleTypes::STRING, SimpleTypes::ARR, SimpleTypes::NULL, SimpleTypes::INT, SimpleTypes::FLOAT, SimpleTypes::BOOL], 'value')->throwTypeErrorIfNotValid();
     $this->value = $value;
     return $this;
 }
示例#18
0
 protected function addReplacement($replacement)
 {
     TypeChecker::getInstance()->isString($replacement, 'replacement')->throwTypeErrorIfNotValid();
     $this->replacements[] = $replacement;
 }
示例#19
0
 /**
  * @inheritdoc
  */
 public function load($data = null)
 {
     TypeChecker::getInstance()->check($data, [SimpleTypes::ARR, SimpleTypes::NULL], 'data')->throwTypeErrorIfNotValid();
     if ($data === null && isset($_REQUEST[$this->getName()])) {
         $data = $_REQUEST[$this->getName()];
     } elseif ($data === null) {
         return false;
     }
     $deepCopy = new DeepCopy();
     foreach ($data as $name => $value) {
         $child = $this->child($name);
         if ($child instanceof FieldInterface) {
             $child->setValue($value);
         } elseif ($child instanceof BlockInterface && !$child->isRepeatableContainer()) {
             $child->load($value);
         } elseif ($child instanceof BlockInterface && $child->isRepeatableContainer()) {
             $value = array_values($value);
             $childrenCount = count($child->children());
             $childrenMaxIndex = $childrenCount - 1;
             $childrenDelta = count($value) - $childrenCount;
             if ($childrenDelta > 0) {
                 for ($i = 0; $i <= $childrenDelta; $i++) {
                     /** @var BlockInterface $objectClone */
                     $objectClone = $deepCopy->copy($child->getRepeatObject());
                     $objectValue = $objectClone->getValue();
                     if ($value[$i] == $objectValue) {
                         $childrenDelta--;
                         array_splice($value, $i, 1);
                         $i--;
                         continue;
                     }
                     $objectClone->setParent($child);
                     $objectClone->setName((string) ($childrenCount + $i));
                     $child->children()->add($objectClone);
                 }
             } elseif ($childrenDelta < 0) {
                 for ($i = 0; $i < abs($childrenDelta); $i++) {
                     $child->children()->delete($childrenMaxIndex - $i);
                 }
             } elseif ($childrenDelta == 0 && count($value) == 1 && !empty($value[0])) {
                 $objectClone = $deepCopy->copy($child->getRepeatObject());
                 $objectClone->setParent($child);
                 $objectClone->setName((string) count($child->children()));
                 $child->children()->add($objectClone);
             }
             $child->load($value);
         }
     }
     return true;
 }