Create new instance.

@param array $value
@param bool  $validate [optional]

@return static
@throws InvalidArgumentException
427839
public static function createFromArray($value, $validate = true)
    {
        if (!isset($value['perTaxRate'])) {
            throw new InvalidArgumentException("key perTaxRate is missing on root level");
        }

        $priceAggregate = new static();

        foreach ($value['perTaxRate'] as $perTaxRate) {
            $priceAggregate->addPrice(Price::createFromArray($perTaxRate, Price::GROSS, $validate));
        }

        return $priceAggregate;
    }
998494
protected function checkValueStructure(BaseValue $value)
    {
        if (!is_array($value->tags)) {
            throw new InvalidArgumentType(
                '$value->tags',
                'array',
                $value->tags
            );
        }

        foreach ($value->tags as $tag) {
            if (!$tag instanceof Tag) {
                throw new InvalidArgumentType(
                    "${tag}",
                    Value::class,
                    $tag
                );
            }
        }
    }
102369
public static function create($validator, $message = null)
    {
        $class = self::checkValidator($validator);

        /** @var ValidatorInterface $object */
        $object = new $class;
        if (!is_null($message)) {
            $object->setMessage($message);
        }
        return $object;
    }
444233
public static function make($value)
    {
        $value = static::prepareValue($value);
        $is_negation = static::parseIsNegation($value);
        list($operator, $value) = static::parseOperatorAndValue($value, $is_negation);

        return new static($operator, $value, $is_negation);
    }
413191
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if(!$exists) {
            return true;
        }
        
        if(!\is_callable($value)) {
            return 'formvalidator_make_callable';
        }
        
        if(empty($options)) {
            throw new \LogicException('Invalid options value given for callback rule');
        }
        
        /** @var \ReflectionMethod|\ReflectionFunction  $prototype */
        
        if(\is_array($value)) {
            $prototype = new \ReflectionMethod($value[0], $value[1]);
        } else {
            $prototype = new \ReflectionFunction($value);
        }
        
        $options = \explode('=', $options, 2);
        
        if(!empty($options[0])) {
            $params = \explode(',', $options[0]);
            
            /** @var \ReflectionParameter  $param */
            foreach($prototype->getParameters() as $pos => $param) {
                $type = $param->getType();
                
                if(!isset($params[$pos])) {
                    return array('formvalidator_make_callback_param_superfluos', array('{0}' => $pos));
                } elseif($params[$pos] === '') {
                    continue; // "mixed" type - wildcard
                } elseif(($type === null && $params[$pos] !== '') || \trim($params[$pos], '?') !== $type->getName()) {
                    return array('formvalidator_make_callback_param', array('{0}' => $pos, '{1}' => \trim($params[$pos], '?')));
                } elseif($params[$pos][0] === '?' && !$type->allowsNull()) {
                    return array('formvalidator_make_callback_param_nullable', array('{0}' => $pos));
                } elseif(\substr($params[$pos], -1) === '?' && !$param->isOptional()) {
                    return array('formvalidator_make_callback_param_optional', array('{0}' => $pos));
                }
            }
        }
        
        if(!empty($options[1])) {
            $return = $prototype->getReturnType();
            
            if($return === null) {
                return array('formvalidator_make_callback_return', array('{0}' => $options[1]));
            } elseif(($return->allowsNull() ? '?' : '').$return->getName() !== $options[1]) {
                return array('formvalidator_make_callback_return_type', array('{0}' => $options[1], '{1}' => $return->getName()));
            }
        }
        
        return true;
    }
1260638
protected function createValueFromInput( $inputValue )
    {
        if ( is_array( $inputValue ) )
        {
            foreach ( $inputValue as $index => $inputValueItem )
            {
                if ( !$inputValueItem instanceof Meta )
                {
                    throw new InvalidArgumentType(
                        '$inputValue[' . $index . ']',
                        "\\Novactive\\Bundle\\SEOBundle\\API\\Repository\\Values\\Metas\\Meta",
                        $inputValueItem
                    );
                }
            }
            $inputValue = new Value( $inputValue );
        }

        return $inputValue;
    }
185638
protected function createRoute($value)
    {
        if ($value instanceof Route) {
            return $value;
        }
        
        if (is_array($value)) {
            $value = (object)$value;
        }
        
        if (is_object($value) && is_callable($value)) {
            $value = (object)['fn' => $value];
        }
        
        if (!$value instanceof \stdClass) {
            throw new \InvalidArgumentException("Unable to create a Route from value " . var_export($value, true));
        }
        
        return new Route($value);
    }
193413
public function eachValidator(array $values, ...$args): bool
    {
        if (!$validator = \array_shift($args)) {
            throw new \InvalidArgumentException('must setting a validator for \'each\' validate.');
        }

        foreach ($values as $value) {
            $passed = false;

            if (\is_object($validator) && \method_exists($validator, '__invoke')) {
                $passed = $validator($value, ...$args);
            } elseif (\is_string($validator)) {
                // special for required
                if ('required' === $validator) {
                    $passed = !Validators::isEmpty($value);

                } elseif (isset($this->_validators[$validator])) {
                    $callback = $this->_validators[$validator];
                    $passed   = $callback($value, ...$args);

                } elseif (\method_exists($this, $method = $validator . 'Validator')) {
                    $passed = $this->$method($value, ...$args);

                } elseif (\method_exists(Validators::class, $validator)) {
                    $passed = Validators::$validator($value, ...$args);

                    // it is function name
                } elseif (\function_exists($validator)) {
                    $passed = $validator($value, ...$args);
                } else {
                    throw new \InvalidArgumentException("The validator [$validator] don't exists!");
                }
            }

            if (!$passed) {
                return false;
            }
        }

        return true;
    }
12681
public function validate(...$validate)
    {
        if( $this->validate === [] )
        {
            $this->validate = $validate;
        }
        else
        {
            $this->validate = array_merge($this->validate, $validate);
        }

        return $this;
    }
72063
public function map(ValueObject $value): PolicyCreateData
    {
        if (!$value instanceof PolicyCreateStruct) {
            throw new InvalidArgumentException('value', 'must be an instance of ' . PolicyCreateStruct::class);
        }

        $data = new PolicyCreateData();

        $data->setModule($value->module);
        $data->setFunction($value->function);
        $data->setLimitations($value->getLimitations());

        return $data;
    }
625122
final public static function byValue($value)
    {
        if (!isset(self::$constants[static::class])) {
            self::detectConstants(static::class);
        }

        $name = \array_search($value, self::$constants[static::class], true);
        if ($name === false) {
            throw new InvalidArgumentException(sprintf(
                'Unknown value %s for enumeration %s',
                \is_scalar($value)
                    ? \var_export($value, true)
                    : 'of type ' . (\is_object($value) ? \get_class($value) : \gettype($value)),
                static::class
            ));
        }

        if (!isset(self::$instances[static::class][$name])) {
            self::$instances[static::class][$name] = new static(self::$constants[static::class][$name]);
        }

        return self::$instances[static::class][$name];
    }
113047
public function validate($validate)
    {
        $this->_table->getValidator($validate);
        $this->_options['validate'] = $validate;

        return $this;
    }
398797
public function addAuth(array $auth, $validate = false)
    {
        $response = $this->getUser()->post(
            'source/auth/add',
            array('id' => $this->getId(), 'auth' => $auth, 'validate' => $validate)
        );

        $this->auth = $response['auth'];
    }
44697
protected function procPropValue($value, array &$validPropertyValues)
    {
        // If the value is not a nested item
        if (!($value instanceof ValueInterface)) {
            throw new InvalidArgumentException(
                sprintf(InvalidArgumentException::INVALID_PROPERTY_VALUE_STR, gettype($value)),
                InvalidArgumentException::INVALID_PROPERTY_VALUE
            );
        }

        // If the value isn't empty
        if (!$value->isEmpty()) {
            $validPropertyValues[] = $value;
        }
    }
278752
private function storeValue(string $name, bool $valid, $userInput = null, $value = null) : self
    {
        $this->values[$name] = [
            'userInput' => $userInput,
            'valid' => $valid,
            'value' => $value,
        ];

        // store array in friendly property
        if (stripos($name, '[') !== false && !is_null($value) && $value != '') {
            $names = explode('[', str_replace(']', '', $name));
            if ($names[sizeof($names) - 1] == '') {
                array_pop($names);
            }

            $valueAsArray = [];
            $ref = &$valueAsArray;
            $leave = false;

            while ($leave == false) {
                $key = array_shift($names);

                if (is_null($key)) {
                    $leave = true;
                    $ref = $value;
                } else {
                    $ref = &$ref[$key];
                }
            }

            $this->valuesAsArray = array_replace_recursive($this->valuesAsArray, $valueAsArray);
        }

        return $this;
    }
814205
public function save($new = false, $validate=true,$validateFields=[])
    {
        $this->isNewRecord = $new;

        if($validate){
            if(!$this->validate($validateFields)){
                return false;
            }
        }
        if(!static::beforeSave()) return false;
        $db = X::app()->db->table(self::tableName());
        $tableFields = $db->getFields(self::tableName());
        foreach($this->_modelData as $k=>$v){
            //删除数据库没有的字段
            if(!in_array($k,$tableFields)) unset($this->_modelData[$k]);
        }
        if ($new) {
            return $db->add($this->_modelData);
        } else {
            $id = $this->{self::$pk};
            unset($this->_modelData[self::$pk]);
            return $db->update([self::$pk => $id], $this->_modelData);
        }
    }
732212
public function validate($value)
    {
        if ($value === null) {
            return;
        }

        $normalized = $this->normalize($value);
        foreach ($this->validators as $validator) {
            $result = call_user_func($validator, $normalized);
            if (is_string($result)) {
                throw new InvalidValueException($result);
            } elseif ($result === false) {
                throw new InvalidValueException("Invalid value for '{$this->name}': $value");
            }
        }
    }