Skip to content

Commit

Permalink
[DependencyInjection] Show better error when the Yaml component is no…
Browse files Browse the repository at this point in the history
…t installed
  • Loading branch information
dosten authored and fabpot committed Apr 15, 2015
1 parent 89f6e1e commit 870a299
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* YamlDumper dumps a service container as a YAML string.
Expand All @@ -31,20 +30,6 @@ class YamlDumper extends 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.
*
Expand All @@ -56,6 +41,14 @@ public function __construct(ContainerBuilder $container)
*/
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();
}

Expand Down
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Yaml\Parser as YamlParser;

Expand Down Expand Up @@ -269,6 +270,10 @@ private function parseDefinition($id, $service, $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)) {
throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
}
Expand Down

0 comments on commit 870a299

Please sign in to comment.