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


PHP BuilderConfiguration::addResource方法代码示例

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


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

示例1: load

  /**
   * Loads an array of XML files.
   *
   * @param  string $file An XML file path
   *
   * @return BuilderConfiguration A BuilderConfiguration instance
   */
  public function load($file)
  {
    $path = $this->findFile($file);

    $xml = $this->parseFile($path);

    $configuration = new BuilderConfiguration();

    $configuration->addResource(new FileResource($path));

    // anonymous services
    $xml = $this->processAnonymousServices($configuration, $xml, $file);

    // imports
    $this->parseImports($configuration, $xml, $file);

    // parameters
    $this->parseParameters($configuration, $xml, $file);

    // services
    $this->parseDefinitions($configuration, $xml, $file);

    // extensions
    $this->loadFromExtensions($configuration, $xml);

    return $configuration;
  }
开发者ID:nicolasmartin,项目名称:symfony,代码行数:34,代码来源:XmlFileLoader.php

示例2: load

 /**
  * Loads an array of Yaml files.
  *
  * @param mixed                $resource       The resource
  * @param Boolean              $main           Whether this is the main load() call
  * @param BuilderConfiguration $configuration  A BuilderConfiguration instance to use for the configuration
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function load($file, $main = true, BuilderConfiguration $configuration = null)
 {
     $path = $this->findFile($file);
     $content = $this->loadFile($path);
     if (null === $configuration) {
         $configuration = new BuilderConfiguration();
     }
     $configuration->addResource(new FileResource($path));
     if (!$content) {
         return $configuration;
     }
     // imports
     $this->parseImports($configuration, $content, $file);
     // extensions
     $this->loadFromExtensions($configuration, $content);
     if ($main) {
         $configuration->mergeExtensionsConfiguration();
     }
     // parameters
     if (isset($content['parameters'])) {
         foreach ($content['parameters'] as $key => $value) {
             $configuration->setParameter(strtolower($key), $this->resolveServices($value));
         }
     }
     // services
     $this->parseDefinitions($configuration, $content, $file);
     return $configuration;
 }
开发者ID:pgodel,项目名称:PageRoller,代码行数:37,代码来源:YamlFileLoader.php

示例3: load

 /**
  * Loads a resource.
  *
  * @param  string $file An INI file path
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  *
  * @throws \InvalidArgumentException When ini file is not valid
  */
 public function load($file)
 {
     $path = $this->findFile($file);
     $configuration = new BuilderConfiguration();
     $configuration->addResource(new FileResource($path));
     $result = parse_ini_file($path, true);
     if (false === $result || array() === $result) {
         throw new \InvalidArgumentException(sprintf('The %s file is not valid.', $file));
     }
     if (isset($result['parameters']) && is_array($result['parameters'])) {
         foreach ($result['parameters'] as $key => $value) {
             $configuration->setParameter(strtolower($key), $value);
         }
     }
     return $configuration;
 }
开发者ID:jacques-sounvi,项目名称:addressbook,代码行数:25,代码来源:IniFileLoader.php

示例4: Definition

$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$t->is($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
$t->ok($configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');

$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$t->is($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');

try
{
  $configuration->getDefinition('baz');
  $t->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
catch (InvalidArgumentException $e)
{
  $t->pass('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}

// ->findDefinition()
$t->diag('->findDefinition()');
$configuration = new BuilderConfiguration(array('foo' => $definition = new Definition('FooClass')));
$configuration->setAlias('bar', 'foo');
$configuration->setAlias('foobar', 'bar');
$t->is($configuration->findDefinition('foobar'), $definition, '->findDefinition() returns a Definition');

// ->addResource() ->getResources()
$t->diag('->addResource() ->getResources()');
$configuration = new BuilderConfiguration();
$configuration->addResource($a = new FileResource('foo.xml'));
$configuration->addResource($b = new FileResource('foo.yml'));
$t->is($configuration->getResources(), array($a, $b), '->getResources() returns an array of resources read for the current configuration');
开发者ID:nicolasmartin,项目名称:symfony,代码行数:30,代码来源:BuilderConfigurationTest.php

示例5: testResources

 public function testResources()
 {
     $configuration = new BuilderConfiguration();
     $configuration->addResource($a = new FileResource('foo.xml'));
     $configuration->addResource($b = new FileResource('foo.yml'));
     $this->assertEquals(array($a, $b), $configuration->getResources(), '->getResources() returns an array of resources read for the current configuration');
 }
开发者ID:jacques-sounvi,项目名称:addressbook,代码行数:7,代码来源:BuilderConfigurationTest.php

示例6: testResources

 /**
  * @covers Symfony\Components\DependencyInjection\BuilderConfiguration::getResources
  * @covers Symfony\Components\DependencyInjection\BuilderConfiguration::addResource
  */
 public function testResources()
 {
     $configuration = new BuilderConfiguration();
     $configuration->addResource($a = new FileResource(self::$fixturesPath . '/xml/services1.xml'));
     $configuration->addResource($b = new FileResource(self::$fixturesPath . '/xml/services2.xml'));
     $this->assertEquals(array($a, $b), $configuration->getResources(), '->getResources() returns an array of resources read for the current configuration');
 }
开发者ID:bill97420,项目名称:symfony,代码行数:11,代码来源:BuilderConfigurationTest.php

示例7: configLoad

 /**
  * Loads the web configuration.
  *
  * @param array                $config        A configuration array
  * @param BuilderConfiguration $configuration A BuilderConfiguration instance
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function configLoad($config, BuilderConfiguration $configuration)
 {
     if (!$configuration->hasDefinition('controller_manager')) {
         $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
         $configuration->merge($loader->load($this->resources['web']));
     }
     if (isset($config['ide']) && 'textmate' === $config['ide']) {
         $configuration->setParameter('debug.file_link_format', 'txmt://open?url=file://%%f&line=%%l');
     }
     if (isset($config['toolbar']) && $config['toolbar']) {
         $config['profiler'] = true;
     }
     if (isset($config['profiler'])) {
         if ($config['profiler']) {
             if (!$configuration->hasDefinition('profiler')) {
                 $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
                 $configuration->merge($loader->load('profiling.xml'));
             }
         } elseif ($configuration->hasDefinition('profiler')) {
             $configuration->getDefinition('profiling')->clearAnnotations();
         }
     }
     // toolbar need to be registered after the profiler
     if (isset($config['toolbar'])) {
         if ($config['toolbar']) {
             if (!$configuration->hasDefinition('debug.toolbar')) {
                 $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
                 $configuration->merge($loader->load('toolbar.xml'));
             }
         } elseif ($configuration->hasDefinition('debug.toolbar')) {
             $configuration->getDefinition('debug.toolbar')->clearAnnotations();
         }
     }
     if (isset($config['validation'])) {
         if ($config['validation']) {
             if (!$configuration->hasDefinition('validator')) {
                 $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
                 $configuration->merge($loader->load($this->resources['validation']));
             }
             $xmlMappingFiles = array();
             $yamlMappingFiles = array();
             $messageFiles = array();
             // default entries by the framework
             $xmlMappingFiles[] = __DIR__ . '/../../../Components/Form/Resources/config/validation.xml';
             $messageFiles[] = __DIR__ . '/../../../Components/Validator/Resources/i18n/messages.en.xml';
             $messageFiles[] = __DIR__ . '/../../../Components/Form/Resources/i18n/messages.en.xml';
             foreach ($this->bundles as $className) {
                 $tmp = dirname(str_replace('\\', '/', $className));
                 $namespace = str_replace('/', '\\', dirname($tmp));
                 $bundle = basename($tmp);
                 foreach ($this->bundleDirs as $dir) {
                     if (file_exists($file = $dir . '/' . $bundle . '/Resources/config/validation.xml')) {
                         $xmlMappingFiles[] = realpath($file);
                     }
                     if (file_exists($file = $dir . '/' . $bundle . '/Resources/config/validation.yml')) {
                         $yamlMappingFiles[] = realpath($file);
                     }
                     // TODO do we really want the message files of all cultures?
                     foreach (glob($dir . '/' . $bundle . '/Resources/i18n/messages.*.xml') as $file) {
                         $messageFiles[] = realpath($file);
                     }
                 }
             }
             $xmlFilesLoader = new Definition($configuration->getParameter('validator.mapping.loader.xml_files_loader.class'), array($xmlMappingFiles));
             $yamlFilesLoader = new Definition($configuration->getParameter('validator.mapping.loader.yaml_files_loader.class'), array($yamlMappingFiles));
             $configuration->setDefinition('validator.mapping.loader.xml_files_loader', $xmlFilesLoader);
             $configuration->setDefinition('validator.mapping.loader.yaml_files_loader', $yamlFilesLoader);
             $configuration->setParameter('validator.message_interpolator.files', $messageFiles);
             foreach ($xmlMappingFiles as $file) {
                 $configuration->addResource(new FileResource($file));
             }
             foreach ($yamlMappingFiles as $file) {
                 $configuration->addResource(new FileResource($file));
             }
             foreach ($messageFiles as $file) {
                 $configuration->addResource(new FileResource($file));
             }
             if (isset($config['validation']['annotations']) && $config['validation']['annotations'] === true) {
                 $annotationLoader = new Definition($configuration->getParameter('validator.mapping.loader.annotation_loader.class'));
                 $configuration->setDefinition('validator.mapping.loader.annotation_loader', $annotationLoader);
                 $loader = $configuration->getDefinition('validator.mapping.loader.loader_chain');
                 $arguments = $loader->getArguments();
                 array_unshift($arguments, new Reference('validator.mapping.loader.annotation_loader'));
                 $loader->setArguments($arguments);
             }
         } elseif ($configuration->hasDefinition('validator')) {
             $configuration->getDefinition('validator')->clearAnnotations();
         }
     }
     return $configuration;
 }
开发者ID:pgodel,项目名称:PageRoller,代码行数:99,代码来源:WebExtension.php

示例8: detectMetadataDriver

 /**
  * Detects what metadata driver to use for the supplied directory.
  *
  * @param string $dir A directory path
  * @param Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A builder configuration
  *
  * @return string|null A metadata driver short name, if one can be detected
  */
 protected static function detectMetadataDriver($dir, BuilderConfiguration $configuration)
 {
     // add the closest existing directory as a resource
     $resource = $dir . '/Resources/config/doctrine/metadata';
     while (!is_dir($resource)) {
         $resource = dirname($resource);
     }
     $configuration->addResource(new FileResource($resource));
     if (count(glob($dir . '/Resources/config/doctrine/metadata/*.xml'))) {
         return 'xml';
     } elseif (count(glob($dir . '/Resources/config/doctrine/metadata/*.yml'))) {
         return 'yml';
     }
     // add the directory itself as a resource
     $configuration->addResource(new FileResource($dir));
     if (is_dir($dir . '/Document')) {
         return 'annotation';
     }
 }
开发者ID:klaasn,项目名称:symfony-sandbox,代码行数:27,代码来源:MongoDBExtension.php


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