symfony2 bundle extension is not loaded after renaming the bundle - symfony

I have created a new bundle called PostalAddressBundle and i created a service inside it called ss_postal_address. Everything was working fine. But i decided to rename the bundle to AddressBundle instead of PostalAddressBundle, i renamed all namespace and all things related to it. Everything is working but not the service (ss_postal_address).
I cleared the cache, but nothing happens..
this is the content of services.xml file:
<parameters>
<parameter key="ss_address.entity.address.class">Skonsoft\AddressBundle\Entity\Address</parameter>
<parameter key="ss_address.form.type.address.class">Skonsoft\AddressBundle\Form\Type\AddressType</parameter>
</parameters>
<services>
<service id="ss_address.form.type.address" class="%ss_address.form.type.address.class%">
<argument>%ss_address.entity.address.class%</argument>
<tag name="form.type" alias="ss_postal_address" />
</service>
</services>
Have you any idea how to fix this ?
Thank you

I solved this problem but just removing the cache by hand:
rm -Rf ./app/cache/*
symfony cache:clear does not do the work in this case.

Have you renamed your DI extension accordingly? For example a bundle named SkonsoftAddressBundle should have an extension named SkonsoftAddressExtension within the Skonsoft\AddressBundle\DependencyInjection namespace.

Related

Explain These Services.xml File Terms In Shopware 6

What does argument and argument type mean,
What does tag and tag name mean,
in Shopware 6 plugin services.xml file?
<?xml version="1.0" ?>
<services>
<service id="Winner\Service\ExampleService" />
<service id="Winner\Service\ExampleServiceDecorator" decorates="Winner\Service\ExampleService">
<tag name="kernel.event_listener" event="product.loaded" />
<argument type="service" id="Winner\Service\ExampleServiceDecorator.inner" />
</service>
</services>
The services.xml file is the configuration file for the symfony dependency injection container.
By default, Symfony allows autowiring of the config, but the Shopware default is to configure the DI container manually. Please refer to the Symfony docs for more information on manually configuring the DI.
And the Symfony docs also have more information on service tags.
So technically this is not a Shopware specific question, but rather a Symfony question. I hope my answer and the provided docs help you.

Extends a KnpMenu from a Symfony Bundle

I am using Sylius as a shop Symfony bundle, and I would like to extend the KnpMenu used in "/admin" path of this bundle.
In Sylius, the menu is made from a service :
<service id="sylius.menu_builder.admin.main" class="Sylius\Bundle\AdminBundle\Menu\MainMenuBuilder"
parent="sylius.menu_builder" public="false">
</service>
<service id="sylius.menu.admin.main" class="Knp\Menu\MenuItem">
<factory service="sylius.menu_builder.admin.main" method="createMenu" />
<tag name="knp_menu.menu" alias="sylius.admin.main" />
</service>
Is there a way to add an entry in this menu from my own Bundle ?
Thanks for your help !
Yes, you have to create MenuListener, add child elements in there, and register it as a service. You have it explained in the documentation: http://docs.sylius.org/en/latest/customization/menu.html
Good luck!

How to deactivate some symfony2 debug toolbar elements?

I am using symfony2 and its debug toolbar is great.
However, I've come to install som extra bundles which add some elements and it is now displayed on two levels.
How can I do to remove some elements from the toolbar ?
For example, I don't need info about my phpversion, not about the route, etc.
Elements of the toolbar are called DataCollectors, they are special services tagged with data_collector. In the following lines, i will take the Time Datacollector as example.
So in order to deactivate one of them, you first have to get his service id.
You can list all the DataCollectors by running the console command:
php console container:debug --show-private --tag='data_collector'
The output is:
[container] Public and private services with tag data_collector
Service ID template id priority Class name
9d48641ce55174a7d8ab08e99157426bc290884423a78a5821440d644f6a37df_5 #WebProfiler/Collector/time.html.twig time 300 Symfony\Component\HttpKernel\DataCollector\TimeDataCollector
So now you got the id of the service which is time, you have to build the name. Add data_collector. as a prefix of the id to get the name. The name of the service is data_collector.time.
Now as you want to deactivate it, you have to give it a Zero priority.
In your config.yml:
services:
data_collector.time:
class: "%data_collector.time.class%"
tags:
- {name: 'data_collector', priority: '0'}
Now the profiler doesn't have the time no more.
This is a way to unable some profiler items properly. ( A.K.A: A symfony update won't affect it, unless they change the name of the DataCollectors )
The shortiest way is to direcly put the zero priority in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.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">
<parameters>
<parameter key="data_collector.config.class">Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector</parameter>
<parameter key="data_collector.request.class">Symfony\Component\HttpKernel\DataCollector\RequestDataCollector</parameter>
<parameter key="data_collector.exception.class">Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector</parameter>
<parameter key="data_collector.events.class">Symfony\Component\HttpKernel\DataCollector\EventDataCollector</parameter>
<parameter key="data_collector.logger.class">Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector</parameter>
<parameter key="data_collector.time.class">Symfony\Component\HttpKernel\DataCollector\TimeDataCollector</parameter>
<parameter key="data_collector.memory.class">Symfony\Component\HttpKernel\DataCollector\MemoryDataCollector</parameter>
<parameter key="data_collector.router.class">Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector</parameter>
</parameters>
<services>
[...]
<service id="data_collector.time" class="%data_collector.time.class%" public="false">
<tag name="data_collector" template="#WebProfiler/Collector/time.html.twig" id="time" priority="0" />
<argument type="service" id="kernel" on-invalid="ignore" />
<argument type="service" id="debug.stopwatch" on-invalid="ignore" />
</service>
[..]
</services>
</container>
All the DataCollectors are not defined in the same file. But here is a quick list of some of them:
data_collector.config:
data_collector.request:
data_collector.router:
data_collector.security:
data_collector.logger:
data_collector.memory:
data_collector.exception:
data_collector.events:
swiftmailer.data_collector:
I had issue with php-cache. It had CacheDataCollector which could crash symfony2 in some cases - https://github.com/php-cache/issues/issues/112
I tried solution above (with priority 0) - and it doesnt worked, data-collector still crashed symfony2
I dont have any ideas why priority = 0 should disable anything.
You could check symfony2 ProfilerPass yourself, which process tag data_collector in
https://github.com/avorobiev/symfony2/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ProfilerPass.php
So, I have used pretty dirty patch intead - in application config I add service with the same name, but without tag data_collector.
Like
services:
cache.data_collector:
class: Cache\CacheBundle\DataCollector\CacheDataCollector
More clean and more stable way would be adding CompilerPass, which will remove tag - https://blog.liplex.de/disable-elements-in-the-symfony-developer-toolbar-with-compilerpass/

Cannot load doctrine:config , services.xml

I am trying to build an eventlistener for my project and followed the instruction of this guide: How to register eventlisteners I edited my services.xml like in the tutorial , but i get this error message, when i want to test it:
InvalidArgumentException: There is no extension able to load the configuration for "doctrine:config" (in /var/www/symfony/src/Acme/AppBundle/DependencyInjection/../Resources/config/services.xml). Looked for namespace "http://symfony.com/schema/dic/doctrine", found none
My services.xml :
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
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">
<doctrine:config>
<doctrine:dbal default-connection="default">
<doctrine:connection driver="pdo_sqlite" memory="true" />
</doctrine:dbal>
</doctrine:config>
<services>
<service id="my.listener" class="Acme\AppBundle\EventListener\Confirmer">
<tag name="doctrine.event_listener" event="preUpdate" />
</service>
</services>
</container>
Where is the problem?
You don't need the doctrine configuration in your service config.
The connection driver is being configured inside app/config/config.yml.
The listener configuration looks good though - just remove the doctrine:config stuff.
Have a look at the doctrine configuration reference.
Symfony will automatically use the default connection for your listener/subscriber if you don't specify one using the connectionoption. The documentation is a bit confusing here but the doctrine connection is just there to show how to use a different connection.

using web.config variables within web.config

I would like to have a variable defined in my web.config that I can use in multiple places within my web.config file (and other config files). It's probably easier to explain by example ...
web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="AuthServiceEndPoint" value="any_old_name_i_like"/>
</appSettings>
<system.web>
...
<system.serviceModel>
<client>
<endpoint
address="net.tcp://localhost/AuthService"
binding="netTcpBinding"
contract="MyServices.Contracts.IAuthService"
name="#{AppSettings.AuthServiceEndPoint}"
bindingConfiguration="netTcpBindingConfig"
/>
</client>
</system.serviceModel>
</configuration>
windsor.config
<?xml version="1.0" encoding="utf-8" ?>
<castle>
<components>
...
<component
id="AuthProvider"
service="MyServices.Client.IAuthProvider, MyServices.Client"
type="MyServices.Client.AuthProvider, MyServices.Client"
lifestyle="transient">
<parameters>
<endpoint>#{AppSettings.AuthServiceEndPoint}</endpoint>
</parameters>
</component>
</components>
</castle>
Is this possible?
Edit (a bit more information)
I already have the ability to access the AppSettings from my windsor.config file (which is actually processed by castle windsor and a custom XmlInterpreter.
The real question is can I do this in my web.config?
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="AuthServiceEndPoint" value="any_old_name_i_like"/>
</appSettings>
<system.web>
...
<system.serviceModel>
<client>
<endpoint
address="net.tcp://localhost/AuthService"
binding="netTcpBinding"
contract="MyServices.Contracts.IAuthService"
name="#{AppSettings.AuthServiceEndPoint}"
bindingConfiguration="netTcpBindingConfig"
/>
</client>
</system.serviceModel>
</configuration>
ie - access variable in my <appSettings> from other parts of my web.config file.
Off the top of my head, I wonder if you might be able to do this with T4? I'm thinking that perhaps you could define a template which parses Web-Template.config and outputs Web.config? Of course, this only works for a single file.
You can use NAnt or MSBuild for this. You do need separate configuration files for both, but when you build your project they can automatically do transformations on your Web.config and other configuration files.
Not that I can think of. You could do your configuration in C# in global.asax.cs instead of the xml file.
Alternatively, have your web.config edited by your build process to replace all these values. FinalBuilder has a neato "Edit XML File" action that uses XPath quite well to do this, and FinalBuilder does have variables. Problem solved. This is how I do my builds at work.
Here I go answering my own question again :-S
I solved this by writing a NetTcpServiceLocator ...
public interface INetTcpServiceLocator
{
EndpointAddress GetAddress(Type serviceType);
}
... along with a custom config section handler which also implements the above interface and reads in the following config section ...
<services>
<service contract="My.Services.TestService.Contracts.ITestService" address="net.tcp://localhost/TestService" />
</services>
Then I created a proxy for each service ...
public class TestServiceProxy : ITestService
{
public SomeInformation GetSomeInformation(SomeParams #params)
{
using (var factory = new NetTcpServiceFactory<ITestService>())
{
var service = factory.Service;
return service.GetSomeInformation(#params);
}
}
}
My Controller has a dependency on a Service, which has a dependancy on ITestService. All this is glued together with Castle Windsor and by using property dependency injection.
So, my controller calls it's Service, which in turn calls the ITestService (in this case a proxy, which gets it's endpoint from the custom section handler).
The custom section handler (which is also the INetTcpServiceLocator) has a windsor lifestyle of "perWebRequest", so it gets called by the framework and web.config is read into an array in memory. When the service proxy is called, it then just pulls the relevant endpoint based on the contract type.
It's all driven by the type of the contract, so there is no need to have any variables in web.config anymore.
I've gone for a code based solution, as I don't use a build process locally, only when I submit my code to subversion does the build process kick in on our build server.

Resources