net_bazzline / php_propel_behavior_entity_instantiator
This free as in freedom behavior that easy up entity instantiation for propel
Installs: 1 399
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 6
Forks: 2
Open Issues: 2
Requires
- php: >=7.4
- mikey179/vfsstream: dev-master
- phpunit/phpunit: ^7.0|^8.0
- propel/propel1: @dev
Requires (Dev)
- symplify/easy-coding-standard: ^6.1@dev
README
I still like the idea but there is currently no use case to develop it anymore.
Entity Instantiator Generator Behavior for Propel
This free as in freedom behavior that easy up entity instantiation for your propel query and object classes.
Thanks to the ExtraPropertiesBehavior to act as such a great template.
The build status of the current master branch is tracked by Travis CI:
It is available at openhub.net.
If you want to control things in more detail, you should have a look to the locator generator component for php and its propel examples
The current change log can be found here.
Why
- no
new
in your code anymore - no static
Query::create
call in your code anymore - eases up writing test code (
createMyEntity
andcreateMyEntityQuery
can be mocked)
Usage
- make sure you have
extension=pdo_sqlite.so
enabled if you want to run phpunit - the behavior creates a instantiator class and file
- the behavior has following parameters
entity_instantiator_add_to_entity_instantiator
- ("true"|"false") allowed to add or not add this table to the instantiator, default istrue
entity_instantiator_class_name
- (string) that represents the class name, default isDatabaseEntityInstantiator
entity_instantiator_extends
- (string) that represents the full qualified class name, default is ``entity_instantiator_indention
- (string) that represents the indention in the instantiator, default isentity_instantiator_namespace
- (string) that represents the namespace in the instantiator, default is `` (no namespace)entity_instantiator_path_to_output
- (string) that represents the path (relative tovendor/../
) where the instantiator file will be written, default isdata
entity_instantiator_method_name_prefix
- (string) that represents the prefix for each instantiation method in the instantiator, default iscreate<DatabaseName>
entity_instantiator_default_connection_mode
- (string) that represents the content of the second optional argument in Propel::getConnection($name, $mode)entity_instantiator_default_connection_name
- (string) that represents the content of the first optional argument in Propel::getConnection($name, $mode)entity_instantiator_use_fully_qualified_name
- ("true"|"false") allows to switch usage between fully qualified name or class name, default isfalse
Example
Given a database with following settings
<database name="exampleDatabase"> <behavior name="add_to_entity_instantiator"> <parameter name="entity_instantiator_class_name" value="MyEntityInstantiator" /> <parameter name="entity_instantiator_extends" value="MyAbstractEntityInstantiator" /> <parameter name="entity_instantiator_indention" value=" " /> <parameter name="entity_instantiator_namespace" value="Database\Service" /> <parameter name="entity_instantiator_path_to_output" value="module/Database/src/Database/Service" /> <parameter name="entity_instantiator_method_name_prefix" value="create" /> <paramater name="entity_instantiator_default_connection_name" value="exampleDatabase" /> <paramater name="entity_instantiator_default_connection_mode" value="Propel::CONNECTION_READ" /> <paramater name="entity_instantiator_use_fully_qualified_name" value="true" /> </behavior> <table name="user"> <column name="id" type="INTEGER" primaryKey="true" autoincrement="true" /> <column name="name" type="VARCHAR" size="255" /> <!-- turn it on - default --> <behavior name="add_to_entity_instantiator"> <parameter name="entity_instantiator_add_to_entity_instantiator" value="true" /> </behavior> </table> <table name="product"> <column name="id" type="INTEGER" primaryKey="true" autoincrement="true" /> <column name="name" type="VARCHAR" size="255" /> <!-- turn it on --> <behavior name="add_to_entity_instantiator"> <parameter name="entity_instantiator_add_to_entity_instantiator" value="false" /> </behavior> </table> </database>
will create a file called MyEntityInstantiator.php
in the path module/Database/src/Database/Service
with following content.
<?php namespace Database\Service; use PDO; use Propel; /** * Class MyEntityInstantiator * * @author Net\Bazzline\Propel\Behavior\EntityInstantiatorNet\Bazzline\Propel\Behavior\EntityInstantiator\EntityInstantiatorGenerator * @since 2015-08-29 * @see http://www.bazzline.net */ class MyEntityInstantiator extends MyAbstractEntityInstantiator { /** * @return PDO */ public function getConnection($name = 'exampleDatabase', $mode = \Propel::CONNECTION_WRITE) { return Propel::getConnection($name, $mode); } /** * @return \Database\User */ public function createUser() { return new \Database\User(); } /** * @return \Database\UserQuery */ public function createUserQuery() { return new \Database\UserQuery::create(); } }
Installation
By Hand
mkdir -p vendor/net_bazzline/php_propel_behavior_entity_instantiator
cd vendor/net_bazzline/php_propel_behavior_entity_instantiator
git clone https://github.com/bazzline/php_propel_behavior_entity_instantiator
With Packagist
"net_bazzline/php_propel_behavior_entity_instantiator": "dev-master"
Enable Behavior in Propel
- add the following to your propel.ini
propel.behavior.create_entity_instantiator.class = lib.vendor.net_bazzline.php_propel_behavior_create_entity.source.AddToEntityInstantiatorBehavior
API
API available at bazzline.net
Final Words
Star it if you like it :-). Add issues if you need it. Pull patches if you enjoy it. Write a blog entry if you use it. Donate something if you love it :-].