This gist is about using a Multi-Tenancy strategy for your Doctrine entities.
Multi-tenancy is an architecture in which a single instance of a software application serves multiple customers. Each customer is called a tenant. Tenants may be given the ability to customize some parts of the application [...] but they cannot customize the application's code.
All files are here: https://gist.github.com/CarlosEduardo/aedfa640e3f7f22451686fb7e57228e3
The Doctrine Multi-Tenancy strategy is a:
TenantFilter
class derived fromDoctrine\ORM\Query\Filter\SQLFilter
(seeTenantFilter.php
)TenantAwareInterface
interface to filter your entities (seeTenantAwareInterface.php
)ExampleEntity
class as an@ORM\Entity
implements the interface (seeExampleEntity.php
)
For Zend Framework with DoctrineORMModule users:
- Register the
tenant
filter in yourconfig/module.config.php
(see:module.config.php
) - Enable
tenant
filter in yourModule.php
atModule::onBootstrap()
(see:Module.php
)
For Symphony users:
- Register and enable the
tenant
filter in yourconfig.yml
(see:config.yml
)
For pure Doctrine (or another framework) users:
- Register and enable the
tenant
filter in any bootstrap file (see:pure-doctrine.php
)
Sorry for my bad english :)
Twitter: @CarlosEduardo | E-mail: [email protected]
Reference: http://doctrine2.readthedocs.io/en/latest/reference/filters.html
Awesome, thanks a lot! There's a little typo in the pure-doctrine.php, maybe you want to incorporate this little fix: https://gist.github.com/melbings/7f41c85d4ee00e39a97e1d136b405714/revisions#diff-eacb0c1292c23e7dedea6bee10fed37d