/** * @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; }
protected function getMessageString($message) { TypeChecker::getInstance()->isString($message, 'message')->throwTypeErrorIfNotValid(); if (empty($message)) { $message = $this->getDefaultMessage(); } return $this->processMessageTemplate($message); }
/** * @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; }
/** * @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; }
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); }
/** @inheritdoc */ public function setObjectName($objectName) { TypeChecker::getInstance()->isString($objectName, 'objectName')->throwTypeErrorIfNotValid(); $this->objectName = $objectName; }
/** * @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; }
/** * @param int $count * * @return $this * * @throws ArgumentTypeException */ public function rows($count) { TypeChecker::getInstance()->isInt($count, 'count')->throwTypeErrorIfNotValid(); $this->attribute('rows', $count); return $this; }
/** * @inheritdoc */ public function setStatus($status) { TypeChecker::getInstance()->isInt($status, 'status')->throwTypeErrorIfNotValid(); $sessionData = $this->getSessionData(); $sessionData['status'] = $status; $this->setSessionData($sessionData); }
protected function setMaxLength($maxLength) { TypeChecker::getInstance()->isInt($maxLength, 'maxLength')->throwTypeErrorIfNotValid(); $this->maxLength = $maxLength; }
protected function setMin($min) { TypeChecker::getInstance()->isInt($min, 'minValue')->throwTypeErrorIfNotValid(); $this->min = $min; }
public function getSelectorFromSettings($type = '') { if (empty($type)) { return ''; } $selector = Config::get(['renderer', 'repeat', $type], ''); TypeChecker::getInstance()->isString($selector, 'selector')->throwTypeErrorIfNotValid(); return $selector; }
protected function setMax($max) { TypeChecker::getInstance()->isInt($max, 'maxValue')->throwTypeErrorIfNotValid(); $this->max = $max; }
/** * @inheritdoc */ public function template($name) { TypeChecker::getInstance()->isString($name, 'name')->throwTypeErrorIfNotValid(); $this->templateName = $name; return $this; }
/** * @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; }
protected function addReplacement($replacement) { TypeChecker::getInstance()->isString($replacement, 'replacement')->throwTypeErrorIfNotValid(); $this->replacements[] = $replacement; }
/** * @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; }