本文整理匯總了PHP中Nette\PhpGenerator\Helpers::formatArgs方法的典型用法代碼示例。如果您正苦於以下問題:PHP Helpers::formatArgs方法的具體用法?PHP Helpers::formatArgs怎麽用?PHP Helpers::formatArgs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\PhpGenerator\Helpers
的用法示例。
在下文中一共展示了Helpers::formatArgs方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: formatPhp
/**
* Formats PHP statement.
* @return string
* @internal
*/
public function formatPhp($statement, $args)
{
array_walk_recursive($args, function (&$val) {
if ($val instanceof Statement) {
$val = self::literal($this->formatStatement($val));
} elseif ($val === $this) {
$val = self::literal('$this');
} elseif ($val instanceof ServiceDefinition) {
$val = '@' . current(array_keys($this->getDefinitions(), $val, TRUE));
}
if (!is_string($val)) {
return;
} elseif (substr($val, 0, 2) === '@@') {
$val = substr($val, 1);
} elseif (substr($val, 0, 1) === '@') {
$pair = explode('::', $val, 2);
$name = $this->getServiceName($pair[0]);
if (isset($pair[1]) && preg_match('#^[A-Z][A-Z0-9_]*\\z#', $pair[1], $m)) {
$val = $this->getDefinition($name)->getClass() . '::' . $pair[1];
} else {
if ($name === self::THIS_CONTAINER) {
$val = '$this';
} elseif ($name === $this->currentService) {
$val = '$service';
} else {
$val = $this->formatStatement(new Statement(['@' . self::THIS_CONTAINER, 'getService'], [$name]));
}
$val .= isset($pair[1]) ? PhpHelpers::formatArgs('->?', [$pair[1]]) : '';
}
$val = self::literal($val);
}
});
return PhpHelpers::formatArgs($statement, $args);
}
示例2: formatPhp
/**
* Formats PHP statement.
* @return string
*/
public function formatPhp($statement, $args)
{
$that = $this;
array_walk_recursive($args, function (&$val) use($that) {
if ($val instanceof Statement) {
$val = ContainerBuilder::literal($that->formatStatement($val));
} elseif ($val === $that) {
$val = ContainerBuilder::literal('$this');
} elseif ($val instanceof ServiceDefinition) {
$val = '@' . current(array_keys($that->definitions, $val, TRUE));
} elseif (is_string($val) && preg_match('#^[\\w\\\\]*::[A-Z][A-Z0-9_]*\\z#', $val, $m)) {
$val = ContainerBuilder::literal(ltrim($val, ':'));
}
if (is_string($val) && substr($val, 0, 1) === '@') {
$pair = explode('::', $val, 2);
$name = $that->getServiceName($pair[0]);
if (isset($pair[1]) && preg_match('#^[A-Z][A-Z0-9_]*\\z#', $pair[1], $m)) {
$val = $that->definitions[$name]->class . '::' . $pair[1];
} else {
if ($name === ContainerBuilder::THIS_CONTAINER) {
$val = '$this';
} elseif ($name === $that->currentService) {
$val = '$service';
} else {
$val = $that->formatStatement(new Statement(array('@' . ContainerBuilder::THIS_CONTAINER, 'getService'), array($name)));
}
$val .= isset($pair[1]) ? PhpHelpers::formatArgs('->?', array($pair[1])) : '';
}
$val = ContainerBuilder::literal($val);
}
});
return PhpHelpers::formatArgs($statement, $args);
}
示例3: addBody
/** @return Method */
public function addBody($statement, array $args = NULL)
{
$this->body .= (func_num_args() > 1 ? Helpers::formatArgs($statement, $args) : $statement) . "\n";
return $this;
}
示例4: formatPhp
/**
* Formats PHP statement.
* @return string
* @internal
*/
public function formatPhp($statement, $args)
{
array_walk_recursive($args, function (&$val) {
if ($val instanceof Statement) {
$val = new PhpLiteral($this->formatStatement($val));
} elseif (is_string($val) && substr($val, 0, 2) === '@@') {
// escaped text @@
$val = substr($val, 1);
} elseif (is_string($val) && substr($val, 0, 1) === '@' && strlen($val) > 1) {
// service reference
$name = substr($val, 1);
if ($name === ContainerBuilder::THIS_CONTAINER) {
$val = new PhpLiteral('$this');
} elseif ($name === $this->currentService) {
$val = new PhpLiteral('$service');
} else {
$val = new PhpLiteral($this->formatStatement(new Statement(['@' . ContainerBuilder::THIS_CONTAINER, 'getService'], [$name])));
}
}
});
return PhpHelpers::formatArgs($statement, $args);
}