/** * Attempts to load a resource from a collection. * * If one of the resources exist, it will be loaded and `true` is returned. * Otherwise, `false` is returned. An `InvalidArgumentException` exception * will only be thrown if the resource fails to load because it is invalid. * * @param ResourceCollection $collection The collection to load. * * @return boolean Returns `true` if loaded, `false` if not. * * @throws InvalidArgumentException If the resource is invalid.. */ public function loadOptional($collection) { // @codeCoverageIgnoreStart if (!$collection instanceof ResourceCollection) { throw new InvalidArgumentException('The resource "%s" is not an instance of "ResourceCollection".', $this->toString($collection)); } // @codeCoverageIgnoreEnd foreach ($collection as $resource) { try { parent::load($resource); return true; } catch (InvalidArgumentException $exception) { if (false === strpos($exception->getMessage(), 'does not exist')) { throw $exception; // @codeCoverageIgnore } } } return false; }
/** * Verifies that we can load a resource. */ public function testLoad() { file_put_contents($this->dir . '/test.yml.dist', Yaml::dump(array('parameters' => array('test' => 'value')))); $this->loader->load(new ResourceSupport('test.yml.dist', 'test.yml')); self::assertEquals('value', $this->container->getParameter('test')); }