Transforms a YAML attribute's value in PHP value.

@throws InvalidArgumentException

@return bool|string|null
480879
private function phpize(array $array, string $key, string $type)
    {
        if (!isset($array[$key])) {
            return null;
        }

        switch ($type) {
            case 'bool':
                if (\is_bool($array[$key])) {
                    return $array[$key];
                }
                break;
            case 'string':
                if (\is_string($array[$key])) {
                    return $array[$key];
                }
                break;
        }

        throw new InvalidArgumentException(sprintf('The property "%s" must be a "%s", "%s" given.', $key, $type, \gettype($array[$key])));
    }
1324639
public function jsonSerialize() {
    // Define empty attribute values.
    // @see http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
    $present = function($value) {
      if ($value === NULL) {
        return FALSE;
      }
      if (is_string($value)) {
        return $value !== '';
      }
      if (is_array($value)) {
        return (bool) $value;
      }
      return TRUE;
    };

    // Protected attributes are not outputted via parent::__toString().
    $out = get_object_vars($this);

    // Required attributes.
    $names = array_diff(array_keys($out), $this->optional());
    foreach ($names as $name) {
      if (!isset($out[$name]) || !$present($out[$name])) {
        $this->triggerError("Missing required attribute ${name}.");
        return NULL;
      }
    }

    // Unset optional attributes.
    $names = array_intersect($this->optional(), array_keys($out));
    foreach ($names as $name) {
      if (!$present($out[$name])) {
        unset($out[$name]);
      }
    }

    // Return empty object, not array.
    if (empty($out)) {
      return new \stdClass();
    }

    return $out;
  }
458299
public function useKeyAsIndexAttribute($key, $normalize = false)
    {
        if (null === $key) {
            $this->indexAttrKey = null;
            return;
        }

        if (true !== $normalize && !$this->isValidNodeName($key)) {
            throw new \InvalidArgumentException(sprintf('%s is an invalid attribute name', $key));
        }

        $this->indexAttrKey = $normalize ? $this->normalizer->normalize($key) : $key;
    }
904386
public function set($key, $value)
    {
        if (!is_string($key)) {
            throw new \InvalidArgumentException('Expected string as key');
        }

        if (!is_string($value)) {
            throw new \InvalidArgumentException('Expected string as value');
        }

        $queryString = 'REPLACE INTO ' . $this->name . ' VALUES (:key, :value);';
        $stmt = $this->db->prepare($queryString);
        $stmt->bindParam(':key', $key, \PDO::PARAM_STR);
        $stmt->bindParam(':value', $value, \PDO::PARAM_STR);
        $stmt->execute();
        $this->data[(string)$key] = $value;

        return $this->data[$key];
    }
865463
public function transform(AttributeEvent $event)
    {
        $value = $event->getValue();

        if ($value instanceof \DateTime) {
            $timestamp = $value->getTimestamp();
        } elseif (is_int($value)) {
            $timestamp = $value;
        } else {
            $timestamp = strtotime($value);
            if ($timestamp === false) {
                throw new \InvalidArgumentException('Expecting value to be an instance of \DateTime, a Unix timestamp, ot a textual datetime description');
            }
        }

        $event->setValue($timestamp);
    }
46605
public function toArray()
    {
        if ($this->field === null || $this->value === null) {
            throw new InvalidArgument('"field" and "value" must be set for this type of query');
        }

        $definition = [
            'value' => $this->getValue(),
        ];

        if ($this->hasBoost()) {
            $definition['boost'] = $this->getBoost();
        }

        if (!empty($this->flags)) {
            $definition['flags'] = $this->getFlagsValue();
        }

        if ($this->maxDeterminizedStates !== null) {
            $definition['max_determinized_states'] = $this->maxDeterminizedStates;
        }

        return [
            'regexp' => [
                $this->getField() => $definition,
            ],
        ];
    }
714843
public function attr()
    {
        $args = func_get_args();

        if (isset($args[0]) && is_array($args[0])) {
            $this->attributes = array_merge($this->attributes, $args[0]);

            return $this;
        } elseif (isset($args[0]) && isset($args[1])) {
            $this->attributes[$args[0]] = $args[1];

            return $this;
        } elseif (isset($args[0])) {
            return isset($this->attributes[$args[0]]) ? $this->attributes[$args[0]] : null;
        }

        return $this->attributes;
    }
980133
public function Render()
    {
        $string = $this->string;
        $tag = $this->tag;

        $classes = $this->classes;
        if (Count($classes)) {
            if ($classPrefix = $this->classPrefix) {
                foreach ($classes as $key => $value) {
                    $prefixedClass = $classPrefix . '__' . $value;
                    $classes[$prefixedClass] = $prefixedClass;
                }
            }
            $this->addAttribute('class', implode(' ', $classes));
        }

        if ($this->isVoidElement() && $string) {
            if ($voidAttributeName = $this->VoidElements[$tag]) {
                $this->addAttribute($voidAttributeName, $string);
            } else {
                throw new InvalidArgumentException("Void element \"{$tag}\" cannot have string");
            }
        }

        $attributes = [];
        foreach ($this->attributes as $name => $value) {
            $attributes[] = sprintf(
                '%s="%s"',
                $name,
                Convert::raw2att($value)
            );
        }
        $attributes = Count($attributes) ? ' ' . implode(' ', $attributes) : '';

        if ($this->isVoidElement()) {
            return "<{$tag}{$attributes} />";
        }

        if (!isset($string) || !$string || $string == '') {
            return null;
        }

        return "<{$tag}{$attributes}>{$string}</{$tag}>";
    }
1120229
public function convert()
    {
        //Cache result if you want to run it multiple times
        if (!empty($this->output))
        {
            return $this->output;
        }

        if (empty($this->data))
        {
            throw new \Exception("No data specified!");
        }

        $this->output = '<?xml version="' . static::XML_VERSION . '" encoding="' . static::XML_ENCODING . '"?>' . PHP_EOL;

        $this->convertNodeToXML($this->data, $this->rootNode, 0);

        $this->output = trim($this->output);

        return $this->output;
    }
88649
public function validateAttributeValue()
    {
        $at = $this->attributeType;
        $at->getController()->setAttributeKey($this->attributeKey);
        $e = true;
        if (method_exists($at->getController(), 'validateValue')) {
            $e = $at->getController()->validateValue();
        }
        return $e;
    }
354091
protected function normalizeAttributes()
    {
        if ($this->attributes === null) {
            if ($this->model instanceof Model) {
                $this->attributes = $this->model->attributes();
            } elseif (is_object($this->model)) {
                $this->attributes = $this->model instanceof Arrayable ? $this->model->toArray() : array_keys(get_object_vars($this->model));
            } elseif (is_array($this->model)) {
                $this->attributes = array_keys($this->model);
            } else {
                throw new InvalidConfigException('The "model" property must be either an array or an object.');
            }
            sort($this->attributes);
        }

        foreach ($this->attributes as $i => $attribute) {
            if (is_string($attribute)) {
                if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $attribute, $matches)) {
                    throw new InvalidConfigException('The attribute must be specified in the format of "attribute", "attribute:format" or "attribute:format:label"');
                }
                $attribute = [
                    'attribute' => $matches[1],
                    'format' => isset($matches[3]) ? $matches[3] : 'text',
                    'label' => isset($matches[5]) ? $matches[5] : null,
                ];
            }

            if (!is_array($attribute)) {
                throw new InvalidConfigException('The attribute configuration must be an array.');
            }

            if (isset($attribute['visible']) && !$attribute['visible']) {
                unset($this->attributes[$i]);
                continue;
            }

            if (!isset($attribute['format'])) {
                $attribute['format'] = 'text';
            }
            if (isset($attribute['attribute'])) {
                $attributeName = $attribute['attribute'];
                if (!isset($attribute['label'])) {
                    $attribute['label'] = $this->model instanceof Model ? $this->model->getAttributeLabel($attributeName) : Inflector::camel2words($attributeName, true);
                }
                if (!array_key_exists('value', $attribute)) {
                    $attribute['value'] = ArrayHelper::getValue($this->model, $attributeName);
                }
            } elseif (!isset($attribute['label']) || !array_key_exists('value', $attribute)) {
                throw new InvalidConfigException('The attribute configuration requires the "attribute" element to determine the value and display label.');
            }

            $this->attributes[$i] = $attribute;
        }
    }
1310957
public function transform($value): ?string
    {
        /** TODO add sanity check is array of Location object? */
        if (!is_array($value) || empty($value)) {
            return null;
        }

        return implode(',', array_column($value, 'id'));
    }
947347
public function setAttribute()
    {
        return function ($next, $value, $args) {
            $key = $args->get('key');

            if ($this->hasMapping($key)) {
                return $this->setMappedAttribute($key, $value);
            }

            return $next($value, $args);
        };
    }
35741
public function value(): ?string
    {
        if (is_empty($this->key)) {
            return $this->original;
        }

        $value = $this->replacements->get($this->key, null);

        return $this->convertToString($value);
    }
338068
public function transform($value)
    {
        if (!$value instanceof Value) {
            return null;
        }

        $ids = [];
        $parentIds = [];
        $keywords = [];
        $locales = [];

        foreach ($value->tags as $tag) {
            $tagKeyword = $tag->getKeyword($this->field->languageCode);
            $mainKeyword = $tag->getKeyword();

            $ids[] = $tag->id;
            $parentIds[] = $tag->parentTagId;
            $keywords[] = $tagKeyword !== null ? $tagKeyword : $mainKeyword;
            $locales[] = $tagKeyword !== null ? $this->field->languageCode : $tag->mainLanguageCode;
        }

        return [
            'ids' => implode('|#', $ids),
            'parent_ids' => implode('|#', $parentIds),
            'keywords' => implode('|#', $keywords),
            'locales' => implode('|#', $locales),
        ];
    }
476526
public function setNull($null)
    {
        if (!is_bool($null)) {
            throw new \InvalidArgumentException('The attribute null on the class Attribute has to be boolean (' . gettype($null) . ('object' === gettype($null) ? ' ' . get_class($null) : '') . ' given).');
        }

        $this->null = $null;

        return $this;
    }
959007
public function setAttribute( $key, $value = NULL, $strict = TRUE )
	{
		if( empty( $key ) )																			//  no valid attribute key defined
			throw new InvalidArgumentException( 'Key must have content' );							//  throw exception
		$key	= strtolower( $key );
		if( array_key_exists( $key, $this->attributes ) && $strict )								//  attribute key already has a value
			throw new RuntimeException( 'Attribute "'.$key.'" is already set' );					//  throw exception
		if( !preg_match( '/^[a-z0-9:_-]+$/', $key ) )												//  key is invalid
			throw new InvalidArgumentException( 'Invalid attribute key "'.$key.'"' );				//  throw exception

		if( $value === NULL || $value === FALSE ){													//  no value available
			if( array_key_exists( $key, $this->attributes ) )										//  attribute exists
				unset( $this->attributes[$key] );													//  remove attribute
		}
		else
		{
//			if( is_string( $value ) || is_numeric( $value ) )										//  value is string or numeric
//				if( preg_match( '/[^\\\]"/', $value ) )												//  detect injection
//					throw new InvalidArgumentException( 'Invalid attribute value' );				//  throw exception
			$this->attributes[$key]	= $value;														//  set attribute
		}
	}