private static function getValueType(BasePrimitive $primitive) { if ($primitive instanceof PrimitiveNoValue) { return null; } if ($primitive->isRequired()) { return ':'; } else { return '::'; } }
public function importMarried($scope) { if (BasePrimitive::import($scope) && isset($scope[$this->name][self::DAY], $scope[$this->name][self::MONTH], $scope[$this->name][self::YEAR]) && is_array($scope[$this->name])) { if ($this->isEmpty($scope)) { return !$this->isRequired(); } $hours = $minutes = $seconds = 0; if (isset($scope[$this->name][self::HOURS])) { $hours = (int) $scope[$this->name][self::HOURS]; } if (isset($scope[$this->name][self::MINUTES])) { $minutes = (int) $scope[$this->name][self::MINUTES]; } if (isset($scope[$this->name][self::SECONDS])) { $seconds = (int) $scope[$this->name][self::SECONDS]; } $year = (int) $scope[$this->name][self::YEAR]; $month = (int) $scope[$this->name][self::MONTH]; $day = (int) $scope[$this->name][self::DAY]; if (!checkdate($month, $day, $year)) { return false; } try { $stamp = new Timestamp($year . '-' . $month . '-' . $day . ' ' . $hours . ':' . $minutes . ':' . $seconds); } catch (WrongArgumentException $e) { // fsck wrong stamps return false; } if ($this->checkRanges($stamp)) { $this->value = $stamp; return true; } } return false; }
public function importMarried($scope) { if (BasePrimitive::import($scope) && is_array($scope[$this->name]) && !$this->isMarriedEmpty($scope)) { $this->raw = $scope[$this->name]; $this->imported = true; $hours = $minutes = $seconds = 0; if (isset($scope[$this->name][self::HOURS])) { $hours = (int) $scope[$this->name][self::HOURS]; } if (isset($scope[$this->name][self::MINUTES])) { $minutes = (int) $scope[$this->name][self::MINUTES]; } if (isset($scope[$this->name][self::SECONDS])) { $seconds = (int) $scope[$this->name][self::SECONDS]; } try { $time = new Time($hours . ':' . $minutes . ':' . $seconds); } catch (WrongArgumentException $e) { return false; } if ($this->checkLimits($time)) { $this->value = $time; return true; } } return false; }
public function import($scope) { if (!$this->className) { throw new WrongStateException("no class defined for PrimitiveIdentifierList '{$this->name}'"); } if (!BasePrimitive::import($scope)) { return null; } if (!is_array($scope[$this->name])) { return false; } $list = array_unique($scope[$this->name]); $values = array(); foreach ($list as $id) { if (!Assert::checkInteger($id)) { return false; } $values[] = $id; } $objectList = array(); foreach ($values as $value) { $className = $this->className; $objectList[] = new $className($value); } if (count($objectList) == count($values)) { $this->value = $objectList; return true; } return false; }
public function import($scope) { if (!$this->className) { throw new WrongStateException("no class defined for PrimitiveIdentifierList '{$this->name}'"); } if (!BasePrimitive::import($scope)) { return null; } if (!is_array($scope[$this->name])) { return false; } $list = array_unique($scope[$this->name]); $values = array(); foreach ($list as $id) { if ((string) $id == "" && $this->isIgnoreEmpty()) { continue; } if ($this->scalar && !Assert::checkScalar($id) || !$this->scalar && !Assert::checkInteger($id)) { if (!$this->isIgnoreWrong()) { return false; } else { continue; } //just skip it } $values[] = $id; } $objectList = $this->dao()->getListByIds($values); if ((count($objectList) == count($values) || $this->isIgnoreWrong()) && !($this->min && count($values) < $this->min) && !($this->max && count($values) > $this->max)) { $this->value = $objectList; return true; } return false; }
public function import($scope) { if (!BasePrimitive::import($scope)) { return null; } if (!$this->list) { throw new WrongStateException('list to check is not set; ' . 'use PrimitiveArray in case it is intentional'); } if (is_array($scope[$this->name])) { $values = array(); foreach ($scope[$this->name] as $value) { if (isset($this->list[$value])) { $values[] = $value; $this->selected[$value] = $this->list[$value]; } } if (count($values)) { $this->value = $values; return true; } } elseif (!empty($scope[$this->name])) { $this->value = array($scope[$this->name]); return true; } return false; }
public function import($scope) { if (!parent::import($scope)) { return null; } if ((is_string($scope[$this->name]) || is_integer($scope[$this->name])) && array_key_exists($scope[$this->name], $this->list)) { $this->value = $scope[$this->name]; return true; } return false; }
public function import($scope) { if (!BasePrimitive::import($scope)) { return null; } if (is_string($scope[$this->name]) && ($length = strlen($scope[$this->name])) < 16 && substr_count($scope[$this->name], '.', null, $length) == 3 && ip2long($scope[$this->name]) !== false) { $this->value = $scope[$this->name]; return true; } return false; }
/** * @throws WrongArgumentException * @return boolean **/ public function importValue($value) { if ($value === null) { return parent::importValue(null); } Assert::isTrue($value instanceof Hstore, 'importValue'); if (!$this->value instanceof Form) { $this->value = $this->makeForm(); } $this->value->import($value->getList()); $this->imported = true; return $this->value->getErrors() ? false : true; }
public function import($scope) { if (!BasePrimitive::import($scope)) { return null; } $this->value = (string) $scope[$this->name]; $this->selfFilter(); if (!empty($this->value) && is_string($this->value) && ($length = strlen($this->value)) && !($this->max && $length > $this->max) && !($this->min && $length < $this->min)) { return true; } else { $this->value = null; } return false; }
public function import($scope) { if (!BasePrimitive::import($scope)) { return null; } $this->value = $scope[$this->name]; $this->selfFilter(); if (is_array($this->value) && !($this->min && count($this->value) < $this->min) && !($this->max && count($this->value) > $this->max)) { return true; } else { $this->value = null; } return false; }
public function importSingle($scope) { if (!BasePrimitive::import($scope) || is_array($scope[$this->name])) { return null; } if (isset($scope[$this->name]) && is_string($scope[$this->name])) { $array = explode('-', $scope[$this->name], 2); $range = BaseRange::lazyCreate(ArrayUtils::getArrayVar($array, 0), ArrayUtils::getArrayVar($array, 1)); if ($range && $this->checkLimits($range)) { $this->value = $range; return true; } } return false; }
public function import($scope) { if (!BasePrimitive::import($scope)) { return null; } if (!is_scalar($scope[$this->name]) || is_bool($scope[$this->name])) { return false; } $this->value = (string) $scope[$this->name]; $this->selfFilter(); if (is_string($this->value) && ($this->value === '0' || !empty($this->value)) && ($length = mb_strlen($this->value)) && !($this->max && $length > $this->max) && !($this->min && $length < $this->min) && (!$this->pattern || preg_match($this->pattern, $this->value))) { return true; } else { $this->value = null; } return false; }
public function import($scope) { if (!BasePrimitive::import($scope)) { return null; } if ($this->single->isTrue()) { return $this->importSingle($scope); } elseif ($this->single->isFalse()) { return $this->importMarried($scope); } else { if (!$this->importMarried($scope)) { return $this->importSingle($scope); } return true; } Assert::isUnreachable(); }
public function import($scope) { if (!BasePrimitive::import($scope)) { return null; } if ($scope[$this->getName()] instanceof $this->className) { $this->value = $scope[$this->getName()]; return true; } try { $this->value = new $this->className($scope[$this->getName()]); return true; } catch (WrongArgumentException $e) { return false; } Assert::isUnreachable(); }
public function import($scope) { if (!BasePrimitive::import($scope)) { return null; } try { $this->checkNumber($scope[$this->name]); } catch (WrongArgumentException $e) { return false; } $this->value = $this->castNumber($scope[$this->name]); $this->selfFilter(); if (!(null !== $this->min && $this->value < $this->min) && !(null !== $this->max && $this->value > $this->max)) { return true; } else { $this->value = null; } return false; }
public function import($scope) { if (!$this->proto) { throw new WrongStateException("no proto defined for PrimitiveFormsList '{$this->name}'"); } if (!BasePrimitive::import($scope)) { return null; } if (!is_array($scope[$this->name])) { return false; } $error = false; $this->value = array(); foreach ($scope[$this->name] as $id => $value) { $this->value[$id] = $this->proto->makeForm()->import($value); if ($this->value[$id]->getErrors()) { $error = true; } } return !$error; }
/** * @return TimeList **/ public function clean() { parent::clean(); $this->value = array(); return $this; }
/** * @return Form **/ public function set(BasePrimitive $prm) { $this->primitives[$prm->getName()] = $prm; return $this; }
public function import($scope) { if (!BasePrimitive::import($scope) || !is_array($scope[$this->name]) || isset($scope[$this->name], $scope[$this->name]['error']) && $scope[$this->name]['error'] == UPLOAD_ERR_NO_FILE) { return null; } if (isset($scope[$this->name]['tmp_name'])) { $file = $scope[$this->name]['tmp_name']; } else { return false; } if (is_readable($file) && $this->checkUploaded($file)) { $size = filesize($file); } else { return false; } $this->mimeType = $scope[$this->name]['type']; if (!$this->isAllowedMimeType()) { return false; } if (isset($scope[$this->name]) && !($this->max && $size > $this->max) && !($this->min && $size < $this->min)) { $this->value = $scope[$this->name]['tmp_name']; $this->originalName = $scope[$this->name]['name']; return true; } return false; }
public function importMarried($scope) { if (BasePrimitive::import($scope) && isset($scope[$this->name][self::DAY], $scope[$this->name][self::MONTH], $scope[$this->name][self::YEAR]) && is_array($scope[$this->name])) { if ($this->isEmpty($scope)) { return !$this->isRequired(); } $year = (int) $scope[$this->name][self::YEAR]; $month = (int) $scope[$this->name][self::MONTH]; $day = (int) $scope[$this->name][self::DAY]; if (!checkdate($month, $day, $year)) { return false; } try { $date = new Date($year . '-' . $month . '-' . $day); } catch (WrongArgumentException $e) { // fsck wrong dates return false; } if ($this->checkRanges($date)) { $this->value = $date; return true; } } return false; }
/** * @throws WrongArgumentException * @return PrimitiveForm **/ public function setValue($value) { Assert::isTrue($value instanceof Form); return parent::setValue($value); }
/** * @return Form **/ private function checkImportResult(BasePrimitive $prm, $result) { if ($prm instanceof PrimitiveAlias && $result !== null) { $this->markGood($prm->getInner()->getName()); } $name = $prm->getName(); if (null === $result) { if ($prm->isRequired()) { $this->errors[$name] = self::MISSING; } } elseif (true === $result) { unset($this->errors[$name]); } elseif ($error = $prm->getCustomError()) { $this->errors[$name] = $error; } else { $this->errors[$name] = self::WRONG; } return $this; }