I am making a ProductBundle based on FOSUserbundle, but I'm having trouble with the autowiring of service arguments to the FormFactory and ProductManager classes.
I keep getting the error:
Cannot autowire service "App\Boa\ProductBundle\Form\Factory\FormFactory": argument "$name" of method "__construct()" must have a type-hint or be given a value explicitly.
FormFactory class:
namespace App\Boa\ProductBundle\Form\Factory;
use Symfony\Component\Form\FormFactoryInterface;
class FormFactory implements FactoryInterface
{
/**
* #var FormFactoryInterface
*/
private $formFactory;
/**
* #var string
*/
private $name;
/**
* #var string
*/
private $type;
/**
* #var array
*/
private $validationGroups;
/**
* FormFactory constructor.
*
* #param FormFactoryInterface $formFactory
* #param string $name
* #param string $type
* #param array $validationGroups
*/
public function __construct(FormFactoryInterface $formFactory, $name,
$type, array $validationGroups = null)
{
$this->formFactory = $formFactory;
$this->name = $name;
$this->type = $type;
$this->validationGroups = $validationGroups;
}
/**
* {#inheritdoc}
*/
public function createForm(array $options = array())
{
$options = array_merge(array('validation_groups' => $this->validationGroups), $options);
return $this->formFactory->createNamed($this->name, $this->type, null, $options);
}
}
create.xml ( located in App\Boa\ProductBundle\Resources\config )
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="boa_product.create.form.factory" class="App\Boa\ProductBundle\Form\Factory\FormFactory" public="true">
<argument type="service" id="form.factory" />
<argument key="$name">%boa_product.create.form.name%</argument>
<argument key="$type">%boa_product.create.form.type%</argument>
<argument>%boa_product.create.form.validation_groups%</argument>
</service>
<service id="boa_product.create.form.type" class="App\Boa\ProductBundle\Form\Type\CreateFormType">
<tag name="form.type" alias="boa_product_create" />
<argument key="$class">%boa_product.model.product.class%</argument>
</service>
<service id="boa_product.create.controller" class="App\Boa\ProductBundle\Controller\CreateController" public="true">
<argument type="service" id="boa_product.create.form.factory" />
<argument type="service" id="boa_product.product_manager" />
</service>
</services>
And the Extension:
<?php
namespace App\Boa\ProductBundle\DependencyInjection;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class BoaProductExtension extends Extension
{
/**
* #var array
*/
private static $doctrineDrivers = array(
'orm' => array(
'registry' => 'doctrine',
'tag' => 'doctrine.event_subscriber',
)
);
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
//$Yamlloader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
if ('custom' !== $config['db_driver']) {
if (isset(self::$doctrineDrivers[$config['db_driver']])) {
$loader->load('doctrine.xml');
$container->setAlias('boa_product.doctrine_registry', new Alias(self::$doctrineDrivers[$config['db_driver']]['registry'], false));
} else {
$loader->load(sprintf('%s.xml', $config['db_driver']));
}
$container->setParameter($this->getAlias().'.backend_type_'.$config['db_driver'], true);
}
if (isset(self::$doctrineDrivers[$config['db_driver']])) {
$definition = $container->getDefinition('boa_product.object_manager');
$definition->setFactory(array(new Reference('boa_product.doctrine_registry'), 'getManager'));
}
$container->setAlias('boa_product.product_manager', new Alias($config['service']['product_manager'], true));
$container->setAlias('App\Boa\ProductBundle\Model\ProductManagerInterface', new Alias('boa_product.product_manager', true));
$this->remapParametersNamespaces($config, $container, array(
'' => array(
'db_driver' => 'boa_product.storage',
'model_manager_name' => 'boa_product.model_manager_name',
'product_class' => 'boa_product.model.product.class',
),
));
$this->loadCreate($config['create'], $container, $loader);
}
/**
* #param array $config
* #param ContainerBuilder $container
* #param array $namespaces
*/
protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces)
{
foreach ($namespaces as $ns => $map) {
if ($ns) {
if (!array_key_exists($ns, $config)) {
continue;
}
$namespaceConfig = $config[$ns];
} else {
$namespaceConfig = $config;
}
if (is_array($map)) {
$this->remapParameters($namespaceConfig, $container, $map);
} else {
foreach ($namespaceConfig as $name => $value) {
$container->setParameter(sprintf($map, $name), $value);
}
}
}
}
/*
* #param array $config
* #param ContainerBuilder $container
* #param array $map
*/
protected function remapParameters(array $config, ContainerBuilder $container, array $map)
{
foreach ($map as $name => $paramName) {
if (array_key_exists($name, $config)) {
$container->setParameter($paramName, $config[$name]);
}
}
}
/**
* #param array $config
* #param ContainerBuilder $container
* #param XmlFileLoader $loader
*/
private function loadCreate(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
$loader->load('create.xml');
$this->remapParametersNamespaces($config, $container, array(
'form' => 'boa_product.create.form.%s',
));
}
}
So when reading the documentation of symfony it's normal to have this Exception message because scalar types can't be autowired, but I still have the message when having ( what I thought to be ) the correct xml file with services to manually wire them.
When I change one of the keys in the create.xml file, for example change the key "$name" to "$example" I get following message:
Invalid service "boa_product.create.form.factory": method "App\Boa\ProductBundle\Form\Factory\FormFactory::__construct()" has no argument named "$example". Check your service definition.
So I guess they must be connected in anyway? Then again, removing the complete service with all the arguments just gives me the same old exception
Cannot autowire service "App\Boa\ProductBundle\Form\Factory\FormFactory": argument "$name" of method "__construct()" must have a type-hint or be given a value explicitly.
so it seems that my xml isn't doing much at all.
I have spent the entire day yesterday trying stuff and looking up documentation, but no success. Thanks very much in advance for your help.
If you need more code, I'll be happy to provide it.
Thanks again!
Did you try doing what the error message says?
argument "$name" of method "__construct()" must have a type-hint or be
given a value explicitly
Neither $name nor $type have type-hint in your method signature. Try to change the method signature to:
public function __construct(FormFactoryInterface $formFactory, string $name, string $type, array $validationGroups = null)
Edit:
The other possibility is that you try to use %boa_product.create.form.name% param in the service definition before this parameter is defined.
if you work with interfaces you need to override that interface alias or add an explicit definition of your FormFactory.
check out:
Working with Interfaces
In the definition of boa_product.create.controller as a service, you are missing the key attribute for your arguments. Try:
<service id="boa_product.create.controller" class="App\Boa\ProductBundle\Controller\CreateController" public="true">
<argument key="$formFactory" type="service" id="boa_product.create.form.factory" />
<argument key="$productManager" type="service" id="boa_product.product_manager" />
</service>
where $formFactory and $productManager are the parameters in CreateController s constructor.
In your extension, you define an alias for App\Boa\ProductBundle\Model\ProductManagerInterface:
$container->setAlias('App\Boa\ProductBundle\Model\ProductManagerInterface', new Alias('boa_product.product_manager', true));
So I guess then, you can remove:
<argument key="$productManager" type="service" id="boa_product.product_manager" />
since this will be autowired.
Alternatively, you could autowire, a.k.a. define an alias for App\Boa\ProductBundle\Form\Factory\FactoryInterface also to boa_product.create.form.factory. how to aurowire services
Add this:
<service id="App\Boa\ProductBundle\Form\Factory\FormFactory" alias="boa_product.create.form.factory" />
My issue was eventually solved. I think it was due to me experimenting with the services files but not clearing the cache before testing the result. Because of that I thought that my services were not loaded ( because the result obviously didn't change ).
I ended up putting my Bundle in a separate repository and including it in the project via composer. I also rewrote the config files in YAML instead of XML because I think it's easier to read.
That way I had more control over the debugging it and eventually I got rid of the errors.
Most important thing when working with services is to run php bin/console cache:clear everytime you make a change.
Thanks for the help
Related
Does anyone knows to modify product data using Shopware\Storefront\Page\Product\ProductPageLoadedEvent ?
services.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="Swag\BasicExample\Service\AddDataToPage" >
<argument type="service" id="product.repository"/>
<tag name="kernel.event_subscriber" />
</service>
</services>
</container>
AddDataToPage.php
<?php declare(strict_types=1);
namespace Swag\BasicExample\Service;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
class AddDataToPage implements EventSubscriberInterface
{
/**
* #var EntityRepositoryInterface
*/
private $productRepository;
/**
* #param EntityRepositoryInterface $productRepository
*/
public function __construct(
EntityRepositoryInterface $productRepository
)
{
$this->productRepository = $productRepository;
}
/**
* #return string[]
*/
public static function getSubscribedEvents(): array
{
return [
ProductPageLoadedEvent::class => 'onProductsLoaded'
];
}
/**
* #param ProductPageLoadedEvent $event
* #return void
*/
public function onProductsLoaded(
ProductPageLoadedEvent $event
)
{
// the product is inside the page object
$productData = $event->getPage()->getProduct();
//modifying name
$this->log($productData->getName());
$productData->setName('Prefix Product Name' . $productData->getName());
$this->log($productData->getName());
//modifying ManufacturerNumber
$this->log($productData->getManufacturerNumber());
$productData->setManufacturerNumber('Prefix ManufacturerNumber' . $productData->getManufacturerNumber());
$this->log($productData->getManufacturerNumber());
$event->getPage()->setProduct($productData);
}
/**
* #param $message
* #return void
*/
private function log($message)
{
$logFileName = 'someFile.log';
file_put_contents(
$logFileName,
$message . PHP_EOL,
FILE_APPEND
);
}
}
After modifying the above mentioned changes it still shows the original data although
$event->getPage()->setProduct($productData);
I'm in doubt whether ProductPageLoadedEvent is an after dispatching event or before dispatching the event.
So, this is not the first time I am creating the service but I just can't resolve the error
You have requested a non-existent service "global_settings".
Steps I took to ensure service is properly setup:
My AppBundleExtension.php
namespace AppBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
class AppBundleExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('settings.xml');
}
}
My settings.xml
<?xml version="1.0" encoding="UTF-8" ?>
<container
xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="global_settings" class="AppBundle\Services\GlobalSettings">
<call method="setEntityManager">
<argument type="service" id="doctrine.orm.default_entity_manager" />
</call>
</service>
</services>
</container>
My GlobalSettings service
namespace AppBundle\Services;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
class GlobalSettings
{
/**
* #var EntityManager
*/
protected $em;
/**
* #var EntityRepository
*/
protected $repo;
public function setEntityManager(EntityManager $em) {
$this->em = $em;
$this->repo = null;
}
/**
* #return array with name => value
*/
public function all() {
return $this->$this->getRepo()->findAll();
}
/**
* #param string $name Name of the setting.
* #return string|null Value of the setting.
* #throws \RuntimeException If the setting is not defined.
*/
public function get($name) {
$setting = $this->$this->getRepo()->findOneBy(array(
'name' => $name,
));
if ($setting === null) {
throw $this->createNotFoundException($name);
}
return $setting->getValue();
}
/**
* #param string $name Name of the setting to update.
* #param string|null $value New value for the setting.
* #throws \RuntimeException If the setting is not defined.
*/
public function set($name, $value) {
$setting = $this->$this->getRepo()->findOneBy(array(
'name' => $name,
));
if ($setting === null) {
throw $this->createNotFoundException($name);
}
$setting->setValue($value);
$this->em->flush($setting);
}
/**
* #return EntityRepository
*/
protected function getRepo() {
if ($this->repo === null) {
$this->repo = $this->em->getRepository('AppBundle:Settings');
}
return $this->repo;
}
/**
* #param string $name Name of the setting.
* #return \RuntimeException
*/
protected function createNotFoundException($name) {
return new \RuntimeException(sprintf('Setting "%s" couldn\'t be found.', $name));
}
}
Then inside my controller I trying to access the service using the following code
$data = $this->get('global_settings')->get('paypal_email');
What am I doing wrong? Any help will be really appreciate as I am out of idea.
The reason why I kept getting this error was that my default setting for services was public: false
So to fix that I needed to set the public property to true for my service
services:
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
my_service:
class: AppBundle\Service\MyService
public: true
You wrote:
Steps I took to ensure service is properly setup
My AppBundleExtension.php
And:
I know AppBundleExtension is not loading, what do I need to do to load it? What am I missing?
So it was clear that the AppBundleExtension class was not loaded.
According to the official documentation you should remove the Bundle in the file name and class name:
The name is equal to the bundle name with the Bundle suffix replaced by Extension (e.g. the Extension class of the AppBundle would be called AppExtension and the one for AcmeHelloBundle would be called AcmeHelloExtension).
You can update your config.yml file:
imports:
- { resource: "#AppBundle/Resources/config/services.yml" }
guys I'm trying ti include in one Form type for some reason the manager did not include in the constructor maybe it is a simple typo but for now i cannot see a error through the examples of the coookbook of symfony2 (2.7).
Here is the FormType FloorType
namespace George\FloorBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use George\FloorBundle\Form\DataTransformer\ObjectToNumberTransformer;
use Doctrine\Common\Persistence\ObjectManager;
class FloorType extends AbstractType
{
private $manager;
public function __construct(ObjectManager $manager)
{
$this->manager = $manager;
}
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('translations', 'a2lix_translations',array(
'required_locales' => array('bg','en')
))
->add('object', 'hidden', array(
// validation message if the data transformer fails
'invalid_message' => 'That is not a valid issue number',
));
$builder ->get('object')->addModelTransformer(new ObjectToNumberTransformer($this->manager));
}
/**
* #param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'George\FloorBundle\Entity\Floor'
));
}
/**
* #return string
*/
public function getName()
{
return 'george_floorbundle_floor';
}
}
The service which need to inject the manager
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="app.form.type.floor" class="George\FloorBundle\Form\Type\FloorType">
<tag name="form.type" />
<argument type="service" id="doctrine.orm.entity_manager"></argument>
</service>
</services>
The transformer which use the manager (but i got not errors in it i just want to make a full example of the case)
<?php
namespace George\FloorBundle\Form\DataTransformer;
use George\ObjectsBundle\Entity\Object;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
class ObjectToNumberTransformer implements DataTransformerInterface
{
private $manager;
public function __construct(ObjectManager $manager)
{
$this->manager = $manager;
}
/**
* Transforms an object (issue) to a string (number).
*
* #param Object|null $issue
* #return string
*/
public function transform($object)
{
if (null === $object) {
return '';
}
return $object->getId();
}
/**
* Transforms a string (number) to an object (issue).
*
* #return Object|null
* #throws TransformationFailedException if object (issue) is not found.
*/
public function reverseTransform($objectNumber)
{
// no issue number? It's optional, so that's ok
if (!$objectNumber) {
return;
}
$object= $this->manager
->getRepository('ObjectsBundle:Object')
// query for the issue with this id
->find($objectNumber)
;
if (null === $object) {
// causes a validation error
// this message is not shown to the user
// see the invalid_message option
throw new TransformationFailedException(sprintf(
'An issue with number "%s" does not exist!',
$objectNumber
));
}
return $object;
}
}
And the controller method in which i need to load the FloorType:
private function createEditForm(Floor $entity)
{
$manager = $this->getDoctrine()->getManager();
$form = $this->createForm(new FloorType($manager), $entity, array(
'action' => $this->generateUrl('admin_floor_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
So when i remove the manager:
$manager = $this->getDoctrine()->getManager();
I got a big fat error:
Catchable Fatal Error: Argument 1 passed to George\FloorBundle\Form\FloorType::__construct() must implement interface Doctrine\Common\Persistence\ObjectManager, none given, called in D:\work\infinity3\src\George\FloorBundle\Controller\FloorController.php on line 171 and defined
I understand it like this - the service did not manage to inject the manager
Debug the service in local bundle
I have debug the service and it is listed but i cannot manage it to include the manager in the FloorType what i have been missed here?
Edit
So it was the service xml problem i did not include the alias attribute thanks to #Matteo answer i edit the code and it works like a charm!
Thank you #Matteo!
Here is the edit service
<services>
<service id="app.form.type.floor" class="George\FloorBundle\Form\FloorType">
<tag name="form.type" alias="george_floorbundle_floor" />
<argument type="service" id="doctrine.orm.entity_manager"></argument>
</service>
</services>
And where i create the form:
$form = $this->createForm('george_floorbundle_floor', $entity, array(
'action' => $this->generateUrl('admin_floor_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
You should define an alias in the tags section as follow:
service.xml
<services>
<service id="app.form.type.floor" class="George\FloorBundle\Form\Type\FloorType">
<tag name="form.type" alias="george_floorbundle_floor" />
<argument type="service" id="doctrine.orm.entity_manager"></argument>
</service>
</services>
And refer in the form creation with the reference, as follow:
$form = $this->createForm('george_floorbundle_floor', $entity, array(
'action' => $this->generateUrl('admin_floor_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
Hope this help
I have an Entity named "Document" and I use sonata media to handle the file management. So, an Admin can add a new document and attach a file, this document is assigned to an user.
My problem is :
I want the users to be able to download the files that are assigned to them through the "Protected URL"(because if you change the number at the end of the download url, you are able to download files that are assigned to other users)
According to the Sonata Media's doc, I need to create a Download Strategy and the service. I did it, i called it : PrivateDownloadStrategy.php (and made the service)
This file should be based on RolesDownloadStrategy.php, because i want the admins able to download all the files, but how to do for the users be able to download the files that are assigned to them ?
This is my actual PrivateDownloadStrategy.php (copy from rolesDownloadStrategy.php)
<?php
namespace Application\Core\DocumentBundle\Security;
use Sonata\MediaBundle\Security\DownloadStrategyInterface;
use Sonata\MediaBundle\Model\MediaInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PrivateDownloadStrategy implements DownloadStrategyInterface
{
protected $roles;
protected $security;
protected $translator;
/**
* #param \Symfony\Component\Translation\TranslatorInterface $translator
* #param \Symfony\Component\Security\Core\SecurityContextInterface $security
* #param array $roles
*/
public function __construct(TranslatorInterface $translator, SecurityContextInterface $security, array $roles = array())
{
$this->roles = $roles;
$this->security = $security;
$this->translator = $translator;
}
/**
* #param \Sonata\MediaBundle\Model\MediaInterface $media
* #param \Symfony\Component\HttpFoundation\Request $request
*
* #return bool
*/
public function isGranted(MediaInterface $media, Request $request)
{
return $this->security->getToken() && $this->security->isGranted($this->roles);
}
/**
* #return string
*/
public function getDescription()
{
return $this->translator->trans('description.roles_download_strategy', array('%roles%' => '<code>'.implode('</code>, <code>', $this->roles).'</code>'), 'SonataMediaBundle');
}
}
and the service :
<service id="sonata.media.security.private_strategy" class="Application\Core\DocumentBundle\Security\PrivateDownloadStrategy" >
<argument type="service" id="translator" />
<argument type="service" id="security.context" />
<argument type="collection">
<argument>ROLE_SUPER_ADMIN</argument>
<argument>ROLE_ADMIN</argument>
</argument>
</service>
nb : sonata media doc : link
sonata rolesDownloadStrategy : link
I'm using JMSDiExtraBundle in my Symfony2 project.
Here is my the problem:
Repository.php
abstract class Repository extends DocumentRepository implements ReadOnlyRepositoryInterface {
protected $dm;
protected $repo;
protected $query;
/**
* #InjectParams({
* "dm" = #Inject("doctrine.odm.mongodb.document_manager")
* })
*/
public function __construct(DocumentManager $dm) {
$this->dm = $dm;
parent::__construct($dm, $this->dm->getUnitOfWork(), new ClassMetadata($this->getDocumentName()));
$this->query = $this->dm->createQueryBuilder($this->getDocumentName());
}
}
PostRepository.php
/**
* #Service("post_repository")
*/
class PostRepository extends Repository implements PostRepositoryInterface {
private $uploader;
/**
* #InjectParams({
* "dm" = #Inject("doctrine.odm.mongodb.document_manager"),
* "uploader" = #Inject("uploader"),
* })
*/
public function __construct(DocumentManager $dm, UploaderService $uploader) {
parent::__construct($dm);
$this->uploader = $uploader;
}
}
As can be seen, PostRepository requires 2 dependency : DocumentManager (later injected to Repository as parent) and Uploader.
But it seems that Symfony does something which making it assumed that PostRepository needed 3 dependency : DocumentManager, DocumentManager (again) and Uploader, which off course gives an error since I explicitly stated that the second parameter is required to be an Uploader instance.
Here's from appDevDebugProjectContainer.xml :
<service id="post_repository" class="BusinessLounge\BlogBundle\Repository\PostRepository">
<argument type="service" id="doctrine_mongodb.odm.default_document_manager"/>
<argument type="service" id="doctrine_mongodb.odm.default_document_manager"/>
<argument type="service" id="uploader"/>
</service>
and appDevDebugProjectContainer.php :
/**
* Gets the 'post_repository' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* #return BusinessLounge\BlogBundle\Repository\PostRepository A BusinessLounge\BlogBundle\Repository\PostRepository instance.
*/
protected function getPostRepositoryService()
{
$a = $this->get('doctrine_mongodb.odm.default_document_manager');
return $this->services['post_repository'] = new \BusinessLounge\BlogBundle\Repository\PostRepository($a, $a, $this->get('uploader'));
}
Is this an intended behavior? Or a bug perhaps? Or I did something wrong?
Need advice!
You can just remove the #InjectParams on your abstract parent class, since it is never instantiated anyways. Then only the things you need are injected in your real service.