Hi all,

I would like if someone could clarify some points to me regarding the
dependency container. I've successfully modified some stuff of the security
component just adding a config.xml to my Resources/config dir. I've changed
some parameters of the security component there. Then, in my
app/config/config.yml I've imported my Resources/config/config.xml and
everything went fine.

Now, I want to create a service of my own on one of my bundles. But I don't
want to make the user import the config.xml from his/her
app/config/config.yml. What I see everyone does is create a
MyBundle/DependencyInjection/WhateverExtension.php, and automatically load
the config there. So, with my new service, what I did es create again a
simple Resources/config/config.xml that looks like this:

<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://www.symfony-project.org/schema/dic/services";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services
http://www.symfony-project.org/schema/dic/services/services-1.0.xsd";>

  <parameters>
    <parameter
key="my_service.class">Bundle\MyBundle\ModuleManager\ModuleManager</parameter>
  </parameters>

  <services>
    <service id="my_service" class="%my_service.class%" />
  </services>
</container>


Then, I create DependencyInjection/WhateverExtension.php


class WhateverExtension extends Extension
{
    public function configLoad( $config, ContainerBuilder $container )
    {
$loader = new XmlFileLoader( $container, __DIR__.'/../Resources/config' );
$loader->load( 'config.xml' );
    }
 public function getXsdValidationBasePath()
    {
        return __DIR__.'/../Resources/config/schema';
    }

    public function getNamespace()
    {
        return 'http://www.symfony-project.org/schema/dic/my_service';
    }

    public function getAlias()
    {
        return 'my_service';
    }
}

Finally, to get it work I had to add this to my app/config/config.yml

my_service.config: ~




Then, my questions:

1) Is this the way to create a service that needs to get autoloaded, without
import the xml file from the app/config/config.yml? If that's the case, Is
this the shortest way to create a new service that gets autoloaded?
2) The getAlias method is the alias to get the service with
$this->container->get( $myAlias ) ?
3) Which are the other uses the Extension class has, besides the fact that
it gets autoloaded? For example, I saw a lot of other extensions (from some
symfony bundles too) and it seems to provide a way to handle defaults for
certain configs.
4) Any other point that you can tell me about this topic would be of great
help. I saw the Dependency Injection docs (I'll have to see it again to
refresh my knowledge :P), and I saw the part of this topic on the symfony 2
docs, but there're a few points that still don't know about it. I know that
the documentation will be more and more complete within the next months, but
if you can give me a few hints regarding this topic, I'd be very grateful :)



Thanks and sorry for the long post.

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to