[DependencyInjection] Show better error when the Yaml component is not installed
This commit is contained in:
parent
89f6e1e115
commit
870a299eb3
@ -18,7 +18,6 @@ use Symfony\Component\DependencyInjection\Definition;
|
|||||||
use Symfony\Component\DependencyInjection\Parameter;
|
use Symfony\Component\DependencyInjection\Parameter;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YamlDumper dumps a service container as a YAML string.
|
* YamlDumper dumps a service container as a YAML string.
|
||||||
@ -31,20 +30,6 @@ class YamlDumper extends Dumper
|
|||||||
{
|
{
|
||||||
private $dumper;
|
private $dumper;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param ContainerBuilder $container The service container to dump
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
public function __construct(ContainerBuilder $container)
|
|
||||||
{
|
|
||||||
parent::__construct($container);
|
|
||||||
|
|
||||||
$this->dumper = new YmlDumper();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dumps the service container as an YAML string.
|
* Dumps the service container as an YAML string.
|
||||||
*
|
*
|
||||||
@ -56,6 +41,14 @@ class YamlDumper extends Dumper
|
|||||||
*/
|
*/
|
||||||
public function dump(array $options = array())
|
public function dump(array $options = array())
|
||||||
{
|
{
|
||||||
|
if (!class_exists('Symfony\Component\Yaml\Dumper')) {
|
||||||
|
throw new RuntimeException('Unable to dump the container as the Symfony Yaml Component is not installed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $this->dumper) {
|
||||||
|
$this->dumper = new YmlDumper();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->addParameters()."\n".$this->addServices();
|
return $this->addParameters()."\n".$this->addServices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
use Symfony\Component\Config\Resource\FileResource;
|
use Symfony\Component\Config\Resource\FileResource;
|
||||||
use Symfony\Component\Yaml\Parser as YamlParser;
|
use Symfony\Component\Yaml\Parser as YamlParser;
|
||||||
|
|
||||||
@ -269,6 +270,10 @@ class YamlFileLoader extends FileLoader
|
|||||||
*/
|
*/
|
||||||
protected function loadFile($file)
|
protected function loadFile($file)
|
||||||
{
|
{
|
||||||
|
if (!class_exists('Symfony\Component\Yaml\Parser')) {
|
||||||
|
throw new RuntimeException('Unable to load YAML config files as the Symfony Yaml Component is not installed.');
|
||||||
|
}
|
||||||
|
|
||||||
if (!stream_is_local($file)) {
|
if (!stream_is_local($file)) {
|
||||||
throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
|
throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user