Skip to content

Commit

Permalink
Initial refactor from SpiffyDoctrineORM to DoctrineORMModule.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Spraggs authored and Kyle Spraggs committed Jan 10, 2012
1 parent 77e7ed7 commit 7165843
Show file tree
Hide file tree
Showing 12 changed files with 1,086 additions and 908 deletions.
65 changes: 54 additions & 11 deletions Module.php
@@ -1,24 +1,67 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace SpiffyDoctrineORM;
namespace DoctrineORMModule;

use Doctrine\Common\Annotations\AnnotationRegistry,
Zend\Module\Consumer\AutoloaderProvider;
RuntimeException,
Zend\Module\Consumer\AutoloaderProvider,
Zend\Module\Manager;

/**
* Base module for Doctrine ORM.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 1.0
* @version $Revision$
* @author Kyle Spraggs <theman@spiffyjr.me>
*/
class Module implements AutoloaderProvider
{
public function init()
public function init(Manager $moduleManager)
{
$libfile = __DIR__ . '/vendor/doctrine2-orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';
if (file_exists($libfile)) {
AnnotationRegistry::registerFile($libfile);
} else {
@include_once 'Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';
if (!class_exists('Doctrine\ORM\Mapping\Entity', false)) {
throw new \Exception(
'Ensure Doctrine can be autoloaded or initalize submodules in SpiffyDoctrineORM'
$moduleManager->events()->attach('loadModules.post', array($this, 'modulesLoaded'));
}

public function modulesLoaded($e)
{
$config = $e->getConfigListener()->getMergedConfig();
$config = $config['doctrine_orm_module'];

if ($config->use_annotations) {
$libfile = $config->annotation_file ?
realpath($config->annotation_file) :
realpath(__DIR__ . '/vendor/doctrine2-orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');

if (!$libfile || !file_exists($libfile)) {
throw new RuntimeException(
'Failed to load annotation mappings - check the "annotation_file" setting'
);
}
AnnotationRegistry::registerFile($libfile);
}

if (!class_exists('Doctrine\ORM\Mapping\Entity', true)) {
throw new \Exception('
Doctrine could not be autoloaded - ensure it is in the correct path.
');
}
}

Expand Down
4 changes: 2 additions & 2 deletions README.md
@@ -1,5 +1,5 @@
# SpiffyDoctrineORM Module for Zend Framework 2
The SpiffyDoctrineORM module intends to integrate Doctrine 2 ORM with Zend Framework 2 quickly
The DoctrineModule module intends to integrate Doctrine 2 ORM with Zend Framework 2 quickly
and easily. The following features are intended to work out of the box:

- Doctrine ORM support
Expand All @@ -8,7 +8,7 @@ and easily. The following features are intended to work out of the box:
- Support for using existing PDO connections

## Requirements
- [SpiffyDoctrine](http://www.github.com/spiffyjr/spiffydoctrine)
- [DoctrineModule](http://www.github.com/doctrine/DoctrineModule)
- [Zend Framework 2](http://www.github.com/zendframework/zf2)

## Installation
Expand Down
1,612 changes: 806 additions & 806 deletions autoload_classmap.php

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions config/module.config.php
@@ -1,5 +1,9 @@
<?php
return array(
'doctrine_orm_module' => array(
'annotation_file' => __DIR__ . '/../vendor/doctrine2-orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php',
'use_annotations' => true,
),
'di' => array(
'definition' => array(
'class' => array(
Expand All @@ -9,11 +13,11 @@
'port' => array('type' => false, 'required' => true),
)
),
'SpiffyDoctrineORM\Factory\EntityManager' => array(
'instantiator' => array('SpiffyDoctrineORM\Factory\EntityManager', 'get'),
'DoctrineORMModule\Factory\EntityManager' => array(
'instantiator' => array('DoctrineORMModule\Factory\EntityManager', 'get'),
'methods' => array(
'get' => array(
'conn' => array('type' => 'SpiffyDoctrineORM\Doctrine\ORM\Connection', 'required' => true)
'conn' => array('type' => 'DoctrineORMModule\Doctrine\ORM\Connection', 'required' => true)
)
)
),
Expand All @@ -22,20 +26,21 @@
'instance' => array(
'alias' => array(
// entity manager
'doctrine_em' => 'SpiffyDoctrineORM\Factory\EntityManager',
'doctrine_em' => 'DoctrineORMModule\Factory\EntityManager',
'orm_em' => 'doctrine_em',

// configuration
'orm_config' => 'SpiffyDoctrineORM\Doctrine\ORM\Configuration',
'orm_connection' => 'SpiffyDoctrineORM\Doctrine\ORM\Connection',
'orm_driver_chain' => 'SpiffyDoctrineORM\Doctrine\ORM\DriverChain',
'orm_evm' => 'SpiffyDoctrine\Doctrine\Common\EventManager',
'orm_config' => 'DoctrineORMModule\Doctrine\ORM\Configuration',
'orm_connection' => 'DoctrineORMModule\Doctrine\ORM\Connection',
'orm_driver_chain' => 'DoctrineORMModule\Doctrine\ORM\DriverChain',
'orm_evm' => 'DoctrineModule\Doctrine\Common\EventManager',
),
'orm_config' => array(
'parameters' => array(
'opts' => array(
'auto_generate_proxies' => true,
'proxy_dir' => __DIR__ . '/../../../data/SpiffyDoctrine/Proxy',
'proxy_namespace' => 'SpiffyDoctrine\Proxy',
'proxy_dir' => __DIR__ . '/../../../data/DoctrineORMModule/Proxy',
'proxy_namespace' => 'DoctrineORMModule\Proxy',
'entity_namespaces' => array(),
'custom_datetime_functions' => array(),
'custom_numeric_functions' => array(),
Expand Down
Expand Up @@ -8,18 +8,25 @@
* you may override the Zend\Di configuration manually (see module.config.php).
*/
$settings = array(
// if disabled will not register annotations
'use_annotations' => true,

// if use_annotations (above) is set to true this file will be registered
'annotation_file' => __DIR__ . '/../../vendor/DoctrineORMModule/vendor/doctrine2-orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php',

// enables production mode by disabling generation of proxies
'production' => false,

// sets the cache to use for metadata: one of 'array', 'apc', or 'memcache'
'cache' => 'memcache',
'cache' => 'array',

// only used if cache is set to memcache
'memcache' => array(
'host' => '127.0.0.1',
'port' => '11211'
),

// connection parameters
'connection' => array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
Expand All @@ -28,11 +35,15 @@ $settings = array(
'password' => 'password',
'dbname' => 'database',
),

// driver settings
'driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'namespace' => 'Application\Entity',
'paths' => array('module/Application/src/Application/Entity')
),

// namespace aliases for annotations
'namespace_aliases' => array(
),
);
Expand All @@ -50,6 +61,10 @@ if (!in_array($settings['cache'], $cache)) {
$settings['cache'] = 'doctrine_cache_' . $settings['cache'];

return array(
'doctrine_orm_module' => array(
'annotation_file' => $settings['annotation_file'],
'use_annotations' => $settings['use_annotations'],
),
'di' => array(
'instance' => array(
'doctrine_memcache' => array(
Expand Down
@@ -1,10 +1,39 @@
<?php
namespace SpiffyDoctrineORM\Doctrine\ORM;
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace DoctrineORMModule\Doctrine\ORM;

use Doctrine\Common\Cache\Cache,
Doctrine\DBAL\Logging\SQLLogger,
Doctrine\ORM\Configuration as DoctrineConfiguration,
SpiffyDoctrine\Doctrine\Instance;
DoctrineModule\Doctrine\Instance;

/**
* Wrapper for Doctrine ORM configuration that helps setup configuration without relying
* entirely on Di.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 1.0
* @version $Revision$
* @author Kyle Spraggs <theman@spiffyjr.me>
*/
class Configuration extends Instance
{
/**
Expand Down Expand Up @@ -81,7 +110,7 @@ public function __construct(array $opts, $metadataDriver, Cache $metadataCache,

/**
* (non-PHPdoc)
* @see SpiffyDoctrineORM\Instance.Instance::loadInstance()
* @see DoctrineORMModule\Instance.Instance::loadInstance()
*/
protected function loadInstance()
{
Expand Down
81 changes: 81 additions & 0 deletions src/DoctrineORMModule/Doctrine/ORM/Connection.php
@@ -0,0 +1,81 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace DoctrineORMModule\Doctrine\ORM;

use PDO,
Doctrine\DBAL\DriverManager,
DoctrineModule\Doctrine\Instance,
DoctrineModule\Doctrine\Common\EventManager;

/**
* Wrapper for Doctrine ORM connection that helps setup configuration without relying
* entirely on Di.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 1.0
* @version $Revision$
* @author Kyle Spraggs <theman@spiffyjr.me>
*/
class Connection extends Instance
{
/**
* @var Doctrine\ORM\Configuration
*/
protected $config;

/**
* @var Doctrine\Common\EventManager
*/
protected $evm;

/**
* Constructor
*
* @param array $opts
* @param Configuration $config
* @param EventManager $evm
* @param PDO $pdo
*/
public function __construct(array $params, Configuration $config, EventManager $evm, PDO $pdo = null)
{
if ($pdo) {
$params['pdo'] = $pdo;
}

$this->config = $config->getInstance();
$this->evm = $evm->getInstance();

parent::__construct($params);
}

/**
* (non-PHPdoc)
* @see DoctrineORMModule\Instance.Instance::loadInstance()
*/
protected function loadInstance()
{
$this->instance = DriverManager::getConnection(
$this->opts,
$this->config,
$this->evm
);
}
}
35 changes: 35 additions & 0 deletions src/DoctrineORMModule/Doctrine/ORM/DriverChain.php
@@ -0,0 +1,35 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace DoctrineORMModule\Doctrine\ORM;

use DoctrineModule\Doctrine\Common\DriverChain as CommonDriverChain;

/**
* Wrapper for Doctrine DriverChain that helps setup configuration without relying
* entirely on Di.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 1.0
* @version $Revision$
* @author Kyle Spraggs <theman@spiffyjr.me>
*/
class DriverChain extends CommonDriverChain
{}

0 comments on commit 7165843

Please sign in to comment.