BazingaHateoasBundle icon indicating copy to clipboard operation
BazingaHateoasBundle copied to clipboard

Symfony service resolver for DIExtraBundle

Open ibraelillo opened this issue 10 years ago • 4 comments

Hello,

I'm using this bundle for creating an api rest, and also the DIExtraBundle for service annotations.

The issue is that I must declare the service in xml for having a result from the SymfonyContainerResolver class in order of finding my custom relation provider.

I have tested with yml and it doesn't work neither. I've looked into code and I found that the SymfonyContainerResolver class uses the definition in xml for finding the service.

/**
     * {@inheritdoc}
     */
    public function getRelationProvider(RelationProviderConfiguration $configuration, $object)
    {
        if (!preg_match('/^(?P<service>[a-z0-9_.]+):(?P<method>[a-z0-9_]+)$/i', $configuration->getName(), $matches)) {
            return null;
        }

        return array(
            $this->container->get($matches['service']),
            $matches['method']
        );
    }

is it possible of searching the service directly in the service container and not with a regular expression evaluating the xml declaration? That would be great considering the people who use DIExtraBundle or KnpRadBundle for extending annotations.

Thank you

ibraelillo avatar Feb 12 '14 10:02 ibraelillo

Well, why not. Wanna work on this?

willdurand avatar Feb 13 '14 15:02 willdurand

Why not. :)

El jueves, 13 de febrero de 2014, William Durand [email protected] escribió:

Well, why not. Wanna work on this?

Reply to this email directly or view it on GitHubhttps://github.com/willdurand/BazingaHateoasBundle/issues/19#issuecomment-34988469 .

"If you think a professional is expensive, wait 'til you see what an amateur can cost you!" Red Adair

ibraelillo avatar Feb 13 '14 20:02 ibraelillo

@ibraelillo You should be able to specify the id of your service http://jmsyst.com/bundles/JMSDiExtraBundle/master/annotations#service

use JMS\DiExtraBundle\Annotation as DI;

/**
 * @DI\Service("my_relation_provider")
 */
class CustomRelationProvider
{
}
use Hateoas\Configuration\Annotation as Hateoas;

/**
 * @Hateoas\RelationProvider("my_relation_provider")
 */
class UserRepresentation
{
}

Let me know if that fixes your issue! (Sorry for the delay :-()

adrienbrault avatar Jun 03 '14 03:06 adrienbrault

ping @ibraelillo

willdurand avatar Jul 09 '14 12:07 willdurand