Symfony2 未加载服务
Symfony2 not loading Service
我正在尝试 create/load 按照文档书籍示例使用 Synfony 2 的服务,但我遇到了这个问题。目前我有
<?php
//src/AppBundle/Services/AmazonWS.php
namespace AppBundle\Services;
use Aws\S3\S3Client;
class AmazonWS
{
function __construct($bucket,$key,$secret){}
}
在我的 services.yml:
parameters:
# parameter_name: value
amazonws.S3_BUCKET : "synfony"
amazonws.S3_KEY : "my_key"
amazonws.S3_SECRET : "my_secret"
services:
# service_name:
# class: AppBundle\Directory\ClassName
# arguments: ["@another_service_name", "plain_value", "%parameter_name%"]
AmazonWS:
class: AppBundle\Services\AmazonWS
arguments: ["%amazonws.S3_BUCKET%","%amazonws.S3_KEY%","%amazonws.S3_SECRET%"]
我收到以下错误:
[Symfony\Component\Config\Exception\FileLoaderLoadException]
There is no extension able to load the configuration for "AmazonWS" (in /home/sergio/Desktop/hello_symfony_heroku/app/config/services.yml). Looked for namespace "AmazonWS", found "framewor
k", "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution" in /home/sergio/Desktop/hello_symfony_hero
ku/app/config/services.yml (which is being imported from "/home/sergio/Desktop/hello_symfony_heroku/app/config/config.yml").
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
There is no extension able to load the configuration for "AmazonWS" (in /home/sergio/Desktop/hello_symfony_heroku/app/config/services.yml). Looked for namespace "AmazonWS", found "framewor
k", "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution"
我得到了 config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
缩进:
services:
AmazonWS:
class: AppBundle\Services\AmazonWS
arguments: ["%amazonws.S3_BUCKET%","%amazonws.S3_KEY%","%amazonws.S3_SECRET%"]
您是否尝试过使用 AppBundle 中的依赖注入?
src/AppBundle/DependencyInjection/AppExtension.php
:
<?php
namespace AppBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
class AppExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config')
);
$loader->load('services.yml');
}
}
然后使用位于 src/AppBundle/Resources/config/services.yml
中的 services.yml(如果不存在则创建它)。
我正在尝试 create/load 按照文档书籍示例使用 Synfony 2 的服务,但我遇到了这个问题。目前我有
<?php
//src/AppBundle/Services/AmazonWS.php
namespace AppBundle\Services;
use Aws\S3\S3Client;
class AmazonWS
{
function __construct($bucket,$key,$secret){}
}
在我的 services.yml:
parameters:
# parameter_name: value
amazonws.S3_BUCKET : "synfony"
amazonws.S3_KEY : "my_key"
amazonws.S3_SECRET : "my_secret"
services:
# service_name:
# class: AppBundle\Directory\ClassName
# arguments: ["@another_service_name", "plain_value", "%parameter_name%"]
AmazonWS:
class: AppBundle\Services\AmazonWS
arguments: ["%amazonws.S3_BUCKET%","%amazonws.S3_KEY%","%amazonws.S3_SECRET%"]
我收到以下错误:
[Symfony\Component\Config\Exception\FileLoaderLoadException]
There is no extension able to load the configuration for "AmazonWS" (in /home/sergio/Desktop/hello_symfony_heroku/app/config/services.yml). Looked for namespace "AmazonWS", found "framewor
k", "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution" in /home/sergio/Desktop/hello_symfony_hero
ku/app/config/services.yml (which is being imported from "/home/sergio/Desktop/hello_symfony_heroku/app/config/config.yml").
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
There is no extension able to load the configuration for "AmazonWS" (in /home/sergio/Desktop/hello_symfony_heroku/app/config/services.yml). Looked for namespace "AmazonWS", found "framewor
k", "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution"
我得到了 config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
缩进:
services:
AmazonWS:
class: AppBundle\Services\AmazonWS
arguments: ["%amazonws.S3_BUCKET%","%amazonws.S3_KEY%","%amazonws.S3_SECRET%"]
您是否尝试过使用 AppBundle 中的依赖注入?
src/AppBundle/DependencyInjection/AppExtension.php
:
<?php
namespace AppBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
class AppExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config')
);
$loader->load('services.yml');
}
}
然后使用位于 src/AppBundle/Resources/config/services.yml
中的 services.yml(如果不存在则创建它)。