This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php

65 lines
1.6 KiB
PHP
Raw Normal View History

2010-01-04 14:26:20 +00:00
<?php
/*
* This file is part of the Symfony package.
2010-01-04 14:26:20 +00:00
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2010-01-04 14:26:20 +00:00
*/
namespace Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
2010-01-04 14:26:20 +00:00
/**
* FileLoader is the abstract class used by all built-in loaders that are file based.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2010-01-04 14:26:20 +00:00
*/
abstract class FileLoader extends Loader
{
protected $locator;
protected $currentDir;
2010-01-04 14:26:20 +00:00
/**
* Constructor.
*
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function __construct(ContainerBuilder $container, FileLocator $locator)
2010-01-04 14:26:20 +00:00
{
$this->locator = $locator;
parent::__construct($container);
}
2010-01-04 14:26:20 +00:00
public function getLocator()
{
return $this->locator;
}
/**
* Adds definitions and parameters from a resource.
*
* @param mixed $resource A Resource
*/
public function import($resource, $ignoreErrors = false)
{
try {
$loader = $this->resolve($resource);
if ($loader instanceof FileLoader && null !== $this->currentDir) {
$resource = $this->locator->getAbsolutePath($resource, $this->currentDir);
}
$loader->load($resource);
} catch (\Exception $e) {
if (!$ignoreErrors) {
throw $e;
}
}
}
2010-01-04 14:26:20 +00:00
}