Reputation: 1120
Following the advice posted at Loading custom config file for app in symfony2 I stucked into namespace issue.
In \src\AppBundle\DependencyInjection
I have two files:
AppExtension.php:
<?php
namespace AppBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
use AppBundle\DependencyInjection\Configuration;
/**
* This is the class that loads and manages your bundle configuration
*/
class AppExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('kh', $config['kh']);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('general.yml'); # another file of yours
}
}
and Configuration.php:
<?
namespace AppBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('kh');
$rootNode
->children()
->arrayNode('tags')
->prototype('array')
->children()
->scalarNode('name')->isRequired()->end();
->scalarNode('role')->isRequired()->end();
->scalarNode('priority')->isRequired()->end();
->scalarNode('label')->isRequired()->end();
->end();
->end();
->end();
return $treeBuilder;
}
}
It seems that I make some kind of mistake naming the files as executing:
php app/console cache:clear --env=prod
results in:
PHP Fatal error: Class 'AppBundle\DependencyInjection\Configuration' not found in /var/www/dev.investmentopportunities.pl/src/AppBundle/DependencyInjection/AppExtension.php on line 22 [2015-08-02 10:39:36] php.EMERGENCY: Fatal Error: Class 'AppBundle\DependencyInjection\Configuration' not found {"type":1,"file":"/var/www/dev.investmentopportunities.pl/src/AppBundle/DependencyInjection/AppExtension.php","line":22,"level":6143,"stack":[]}
Unluckily I have a problem with finding the error on my own. I have tried to rename files but still the error occurs. Could you please advice what am I doing wrong?
UPDATE 1:
As sugested by @San Thapa I have tried also to remove "use" command. This results in:
PHP Fatal error: Class 'AppBundle\DependencyInjection\Configuration' not found in /var/www/dev.investmentopportunities.pl/src/AppBundle/DependencyInjection/AppExtension.php on line 21 [2015-08-02 12:05:27] php.EMERGENCY: Fatal Error: Class 'AppBundle\DependencyInjection\Configuration' not found {"type":1,"file":"/var/www/dev.investmentopportunities.pl/src/AppBundle/DependencyInjection/AppExtension.php","line":21,"level":6143,"stack":[]}
[Symfony\Component\Debug\Exception\ClassNotFoundException] Attempted to load class "Configuration" from namespace "AppBundle\Dependenc yInjection". Did you forget a "use" statement for e.g. "Symfony\Bundle\TwigBundle\Depend encyInjection\Configuration", "Symfony\Bundle\DebugBundle\DependencyInjecti on\Configuration", "Symfony\Bundle\WebProfilerBundle\DependencyInjection\Co nfiguration", "Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestB undle\DependencyInjection\Configuration", "Symfony\Bundle\FrameworkBundle\D ependencyInjection\Configuration", "Genemu\Bundle\FormBundle\DependencyInje ction\Configuration", "Doctrine\ORM\Configuration", "Doctrine\DBAL\Configur ation", "Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\Configurat ion", "Symfony\Bundle\SwiftmailerBundle\DependencyInjection\Configuration", "Symfony\Bundle\MonologBundle\DependencyInjection\Configuration", "Symfony \Bundle\AsseticBundle\DependencyInjection\Configuration", "Sensio\Bundle\Fr ameworkExtraBundle\DependencyInjection\Configuration", "PUGX\AutocompleterB undle\DependencyInjection\Configuration", "Knp\Bundle\PaginatorBundle\Depen dencyInjection\Configuration", "FOS\UserBundle\DependencyInjection\Configur ation" or "Doctrine\Bundle\DoctrineBundle\DependencyInjection\Configuration "?
What seems a bit strange acessing the webpage from browser does not result in any error.
Upvotes: 0
Views: 2472
Reputation: 1852
Just added to first line of Configuration.php:
<?php
and also remove semicolons:
$rootNode
->children()
->arrayNode('tags')
->prototype('array')
->children()
->scalarNode('name')->isRequired()->end()
->scalarNode('role')->isRequired()->end()
->scalarNode('priority')->isRequired()->end()
->scalarNode('label')->isRequired()->end()
->end()
->end()
->end();
I'm not sure about structure... Maybe you forgot add one more end()...
Upvotes: 1