當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Helpers::formatArgs方法代碼示例

本文整理匯總了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);
 }
開發者ID:ondrejmirtes,項目名稱:di,代碼行數:39,代碼來源:ContainerBuilder.php

示例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);
 }
開發者ID:rostenkowski,項目名稱:nette,代碼行數:37,代碼來源:ContainerBuilder.php

示例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;
 }
開發者ID:jurasm2,項目名稱:nette,代碼行數:6,代碼來源:Method.php

示例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);
 }
開發者ID:nette,項目名稱:di,代碼行數:27,代碼來源:PhpGenerator.php


注:本文中的Nette\PhpGenerator\Helpers::formatArgs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。