2017 © Pedro Peláez
 

symfony-bundle association-resolver-bundle

Resolve relations over annotations

image

ibrows/association-resolver-bundle

Resolve relations over annotations

  • Monday, August 18, 2014
  • by ibrows
  • Repository
  • 14 Watchers
  • 0 Stars
  • 9,488 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 1 % Grown

The README.md

Important:

This Bundle is now stored here: https://gitlab.pwc-digital.ch/ec/bundles/IbrowsAssociationResolverBundle, (*1)

iBrows Association Bundle

A simple bundle to resolve associations on entities when they'll be imported from an external source, (*2)

Create an annotation

See Annotation/OneToMany.php, (*3)

In this case I'm going to create a new OneToMany-annotation for this bundle. Therefore I create a new class called OneToMany in the 'Annotation' folder and annotate the class with @Annotation and extend it from the AbstractAssociation If you need to add some properties which can be configured in the annotation create a public property in the Annotation and create the getter/setter, (*4)

Create the resolver

See Resolver/Type/OneToMany.php, (*5)

To handle the entity with our annotation @OneToMany we have to create a resolver with the exact same name as the annotation class name. Our resolver extends the AbstractResolver to handle the annotated entity correctly. While extending the AbstractResolver we have to implement an abstract function to handle an entity and recive all the configurated properties., (*6)

    
        /**
         * @param ResultBag $resultBag
         * @param AssociationMappingInfoInterface $mappingInfo
         * @param string $propertyName
         * @param mixed $entity
         * @param OutputInterface $output
         * @return ResolverInterface
         */
        public function resolveAssociation(
            ResultBag $resultBag,
            AssociationMappingInfoInterface $mappingInfo,
            $propertyName,
            $entity,
            OutputInterface $output
        )
    

in the function body we extract the data from the mappinginfo for further operations. Inside the MappingInfo object where two properties. The Annotation and the Metadata. The Annotation object holds all the data which can be configured in the annotation. In our case we have 2 properties, (*7)

public $collectionAddFunctionName;
public $collectionRemoveFunctionName;

collectionAddFunctionName to customize the add function. If this property is not set the method name will be generated with an 'add' as prefix and the propertyname as suffix, (*8)

collectionRemoveFunctionName to customize the remove function. If this property is not set the method name will be generated with an 'remove' as prefix and the propertyname as suffix, (*9)

The Service

To make the resolver functional you have to register the resolver as a service in the service.xml, (*10)

<service id="ibrows_associationresolver.resolver.onetoone" class="Ibrows\AssociationResolver\Resolver\Type\OneToOne">
    <argument type="service" id="doctrine.orm.entity_manager" />
    <tag priority="-20" name="ibrows_associationresolver.resolverchain" />
    <call method="setSoftdeletable">
        <argument>%ibrows_associationresolver.softdelete%</argument>
    </call>
    <call method="setSoftdeletableGetter">
        <argument>%ibrows_associationresolver.softdeletegetter%</argument>
    </call>
</service>
´

The tag defines the position in the chain., (*11)

The Versions

18/08 2014

dev-master

9999999-dev

Resolve relations over annotations

  Sources   Download

MIT

The Requires

 

resolver annotation ibrows association

18/08 2014

1.0.6

1.0.6.0

Resolve relations over annotations

  Sources   Download

MIT

The Requires

 

resolver annotation ibrows association

18/08 2014

1.0.5

1.0.5.0

Resolve relations over annotations

  Sources   Download

MIT

The Requires

 

resolver annotation ibrows association

30/04 2014

1.0.4

1.0.4.0

Resolve relations over annotations

  Sources   Download

MIT

The Requires

 

resolver annotation ibrows association

08/04 2013

1.0.3

1.0.3.0

Resolve relations over annotations

  Sources   Download

MIT

The Requires

 

resolver annotation ibrows association

05/03 2013

1.0.2

1.0.2.0

Resolve relations over annotations

  Sources   Download

MIT

The Requires

 

resolver annotation ibrows association

21/02 2013

1.0.1

1.0.1.0

Resolve relations over annotations

  Sources   Download

MIT

The Requires

 

resolver annotation ibrows association

20/02 2013

1.0.0

1.0.0.0

Resolve relations over annotations

  Sources   Download

MIT

The Requires

 

resolver annotation ibrows association