Download the PHP package hostnet/entity-plugin-lib without Composer
On this page you can find all versions of the php package hostnet/entity-plugin-lib. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hostnet/entity-plugin-lib
More information about hostnet/entity-plugin-lib
Files in hostnet/entity-plugin-lib
Package entity-plugin-lib
Short Description Installer for all the Hostnet Doctrine entity libraries
License MIT
Informations about the package entity-plugin-lib
entity-plugin-lib
The problem
The Hostnet Entity Composer plugin was developed to solve several problems experienced with plain usage of the Doctrine ORM. Although our solution is inspired on working with doctrine it is perfectly usable for every other way of persisting entities. The problems we came across are:
- Entities became really big;
- Entities were shared between applications and these applications inherited functionality they were not allowed to use;
- Knowledge areas like calculating discounts were spread through the model and not grouped together;
- Misuse of inheritance to prevent code duplication.
To solve our problem we borrowed some ideas from another realm of software development, since we felt we were hitting the boundaries of Object Oriented Programming and sought for more modularization. We used the ideas behind Aspect Oriented Programming to solve our problems.
The basic concept: Entities are grouped by responsibility in packages. This plugin links the packages together.
This is awesome for you if;
- You maintain an open source project that includes entities, that you would like people to expand on.
- You have a database and various applications accessing different (but related) subsets of that database.
- Or searching to glue something yourself.
If you do not belong in one of those groups, be careful since this might not be what you want.
Example
One application needs to know about , but is unaware of the concept of a . Another application requires access to both of them. So in one application, you'd want to be able to call . But in the other, you'd prefer to not know about contracts at all!
With this plugin you can create one package that is purely focussed, and another that is focussed, and that injects the additional functionality (like ) to .
Usage
Creating an extendable package
- Create a composer package to put your entities in.
- Use PSR-0 or PSR-4 autoloading for the src/ directory.
- The package should be of type .
- The package should require
- Create one entity, say , inside a namespace that ends with .
-
Run . (The entity plugin hooks to this event.) This should cause some output:
- From your entity, use the trait generated in the namespace:
Congratulations, you now have an extendable entity package.
Extending the package
Follow the steps above, and
- Make sure your new package depends on the old one.
- Instead of creating the class, create a .
- Run .
- Check . It should include a reference to your package.
Tips
If you run the composer.phar with or or it will show more information.
If you want to extend an entity from your main application, you can use the setting in the extra section of your composer.json.
If you do not want to generate interfaces, you can set the setting to in the extra setting of your composer.json. We will change this to being the default behaviour in a future release.
For a quick overview have a look at the cheatsheet.
All versions of entity-plugin-lib with dependencies
composer-plugin-api Version ^2.0.0
doctrine/annotations Version ^1.13.2
phpdocumentor/type-resolver Version ^1.4.0
symfony/filesystem Version ^5.4||^6.0
twig/twig Version ^3.0