本文整理汇总了PHP中Symfony\Component\Config\Util\XmlUtils::phpize方法的典型用法代码示例。如果您正苦于以下问题:PHP XmlUtils::phpize方法的具体用法?PHP XmlUtils::phpize怎么用?PHP XmlUtils::phpize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Config\Util\XmlUtils
的用法示例。
在下文中一共展示了XmlUtils::phpize方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: phpize
/**
* Note that the following features are not supported:
* * strings with escaped quotes are not supported "foo\"bar";
* * string concatenation ("foo" "bar").
*/
private function phpize($value)
{
// trim on the right as comments removal keep whitespaces
$value = rtrim($value);
$lowercaseValue = strtolower($value);
switch (true) {
case defined($value):
return constant($value);
case 'yes' === $lowercaseValue || 'on' === $lowercaseValue:
return true;
case 'no' === $lowercaseValue || 'off' === $lowercaseValue || 'none' === $lowercaseValue:
return false;
case isset($value[1]) && ("'" === $value[0] && "'" === $value[strlen($value) - 1] || '"' === $value[0] && '"' === $value[strlen($value) - 1]):
// quoted string
return substr($value, 1, -1);
default:
return XmlUtils::phpize($value);
}
}
示例2: getArgumentsAsPhp
/**
* Returns arguments as valid php types.
*
* @param \DOMElement $node
* @param string $name
* @param bool $lowercase
*
* @return mixed
*/
private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
{
$arguments = array();
foreach ($this->getChildren($node, $name) as $arg) {
if ($arg->hasAttribute('name')) {
$arg->setAttribute('key', $arg->getAttribute('name'));
}
if (!$arg->hasAttribute('key')) {
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
} else {
$key = $arg->getAttribute('key');
}
// parameter keys are case insensitive
if ('parameter' == $name && $lowercase) {
$key = strtolower($key);
}
// this is used by DefinitionDecorator to overwrite a specific
// argument of the parent definition
if ($arg->hasAttribute('index')) {
$key = 'index_' . $arg->getAttribute('index');
}
switch ($arg->getAttribute('type')) {
case 'service':
$onInvalid = $arg->getAttribute('on-invalid');
$invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
if ('ignore' == $onInvalid) {
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
} elseif ('null' == $onInvalid) {
$invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
}
if ($strict = $arg->getAttribute('strict')) {
$strict = XmlUtils::phpize($strict);
} else {
$strict = true;
}
$arguments[$key] = new Reference($arg->getAttribute('id'), $invalidBehavior, $strict);
break;
case 'expression':
$arguments[$key] = new Expression($arg->nodeValue);
break;
case 'collection':
$arguments[$key] = $this->getArgumentsAsPhp($arg, $name, false);
break;
case 'string':
$arguments[$key] = $arg->nodeValue;
break;
case 'constant':
$arguments[$key] = constant($arg->nodeValue);
break;
default:
$arguments[$key] = XmlUtils::phpize($arg->nodeValue);
}
}
return $arguments;
}
示例3: parseOptions
/**
* Parses a collection of "option" XML nodes.
*
* @param \SimpleXMLElement $nodes The XML nodes
*
* @return array The options
*/
protected function parseOptions(\SimpleXMLElement $nodes)
{
$options = array();
foreach ($nodes as $node) {
if (count($node) > 0) {
if (count($node->value) > 0) {
$value = $this->parseValues($node->value);
} elseif (count($node->constraint) > 0) {
$value = $this->parseConstraints($node->constraint);
} else {
$value = array();
}
} else {
$value = XmlUtils::phpize($node);
if (is_string($value)) {
$value = trim($value);
}
}
$options[(string) $node['name']] = $value;
}
return $options;
}
示例4: testPhpize
/**
* @dataProvider getDataForPhpize
*/
public function testPhpize($expected, $value)
{
$this->assertSame($expected, XmlUtils::phpize($value));
}
示例5: phpize
/**
* Converts an xml value to a PHP type.
*
* @param mixed $value
*
* @return mixed
*/
public static function phpize($value)
{
return XmlUtils::phpize($value);
}
示例6: phpize
/**
* Transforms an XML attribute's value in a PHP value.
*
* @param \SimpleXMLElement $array
* @param string $key
* @param string $type
*
* @return bool|string|null
*/
private function phpize(\SimpleXMLElement $array, string $key, string $type)
{
if (!isset($array[$key])) {
return;
}
switch ($type) {
case 'string':
return (string) $array[$key];
case 'bool':
return (bool) XmlUtils::phpize($array[$key]);
}
}
示例7: getArgumentsAsPhp
/**
* Returns arguments as valid php types.
*
* @param \DOMElement $node
* @param string $name
* @param bool $lowercase
*
* @return mixed
*/
private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
{
$arguments = [];
foreach ($this->getChildren($node, $name) as $arg) {
if ($arg->hasAttribute('name')) {
$arg->setAttribute('key', $arg->getAttribute('name'));
}
if (!$arg->hasAttribute('key')) {
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
} else {
$key = $arg->getAttribute('key');
}
// parameter keys are case insensitive
if ('parameter' == $name && $lowercase) {
$key = strtolower($key);
}
// this is used by DefinitionDecorator to overwrite a specific
// argument of the parent definition
if ($arg->hasAttribute('index')) {
$key = 'index_' . $arg->getAttribute('index');
}
switch ($arg->getAttribute('type')) {
case 'service':
$arguments[$key] = $this->containerConfiguration->createReferenceFor($arg->getAttribute('id'), $arg->getAttribute('container') ?: null);
break;
case 'expression':
$arguments[$key] = new Expression($arg->nodeValue);
break;
case 'collection':
$arguments[$key] = $this->getArgumentsAsPhp($arg, $name, false);
break;
case 'string':
$arguments[$key] = $arg->nodeValue;
break;
case 'constant':
$arguments[$key] = constant($arg->nodeValue);
break;
default:
$arguments[$key] = XmlUtils::phpize($arg->nodeValue);
}
}
return $arguments;
}
示例8: getReferenceByParameters
public function getReferenceByParameters($parameters)
{
$viewReference = array();
$arguments = array();
foreach ($parameters as $key => $value) {
$arguments[$key] = '@' . $key . '="' . $value . '"';
}
if ($xmlReference = $this->readCache()->xpath("//viewReference[" . implode(' and ', $arguments) . "]")) {
$viewReference['id'] = XmlUtils::phpize($xmlReference[0]['id']);
$viewReference['locale'] = XmlUtils::phpize($xmlReference[0]['locale']);
$viewReference['entityId'] = XmlUtils::phpize($xmlReference[0]['entityId']);
$viewReference['entityNamespace'] = XmlUtils::phpize($xmlReference[0]['entityNamespace']);
$viewReference['url'] = XmlUtils::phpize($xmlReference[0]['url']);
$viewReference['viewId'] = XmlUtils::phpize($xmlReference[0]['viewId']);
$viewReference['viewNamespace'] = XmlUtils::phpize($xmlReference[0]['viewNamespace']);
$viewReference['patternId'] = XmlUtils::phpize($xmlReference[0]['patternId']);
$viewReference['name'] = XmlUtils::phpize($xmlReference[0]['name']);
} else {
$viewReference = null;
}
return $viewReference;
}
示例9: getAttributeAsPhp
/**
* Converts an attribute as a PHP type.
*
* @param SimpleXMLElement $xml
* @param $name
* @return mixed
*/
public function getAttributeAsPhp(SimpleXMLElement $xml, $name)
{
return XmlUtils::phpize($xml[$name]);
}
示例10: phpize
/**
* Converts an xml value to a PHP type.
*
* @param mixed $value
*
* @return mixed
*/
public static function phpize($value)
{
return \Symfony\Component\Config\Util\XmlUtils::phpize($value);
}
示例11: parseOptionNode
protected function parseOptionNode(\DOMNodeList $nodes, $path)
{
$options = array();
foreach ($nodes as $node) {
$options[$this->readAttribute($node, 'name', sprintf('in "%s"', $path))] = XmlUtils::phpize($node->nodeValue);
}
return $options;
}