当前位置: 首页>>代码示例>>PHP>>正文


PHP Definition::getFile方法代码示例

本文整理汇总了PHP中Definition::getFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::getFile方法的具体用法?PHP Definition::getFile怎么用?PHP Definition::getFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Definition的用法示例。


在下文中一共展示了Definition::getFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addService

 /**
  * Adds a service
  *
  * @param string $id
  * @param Definition $definition
  * @return string
  */
 private function addService($id, $definition)
 {
     $code = "  {$id}:\n";
     if ($definition->getClass()) {
         $code .= sprintf("    class: %s\n", $definition->getClass());
     }
     $tagsCode = '';
     foreach ($definition->getTags() as $name => $tags) {
         foreach ($tags as $attributes) {
             $att = array();
             foreach ($attributes as $key => $value) {
                 $att[] = sprintf('%s: %s', Yaml::dump($key), Yaml::dump($value));
             }
             $att = $att ? ', ' . implode(' ', $att) : '';
             $tagsCode .= sprintf("      - { name: %s%s }\n", Yaml::dump($name), $att);
         }
     }
     if ($tagsCode) {
         $code .= "    tags:\n" . $tagsCode;
     }
     if ($definition->getFile()) {
         $code .= sprintf("    file: %s\n", $definition->getFile());
     }
     if ($definition->getFactoryMethod()) {
         $code .= sprintf("    factory_method: %s\n", $definition->getFactoryMethod());
     }
     if ($definition->getFactoryService()) {
         $code .= sprintf("    factory_service: %s\n", $definition->getFactoryService());
     }
     if ($definition->getArguments()) {
         $code .= sprintf("    arguments: %s\n", Yaml::dump($this->dumpValue($definition->getArguments()), 0));
     }
     if ($definition->getProperties()) {
         $code .= sprintf("    properties: %s\n", Yaml::dump($this->dumpValue($definition->getProperties()), 0));
     }
     if ($definition->getMethodCalls()) {
         $code .= sprintf("    calls:\n      %s\n", str_replace("\n", "\n      ", Yaml::dump($this->dumpValue($definition->getMethodCalls()), 1)));
     }
     if (ContainerInterface::SCOPE_CONTAINER !== ($scope = $definition->getScope())) {
         $code .= sprintf("    scope: %s\n", $scope);
     }
     if ($callable = $definition->getConfigurator()) {
         if (is_array($callable)) {
             if (is_object($callable[0]) && $callable[0] instanceof Reference) {
                 $callable = array($this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]);
             } else {
                 $callable = array($callable[0], $callable[1]);
             }
         }
         $code .= sprintf("    configurator: %s\n", Yaml::dump($callable, 0));
     }
     return $code;
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:60,代码来源:YamlDumper.php

示例2: createService

 /**
  * Creates a service for a service definition.
  *
  * @param  Definition $definition A service definition instance
  * @param  string     $id         The service identifier
  *
  * @return object              The service described by the service definition
  */
 protected function createService(Definition $definition, $id)
 {
     if (null !== $definition->getFile()) {
         require_once self::resolveValue($definition->getFile(), $this->parameters);
     }
     $r = new \ReflectionClass(self::resolveValue($definition->getClass(), $this->parameters));
     $arguments = $this->resolveServices(self::resolveValue($definition->getArguments(), $this->parameters));
     if (null !== $definition->getConstructor()) {
         $service = call_user_func_array(array(self::resolveValue($definition->getClass(), $this->parameters), $definition->getConstructor()), $arguments);
     } else {
         $service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
     }
     if ($definition->isShared()) {
         $this->services[$id] = $service;
     }
     foreach ($definition->getMethodCalls() as $call) {
         $services = self::getServiceConditionals($call[1]);
         $ok = true;
         foreach ($services as $s) {
             if (!$this->hasService($s)) {
                 $ok = false;
                 break;
             }
         }
         if ($ok) {
             call_user_func_array(array($service, $call[0]), $this->resolveServices(self::resolveValue($call[1], $this->parameters)));
         }
     }
     if ($callable = $definition->getConfigurator()) {
         if (is_array($callable) && is_object($callable[0]) && $callable[0] instanceof Reference) {
             $callable[0] = $this->getService((string) $callable[0]);
         } elseif (is_array($callable)) {
             $callable[0] = self::resolveValue($callable[0], $this->parameters);
         }
         if (!is_callable($callable)) {
             throw new \InvalidArgumentException(sprintf('The configure callable for class "%s" is not a callable.', get_class($service)));
         }
         call_user_func($callable, $service);
     }
     return $service;
 }
开发者ID:CodingFabian,项目名称:symfony,代码行数:49,代码来源:Builder.php


注:本文中的Definition::getFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。