Symfony3 您请求了一个不存在的服务“validator.builder",同时添加了 FOSUserBundle [英] Symfony3 You have requested a non-existent service "validator.builder", while add FOSUserBundle
问题描述
我有 Symfony 微内核,我正在尝试添加 FOSUserBundle.通过本指南安装后 https://symfony.com/doc/master/bundles/FOSUserBundle/index.html 'validor.builder' 出现错误
致命错误:未捕获的 Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:您请求了一个不存在的服务validator.builder".在第 754 行的/var/www/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
<块引用>
调用栈
/app_dev.php:0 Symfony\Component\HttpKernel\Kernel->handle() .../app_dev.php:9 Symfony\Component\HttpKernel\Kernel->boot() .../Kernel.php:166Symfony\Component\HttpKernel\Kernel->initializeContainer() .../Kernel.php:117Symfony\Component\DependencyInjection\ContainerBuilder->compile() .../Kernel.php:477Symfony\Component\DependencyInjection\Compiler\Compiler->compile() .../ContainerBuilder.php:528FOS\UserBundle\DependencyInjection\Compiler\ValidationPass->process() .../Compiler.php:104Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() .../ValidationPass.php:41
看来symfony 找不到服务validator.builder,它与symfony FrameworkBundle 一起使用.有没有人有建议问题出在哪里以及缺少什么?谢谢!
Composer.json:
<代码>{要求": {"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/验证器":^3.1"},自动加载":{psr-4":{"": "源代码/"}} }
App_dev.php
handle($request);$response->send();$kernel->terminate($request, $response);
AppKernel.php
getEnvironment() == 'dev') {$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();$bundles[] = new \Symfony\Bundle\DebugBundle\DebugBundle();}返回 $bundles;}受保护的函数 configureContainer(ContainerBuilder $c, LoaderInterface $loader){$loader->load(__DIR__ .'/config/config.yml');$loader->load(__DIR__.'/config/parameters.'.$this->getEnvironment().'.yml');//仅当启用了 bundle 时才配置 WebProfilerBundle如果 (isset($this->bundles['WebProfilerBundle'])) {$c->loadFromExtension('web_profiler', array('工具栏' =>真的,'intercept_redirects' =>错误的,));}$loader->load(__DIR__.'/config/services.yml');}受保护的功能 configureRoutes(RouteCollectionBuilder $routes){$routes->import(__DIR__ .'/../src/DebatesBundle/Routes/routes.yml', '/', 'yaml');$routes->import('@FOSUserBundle/Resources/config/routing/all.xml', '/');//导入 WebProfilerRoutes,仅当启用了 bundle 时如果 (isset($this->bundles['WebProfilerBundle'])) {$routes->import('@WebProfilerBundle/Resources/config/routing/wdt.xml', '/_wdt');$routes->import('@WebProfilerBundle/Resources/config/routing/profiler.xml', '/_profiler');}}//可选,使用标准 Symfony 缓存目录公共函数 getCacheDir(){返回 __DIR__ .'/cache/' .$this->getEnvironment();}//可选,使用标准 Symfony 日志目录公共函数 getLogDir(){返回 __DIR__ .'/日志';}}
修复您报告的错误很容易.只需添加:
服务:验证器.builder:类:Symfony\Component\Config\Definition\Builder\ValidationBuilder
到您的 services.yml
...然而,这并不能为我解决所有问题,并且会导致更多问题,因为缺少所有来自 FOS 用户包的身份验证服务.我花了一段时间试图添加这些服务定义,但我认为内心深处有些问题.FOSUserBundle 还没有支持 Symfony 3 的标记版本.你可以尝试在 Composer 中使用 dev-master
来查看它是如何工作的,但它没有为我修复它.
我的建议是首先尝试使用默认的 Symfony3 应用程序(不使用微内核),如果仍然失败,请决定您想要更多的 Symfony3 或 FOSUserBundle.
I have Symfony microkernel and I am trying to add FOSUserBundle. After going through this guide to install it https://symfony.com/doc/master/bundles/FOSUserBundle/index.html I got error with '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
Call Stack
/app_dev.php:0 Symfony\Component\HttpKernel\Kernel->handle( ) .../app_dev.php:9 Symfony\Component\HttpKernel\Kernel->boot( ) .../Kernel.php:166 Symfony\Component\HttpKernel\Kernel->initializeContainer( ) .../Kernel.php:117 Symfony\Component\DependencyInjection\ContainerBuilder->compile( ) .../Kernel.php:477 Symfony\Component\DependencyInjection\Compiler\Compiler->compile( ) .../ContainerBuilder.php:528 FOS\UserBundle\DependencyInjection\Compiler\ValidationPass->process( ) .../Compiler.php:104 Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition( ) .../ValidationPass.php:41
It seams that symfony can not find service validator.builder, which goes with symfony FrameworkBundle. Does anyone has suggestions where is the problem and what is missing? Thanks!
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';
}
}
Fixing the error you reported is easy. Just add:
services:
validator.builder:
class: Symfony\Component\Config\Definition\Builder\ValidationBuilder
To your services.yml
...However this doesn't fix everything for me and leads to more problems with missing authentication services all coming from the FOS User bundle. I spent a while trying to add these service definitions but I think something is wrong deep down. The FOSUserBundle doesn't have a tagged release that supports Symfony 3 yet. You could try using dev-master
for it in composer and see how that works, but it didn't fix it for me.
My recommendation is to first try it with a default Symfony3 app (not using the micro kernel) and if that still fails decide which you want more, Symfony3 or FOSUserBundle.
这篇关于Symfony3 您请求了一个不存在的服务“validator.builder",同时添加了 FOSUserBundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!