1
0
mirror of synced 2025-01-18 22:41:43 +03:00

[2.0] Removing unused code and committing a little 2.0 documentation

This commit is contained in:
jwage 2009-02-17 02:43:40 +00:00
parent f4719b290b
commit 4dc5a4baf5
4 changed files with 92 additions and 50 deletions

View File

@ -1,4 +1,90 @@
Upgrade to Doctrine 2.0
#######################
## Installing
More information coming soon...
Currently the only way to install is via svn. So just checkout the trunk.
$ svn co http://svn.doctrine-project.org/trunk/lib doctrine
$ cd doctrine
## Loading Doctrine
First we need to require one class, the `ClassLoader`.
>**NOTE**
> This assumes you've created some kind of script to test the following code in. Something like a `test.php` file.
[php]
// test.php
require_once 'lib/Doctrine/Common/ClassLoader.php';
Now we need to instantiate the `ClassLoader` and register it:
[php]
$classLoader = new \Doctrine\Common\ClassLoader();
$classLoader->register();
The Doctrine `ClassLoader` supports the ability to use it for loading other classes with a prefix.
Here are the recommend usages for the Doctrine `ClassLoader`:
* Use only 1 class loader instance.
* Set the base paths to your class libraries (including Doctrine's) through
-
[php]
$classLoader->setBasePath($prefix, $basePath);
For example you can set the path for Doctrine with the following:
[php]
$classLoader->setBasePath('Doctrine', '/usr/local/phplibs/doctrine/lib');
Then, when trying to load the class Doctrine\ORM\EntityManager, for example the class loader will look for /usr/local/phplibs/doctrine/lib/Doctrine/ORM/EntityManager.php
* DO NOT setCheckFileExists(true). Doing so is expensive in terms of performance.
* Use an opcode-cache (i.e. APC) (STRONGLY RECOMMENDED).
## Initialize Doctrine
[php]
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\ORM\Cache\ArrayCache);
$eventManager = new \Doctrine\Common\EventManager();
$connectionOptions = array(
'user' => 'john',
'password' => 'wayne'
);
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, 'doctrine', $config, $eventManager);
## Getting the Connection
[php]
$conn = $em->getConnection();
$conn->delete('table_name', array(1, 3, 10));
The DBAL Connection class has lots of useful functions. You can browse the code and check the API to get familiar.
## The Schema Manager
The schema manager is a nice API for issuing database DDL statements like creating a table, or dropping a table.
[php]
$sm = $connection->getSchemaManager();
The schema manager allows you to do all the familiar options on your schema. Like `createTable()`. Below you will find an example:
[php]
$sm->createTable($tableName, $columns, $options);
## The Platform Object
The platform object is the object that provides the appropriate SQL to the schema manager for the DDL statements.
[php]
$platform = $connection->getDatabasePlatform();
Now we can get the generated SQL instead of executing it directly:
[php]
$sql = $platform->getCreateTableSql($tableName, $columns, $options);

View File

@ -59,14 +59,6 @@ class EntityManager
*/
const FLUSHMODE_MANUAL = 'manual';
/**
* The currently active EntityManager. Only one EntityManager can be active
* at any time.
*
* @var Doctrine\ORM\EntityManager
*/
private static $_activeEm;
/**
* The unique name of the EntityManager.
*
@ -536,18 +528,6 @@ class EntityManager
return $this->_unitOfWork;
}
/**
* Checks whether this EntityManager is the currently active one.
*
* Note:This is only useful in scenarios where {@link ActiveEntity}s are used.
*
* @return boolean
*/
public function isActive()
{
return self::$_activeEm === $this;
}
/**
* Gets a hydrator for the given hydration mode.
*
@ -593,16 +573,6 @@ class EntityManager
$this->_hydrators[$hydrationMode] = $hydrator;
}
/**
* Makes this EntityManager the currently active one.
*
* Note: This is only useful in scenarios where {@link ActiveEntity}s are used.
*/
public function activate()
{
self::$_activeEm = $this;
}
/**
* Factory method to create EntityManager instances.
*
@ -636,17 +606,4 @@ class EntityManager
return $em;
}
/**
* Static lookup to get the currently active EntityManager.
*
* Note: Used by {@link ActiveEntity}s to actively lookup an EntityManager.
*
* @return Doctrine\ORM\EntityManager
*/
public static function getActiveEntityManager()
{
return self::$_activeEm;
}
}
}

View File

@ -35,8 +35,6 @@ class EntityPersisterTest extends \Doctrine\Tests\OrmTestCase
$this->_emMock->setUnitOfWork($this->_uowMock);
$this->_idGenMock = new SequenceMock($this->_emMock);
$this->_emMock->setIdGenerator('Doctrine\Tests\Models\Forum\ForumUser', $this->_idGenMock);
$this->_emMock->activate();
}
public function testSimpleInsert() {

View File

@ -15,7 +15,8 @@ class OrmTestCase extends DoctrineTestCase
*
* @return Doctrine\ORM\EntityManager
*/
protected function _getTestEntityManager($conf = null, $eventManager = null) {
protected function _getTestEntityManager($conf = null, $eventManager = null)
{
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(self::getSharedMetadataCacheImpl());
$eventManager = new \Doctrine\Common\EventManager();