Symfony3您已经请求了一个不存在的服务“validator.builder”,同时添加了FOSUserBundle

时间:2016-11-25 15:28:45

标签: symfony service microkernel

我有Symfony微内核,我正在尝试添加FOSUserBundle。 完成本指南安装https://symfony.com/doc/master/bundles/FOSUserBundle/index.html后,我收到了'validor.builder'错误

Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "validator.builder". in /var/www/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php on line 754
  

调用堆栈

     

/app_dev.php:0 Symfony \ Component \ HttpKernel \ Kernel-> handle(   )... / app_dev.php:9 Symfony \ Component \ HttpKernel \ Kernel-> boot(   )... / Kernel.php:166   的Symfony \组件\ HttpKernel \内核级> initializeContainer(   )... / Kernel.php:117   的Symfony \组件\ DependencyInjection \ ContainerBuilder->编译(   )... / Kernel.php:477   的Symfony \组件\ DependencyInjection \编译\反编译>编译(   )... / ContainerBuilder.php:528   FOS \ UserBundle \ DependencyInjection \编译\ ValidationPass->处理(   )... / Compiler.php:104   的Symfony \组件\ DependencyInjection \ ContainerBuilder-> getDefinition方法(   )... / ValidationPass.php:41

它认为symfony找不到服务验证器.builder,它与symfony FrameworkBundle一起使用。 有人有建议问题在哪里,缺少什么? 谢谢!

Composer.json:

{
    "require": {
        "symfony/symfony": "^3.1",
        "symfony/security": "^3.1",
        "symfony/monolog-bundle": "^3.0",
        "twig/twig": "^1.28",
        "alcaeus/mongo-php-adapter": "^1.0",
        "ext-mongo": "*",
        "mongodb/mongodb": "^1.0",
        "doctrine/mongodb-odm": "^1.1",
        "doctrine/mongodb-odm-bundle": "^3.2",
        "friendsofsymfony/user-bundle": "~2.0@dev",
        "symfony/validator": "^3.1"
    },
    "autoload": {
        "psr-4": {
            "": "src/"
        }
    } }

App_dev.php

<?php

use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

AppKernel.php

<?php

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

// require Composer's autoloader
$loader = require __DIR__.'/../vendor/autoload.php';

class AppKernel extends Kernel
{
    use MicroKernelTrait;

    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new DebatesBundle\DebatesBundle(),
            new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new Exten\FOSUserBundle\ExtenFOSUserBundle()
        );

        if ($this->getEnvironment() == 'dev') {
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new \Symfony\Bundle\DebugBundle\DebugBundle();
        }

        return $bundles;
    }

    protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
    {
        $loader->load(__DIR__ . '/config/config.yml');
        $loader->load(__DIR__.'/config/parameters.'.$this->getEnvironment().'.yml');

        // configure WebProfilerBundle only if the bundle is enabled
        if (isset($this->bundles['WebProfilerBundle'])) {
            $c->loadFromExtension('web_profiler', array(
                'toolbar' => true,
                'intercept_redirects' => false,
            ));
        }

        $loader->load(__DIR__.'/config/services.yml');
    }

    protected function configureRoutes(RouteCollectionBuilder $routes)
    {

        $routes->import(__DIR__ . '/../src/DebatesBundle/Routes/routes.yml', '/', 'yaml');
        $routes->import('@FOSUserBundle/Resources/config/routing/all.xml', '/');

        // import the WebProfilerRoutes, only if the bundle is enabled
        if (isset($this->bundles['WebProfilerBundle'])) {
            $routes->import('@WebProfilerBundle/Resources/config/routing/wdt.xml', '/_wdt');
            $routes->import('@WebProfilerBundle/Resources/config/routing/profiler.xml', '/_profiler');
        }
    }

    // optional, to use the standard Symfony cache directory
    public function getCacheDir()
    {
        return __DIR__ . '/cache/' .$this->getEnvironment();
    }

    // optional, to use the standard Symfony logs directory
    public function getLogDir()
    {
        return __DIR__ . '/logs';
    }
}

2 个答案:

答案 0 :(得分:3)

修复您报告的错误很容易。只需添加:

services:
  validator.builder:
    class: Symfony\Component\Config\Definition\Builder\ValidationBuilder

到您的services.yml

...但是,这并没有为我解决所有问题,并导致更多来自FOS用户捆绑包的遗失认证服务的问题。我花了一些时间尝试添加这些服务定义,但我认为内心有问题。 FOSUserBundle还没有支持Symfony 3的标记版本。你可以尝试在作曲家中使用dev-master来查看它是如何工作的,但它并没有为我修复它。

我的建议是首先尝试使用默认的Symfony3应用程序(不使用微内核),如果仍然无法确定您想要更多,Symfony3或FOSUserBundle。

答案 1 :(得分:0)

我解决了我的问题 services.yml:

Symfony\Component\Config\Definition\Builder\ValidationBuilder:
    autowire: true

根据documentation

你的病例怎么样?