View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_Application_Resource_Doctrine
{zone-data}

{zone-data:proposer-list}
[Matthew Lurz|mailto:mlurz71@gmail.com]
{zone-data}

{zone-data:liaison}
TBD
{zone-data}

{zone-data:revision}
0.1 - 1 June 2009: Initial Draft.
{zone-data}

{zone-data:overview}
Zend_Application_Resource_Doctrine is a resource plugin for the Doctrine O/RM that supports manager and connection level configuration and initialization.

A working prototype is available [here|http://github.com/mlurz71/parables/tree] in Parables/Application/Resource/Doctrine.php
{zone-data}

{zone-data:references}
* Doctrine
* Zend_Application_Resource
{zone-data}

{zone-data:requirements}
* This component will allow configuration of manager level attributes.

* This component will allow configuration of connection level attributes.

* This component will allow configuration of and initialization for connections.

* This component will allow configuration of connection level event listeners.

* This component will allow configuration of manager and connection level query and result caching.

* This component will support both non-namespaced, Doctrine generated models and custom, namespaced models.

* This component does not currently support Doctrine extensions due to autoloading issues.

* This component does not currently support bitmasks for manager and connection attribute values
{zone-data}

{zone-data:dependencies}
* Zend_Application_Resource_ResourceAbstract
{zone-data}

{zone-data:operation}
The component will work like other resource plugins. Users will specify configuration options in an application configuration files and use Zend_Application_Bootstrap to load the resource.
{zone-data}

{zone-data:milestones}
* Milestone 1: [DONE] Initial proposal published for review.
* Milestone 2: Working prototype checked into the incubator supporting use cases #1, #2, ...
* Milestone 3: Working prototype checked into the incubator supporting use cases #3 and #4.
* Milestone 4: Unit tests exist, work, and are checked into SVN.
* Milestone 5: Initial documentation exists.
{zone-data}

{zone-data:class-list}
* Zend_Application_Resource_Doctrine
{zone-data}

{zone-data:use-cases}
||UC-01||

*Initial Setup*

The two most common usage scenarios are those of generating model classes from schema and creating models by hand. In either case:

- Add a key to application.ini for registering the Doctrine namespace with the default autoloader.

{code}
autoloaderNamespaces[] = "Doctrine"
{code}

If generating model classes from schema files:

- Add paths to your models and generated models anywhere the include_path is
set such as public/index.php, tests/index.php, scripts/somescript.sh, etc.

{code}
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/models'),
realpath(APPLICATION_PATH . '/models/generated'),
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
{code}

- Add a method to your bootstrap(s) for setting the fallback autoloader.

{code}
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoload()
{
$autoloader = $this->getApplication()->getAutoloader();
if (!$autoloader->isFallbackAutoloader()) {
$autoloader->setFallbackAutoloader(true);
}
return $autoloader;
}
}
{code}

If creating model classes by hand:

- Add a method to your bootstrap(s) to configure module autoloading.

{code}
protected function _initAutoload()
{
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'namespace',
'basePath' => dirname(__FILE__),
));
return $autoloader;
}
{code}

- When using table classes, you will also need to enable table classautoloading at either the manager or connection level in as:

{code}
resources.doctrine.manager.attributes.attr_autoload_table_classes = 1
{code}

.. or ..

{code}
resources.doctrine.connections.cx1.attributes.attr_autoload_table_classes = 1
{code}

||UC-02||

*Configure DSNs*

Connection DSNs can be specified in any combination of string and/or array
formats.

Configure a DSN (string form)
{code}
resources.doctrine.connections.cx1.dsn = "mysql://user:pass@host/cx1"
{code}

Configure a DSN (array form)
{code}
resources.doctrine.connections.cx1.dsn.adapter = "mysql"
resources.doctrine.connections.cx1.dsn.user = "user"
resources.doctrine.connections.cx1.dsn.pass = "pass"
resources.doctrine.connections.cx1.dsn.hostspec = "host"
resources.doctrine.connections.cx1.dsn.database = "cx1"
resources.doctrine.connections.cx1.dsn.options.option1 = "value"
resources.doctrine.connections.cx1.dsn.options.option2 = "value"
{code}

||UC-03||

*Configure Manager Attributes*

{code}
resources.doctrine.manager.attributes.attr_auto_accessor_override = 0
resources.doctrine.manager.attributes.attr_auto_free_query_objects = 0
resources.doctrine.manager.attributes.attr_autoload_table_classes = 0
resources.doctrine.manager.attributes.attr_quote_identifier = 0
resources.doctrine.manager.attributes.attr_use_dql_callbacks = 0
resources.doctrine.manager.attributes.attr_use_native_enum = 0

resources.doctrine.manager.attributes.attr_export = "export_all"
resources.doctrine.manager.attributes.attr_model_loading = "model_loading_conservative"
resources.doctrine.manager.attributes.attr_portability = "portability_all"
resources.doctrine.manager.attributes.attr_query_limit = "limit_records"
resources.doctrine.manager.attributes.attr_validate = "validate_all"

resources.doctrine.manager.attributes.attr_default_column_options.length = 255
resources.doctrine.manager.attributes.attr_default_column_options.notnull = 1
resources.doctrine.manager.attributes.attr_default_column_options.type = "string"

resources.doctrine.manager.attributes.attr_default_identifier_options.length = 16
resources.doctrine.manager.attributes.attr_default_identifier_options.name = "%s_id"
resources.doctrine.manager.attributes.attr_default_identifier_options.type = "string"

resources.doctrine.manager.attributes.attr_dbname_format = "appname_%s"
resources.doctrine.manager.attributes.attr_idxname_format = "%s_index"
resources.doctrine.manager.attributes.attr_seqname_format = "%s_sequence"
resources.doctrine.manager.attributes.attr_tblname_format = "%s"

resources.doctrine.manager.attributes.attr_query_cache.class = "Doctrine_Cache_Memcache"
resources.doctrine.manager.attributes.attr_query_cache.lifespan = 3600
resources.doctrine.manager.attributes.attr_query_cache.options.compression = 0
resources.doctrine.manager.attributes.attr_query_cache.options.servers.host = "localhost"
resources.doctrine.manager.attributes.attr_query_cache.options.servers.persistent = 1
resources.doctrine.manager.attributes.attr_query_cache.options.servers.port = "11211"

resources.doctrine.manager.attributes.attr_result_cache.class = "Doctrine_Cache_Memcache"
resources.doctrine.manager.attributes.attr_result_cache.lifespan = 3600
resources.doctrine.manager.attributes.attr_result_cache.options.compression = 0
resources.doctrine.manager.attributes.attr_result_cache.options.servers.host = "localhost"
resources.doctrine.manager.attributes.attr_result_cache.options.servers.persistent = 1
resources.doctrine.manager.attributes.attr_result_cache.options.servers.port = 11211
{code}

||UC-04||

*Configure Connection Attributes*

{code}
resources.doctrine.connections.cx1.attributes.attr_auto_accessor_override = 0
resources.doctrine.connections.cx1.attributes.attr_auto_free_query_objects = 0
resources.doctrine.connections.cx1.attributes.attr_autoload_table_classes = 0
resources.doctrine.connections.cx1.attributes.attr_quote_identifier = 0
resources.doctrine.connections.cx1.attributes.attr_use_dql_callbacks = 0
resources.doctrine.connections.cx1.attributes.attr_use_native_enum = 0

resources.doctrine.connections.cx1.attributes.attr_export = "export_all"
resources.doctrine.connections.cx1.attributes.attr_model_loading = "model_loading_conservative"
resources.doctrine.connections.cx1.attributes.attr_portability = "portability_all"
resources.doctrine.connections.cx1.attributes.attr_query_limit = "limit_records"
resources.doctrine.connections.cx1.attributes.attr_validate = "validate_all"

resources.doctrine.connections.cx1.attributes.attr_dbname_format = "appname_%s"
resources.doctrine.connections.cx1.attributes.attr_idxname_format = "%s_index"
resources.doctrine.connections.cx1.attributes.attr_seqname_format = "%s_sequence"
resources.doctrine.connections.cx1.attributes.attr_tblname_format = "%s"

resources.doctrine.connections.cx1.attributes.attr_default_column_options.length = 255
resources.doctrine.connections.cx1.attributes.attr_default_column_options.notnull = 1
resources.doctrine.connections.cx1.attributes.attr_default_column_options.type = "string"

resources.doctrine.connections.cx1.attributes.attr_default_identifier_options.length = 16
resources.doctrine.connections.cx1.attributes.attr_default_identifier_options.name = "%s_id"
resources.doctrine.connections.cx1.attributes.attr_default_identifier_options.type = "string"

resources.doctrine.connections.cx1.attributes.attr_query_cache.class = "Doctrine_Cache_Memcache"
resources.doctrine.connections.cx1.attributes.attr_query_cache.lifespan = 3600
resources.doctrine.connections.cx1.attributes.attr_query_cache.options.compression = 0
resources.doctrine.connections.cx1.attributes.attr_query_cache.options.servers.host = "localhost"
resources.doctrine.connections.cx1.attributes.attr_query_cache.options.servers.persistent = 1
resources.doctrine.connections.cx1.attributes.attr_query_cache.options.servers.port = "11211"

resources.doctrine.connections.cx1.attributes.attr_result_cache.class = "Doctrine_Cache_Memcache"
resources.doctrine.connections.cx1.attributes.attr_result_cache.lifespan = 3600
resources.doctrine.connections.cx1.attributes.attr_result_cache.options.compression = 0
resources.doctrine.connections.cx1.attributes.attr_result_cache.options.servers.host = "localhost"
resources.doctrine.connections.cx1.attributes.attr_result_cache.options.servers.persistent = 1
resources.doctrine.connections.cx1.attributes.attr_result_cache.options.servers.port = 11211

resources.doctrine.connections.cx1.listeners.listener1 = "somelistener"
resources.doctrine.connections.cx1.listeners.listener2 = "someotherlistener"
{code}

{zone-data:skeletons}
{code}
class Parables_Application_Resource_Doctrine extends Zend_Application_Resource_ResourceAbstract
{
/**
* Build DSN string from an array
*
* @param array $dsn
* @return string
*/
protected function _buildDsnFromArray(array $dsn)
{
}

/**
* Set attributes for a Doctrine_Configurable instance
*
* @param Doctrine_Configurable $object
* @param array $attributes
* @return void
* @throws Zend_Application_Resource_Exception
*/
protected function _setAttributes(Doctrine_Configurable $object, array $attributes)
{
}

/**
* Set connection listeners
*
* @param Doctrine_Connection_Common $conn
* @param array $options
* @return void
* @throws Zend_Application_Resource_Exception
*/
protected function _setConnectionListeners(Doctrine_Connection_Common $conn, array $options)
{
}

/**
* Retrieve a Doctrine_Cache instance
*
* @param array $options
* @return Doctrine_Cache
* @throws Zend_Application_Resource_Exception
*/
protected function _getCache(array $options)
{
}

/**
* Set manager level attributes
*
* @param array $options
* @return Parables_Application_Resource_Doctrine
*/
public function setManager(array $options)
{
}

/**
* Set connections and connection level attributes
*
* @param array $options
* @return Parables_Application_Resource_Doctrine
* @throws Zend_Application_Resource_Exception
*/
public function setConnections(array $options)
{
}

/**
* Defined by Zend_Application_Resource_Resource
*
* @return Parables_Application_Resource_Doctrine
* @throws Zend_Application_Resource_Exception
*/
public function init()
{
}
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>