Пример #1
0
 /**
  * @inheritdoc
  * @return string
  */
 public function filter($value)
 {
     if (is_null($value)) {
         $value = $this->default;
     }
     $value = StringHelper::toStr($value);
     return StringHelper::strCrop(StringHelper::strPad($value, $this->minLength, $this->padString, $this->padType), $this->maxLength, $this->cropType);
 }
Пример #2
0
 /**
  * @inheritdoc
  * @return string
  */
 public function filter($value)
 {
     if (!is_string($value)) {
         $value = StringHelper::toStr($value);
     }
     $pattern = StringHelper::toStr($this->pattern);
     $replacement = StringHelper::toStr($this->replacement);
     if (is_string($pattern) && !empty($pattern) && !empty($replacement)) {
         $value = preg_replace($pattern, $replacement, $value);
     }
     return parent::filter($value);
 }
Пример #3
0
 /**
  * Преобразование объекта в строку.
  * @return string
  */
 public function __toString()
 {
     $result = '';
     $attributes = [];
     foreach ($this->_attributes as $data) {
         $attributes[$data['name']] = $data['value'];
     }
     $reflection = new \ReflectionClass($this);
     foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $reflectionProperty) {
         $propName = $reflectionProperty->name;
         $attributes[$propName] = $this->{$propName};
     }
     ksort($attributes);
     foreach ($attributes as $attributeName => $attributeValue) {
         $result .= ', ' . StringHelper::printVar($attributeName) . '=>' . StringHelper::printVar($attributeValue);
     }
     return 'Object(' . $this->className() . '){' . trim($result, ', ') . '}';
 }
 public function __construct($attributeName, $filter, $previous = null)
 {
     $filter = StringHelper::strCrop(StringHelper::printVar($filter), 50);
     parent::__construct('Filter \'' . $filter . '\' for attribute \'' . $attributeName . '\' is wrong.', 1016, $previous);
 }