Commit: fe942507db0d0d0ba1263d8c33cda8bf2b108011
Author: Richard McIntyre | Date: 2011-01-13 16:59:01 +0900
diff --git a/config/bootstrap.php b/config/bootstrap.php
index 96ccd87..449af50 100644
--- a/config/bootstrap.php
+++ b/config/bootstrap.php
@@ -21,4 +21,4 @@ foreach($libraries as $name) {
}
}
-?>
\ No newline at end of file
+?>
diff --git a/extensions/command/Doctrine.php b/extensions/command/Doctrine.php
index bc3da89..fccddb9 100644
--- a/extensions/command/Doctrine.php
+++ b/extensions/command/Doctrine.php
@@ -59,9 +59,26 @@ class Doctrine extends \lithium\console\Command {
protected $_repositoryPath = 'git://github.com/doctrine/doctrine2.git';
public function run($args = array()) {
- $args = $this->_config['request']->args;
+
+ $defaults = array(
+ 'proxy' => array(
+ 'auto' => true,
+ 'path' => LITHIUM_APP_PATH . '/resources/tmp/cache/Doctrine/Proxies',
+ 'namespace' => 'Doctrine\Proxies'
+ ),
+ 'useModelDriver' => true,
+ 'mapping' => array('class' => null, 'path' => LITHIUM_APP_PATH . '/models'),
+ 'configuration' => null,
+ 'eventManager' => null,
+ );
+
+ if ($this->request->params['action'] != 'run') {
+ $args = $this->request->argv;
+ }
+
$input = new \Symfony\Component\Console\Input\ArgvInput($args);
$conn = Connections::get($this->connection);
+ $conn->_config = $conn->_config + $defaults;
if (!$conn || !$conn instanceof \li3_doctrine\extensions\data\source\Doctrine) {
$error = "Error: Could not get Doctrine proxy object from Connections, using";
@@ -79,29 +96,28 @@ class Doctrine extends \lithium\console\Command {
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
- //Annotation Driver
+ //Annotation Driver
$driver = $config->newDefaultAnnotationDriver(array(LITHIUM_APP_PATH . '/models'));
$config->setMetadataDriverImpl($driver);
//Proxy configuration
- $config->setProxyDir($conn->_config['proxyDir']);
- $config->setProxyNamespace($conn->_config['proxyNamespace']);
+ $config->setProxyDir($conn->_config['proxy']['path']);
+ $config->setProxyNamespace($conn->_config['proxy']['namespace']);
//EntityManager
$em = \Doctrine\ORM\EntityManager::create($conn->_config, $config);
- $helpers = array(
- 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
- 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
- );
+ $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
+ 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
+ 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
+ ));
//CLI
- $cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', \Doctrine\Common\Version::VERSION);
+ $cli = new \Symfony\Component\Console\Application(
+ 'Doctrine Command Line Interface', \Doctrine\Common\Version::VERSION
+ );
$cli->setCatchExceptions(true);
$cli->register('doctrine');
- $helperSet = $cli->getHelperSet();
- foreach ($helpers as $name => $helper) {
- $helperSet->set($helper, $name);
- }
+ $cli->setHelperSet($helperSet);
$cli->addCommands(array(
// DBAL Commands
@@ -126,6 +142,7 @@ class Doctrine extends \lithium\console\Command {
));
$cli->run($input);
}
+
public function install() {
$this->installPath = $this->installPath ?: LITHIUM_APP_PATH . '/libraries';
@@ -223,6 +240,14 @@ class Doctrine extends \lithium\console\Command {
$this->out("{$message} config/bootstrap.php.", 2);
}
}
+
+ public function migrationinstall(){
+ $this->installPath = $this->installPath ?: LITHIUM_APP_PATH . '/libraries';
+ $this->out('');
+ $this->out("Preparing to install Doctrine...", 2);
+ $this->out("Checking permissions on...");
+
+ }
}
?>
\ No newline at end of file
diff --git a/extensions/data/source/Doctrine.php b/extensions/data/source/Doctrine.php
index 510d592..229811a 100644
--- a/extensions/data/source/Doctrine.php
+++ b/extensions/data/source/Doctrine.php
@@ -44,7 +44,7 @@ class Doctrine extends \lithium\data\source\Database {
'proxy' => array(
'auto' => true,
'path' => LITHIUM_APP_PATH . '/resources/tmp/cache/Doctrine/Proxies',
- 'namespace' => 'app\resources\tmp\cache\Doctrine\Proxies'
+ 'namespace' => 'Doctrine\Proxies'
),
'useModelDriver' => true,
'mapping' => array('class' => null, 'path' => LITHIUM_APP_PATH . '/models'),
@@ -445,4 +445,4 @@ class Doctrine extends \lithium\data\source\Database {
}
}
-?>
\ No newline at end of file
+?>
diff --git a/readme.wiki b/readme.wiki
index 25c1a61..d1a2ae5 100644
--- a/readme.wiki
+++ b/readme.wiki
@@ -1,77 +1,50 @@
-## Work in progress
-=======
-#### Bootstrap
+## li3_doctrine: The Lithium + Doctrine Integration Project
-To start using li3_doctrine, you first have to import the doctrine ORM library
-into your lithium application, and then the li3_doctrine plugin.
+This plugin enables Lithium application developers to seamlessly implement all or part of their model layer using the [Doctrine Object-Relational Mapper](http://www.doctrine-project.org/).
-To do so, place the doctrine installation inside your `LITHIUM_LIBRARY_PATH`,
-and also the `li3_doctrine` directory. Then, add the following lines of code
-to your application's `config/bootstrap.php`:
+To install, simply do the following (change the direction of slashes as necessary):
{{{
-Libraries::add('Doctrine', array(
- 'path' => LITHIUM_LIBRARY_PATH . '/doctrine/DoctrineORM-2.0.0/Doctrine'
-));
-
-Libraries::add('plugin', array('li3_doctrine' => array('bootstrap' => true)));
+cd /path/to/your/app/libraries
+git clone code@dev.lithify.me:li3_doctrine.git
}}}
-#### Making a connection
-Connecting to a Doctrine managed backend is very easy. You can do so using the
-built-in Connections class provided by Lithium. Try using the following for
-your application's `config/connections.php`:
-{{{<?php
+Then, edit `app/config/bootstrap/libraries.php` and add the following:
-use \lithium\data\Connections;
+{{{ Libraries::add('li3_doctrine'); }}}
-Connections::add('default', 'Doctrine', array(
- 'driver' => 'pdo_mysql',
- 'host' => 'localhost',
- 'user' => 'root',
- 'password' => 'secret',
- 'dbname' => 'lithium'
-));
-
-?>}}}
+Now you're almost ready to go. The only thing remaining is to install doctrine itself. Assuming the `li3` command is in your system path, you can do the following:
-By default, your Doctrine proxy directory will be set to your application's
-`extensions/proxies` directory and your proxy namespace will be set to
-`\app\extensions\proxies`. To gain control over these configurations, you can
-get an instance to the `Doctrine\ORM\Configuration` class:
-{{{<?php
+{{{
+cd .. && li3 doctrine install
+}}}
-use \lithium\data\Connections;
+Finally, you must create a database connection with Doctrine. Edit `app/config/bootstrap/connections.php` and add the following:
-Connections::add('default', 'Doctrine', array(
+{{{
+Connections::add('default', array(
+ 'type' => 'doctrine',
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'root',
- 'password' => 'secret',
- 'dbname' => 'lithium',
- 'config' => function($config) {
- // $config is the Doctrine\ORM\Configuration instance that gets passed
- // to the soon-to-be created Doctrine\ORM\EntityManager.
- $config->setProxyDir('/path/to/proxies');
- $config->setProxyNamespace('\namespace\for\proxies');
- return $config;
- }
+ 'password' => 'password',
+ 'dbname' => 'blog_li3'
));
+}}}
-?>}}}
-To use Doctrine models in your app, add standard
+You can now use Doctrine models in your app, add standard
doctrine entities to the model directory, example:
{{{<?php
// app/models/User.php
namespace app\models;
-use \li3_doctrine\extensions\data\source\Doctrine;
+
/**
* @Entity
*/
-class User extends Doctrine
+class User
{
/**
* @Id
@@ -85,21 +58,11 @@ class User extends Doctrine
*/
protected $name;
- /**
- * Set name
- *
- * @param string $name
- */
public function setName($name)
{
$this->name = $name;
}
- /**
- * Get name
- *
- * @return string $name
- */
public function getName()
{
return $this->name;
@@ -109,13 +72,17 @@ class User extends Doctrine
?>}}}
-Then this can be model can be used and accessed from your controller in the following fashion.
+Then this can be model can be used and accessed from your controller in the following fashion:
-{{{$user = new User();
-$user->setName('Lithium Guy');
-$user->getEntityManager()->persist($user);
-$user->getEntityManager()->flush();}}}
+First be sure to include the relavant namespace and use statements
+{{{namespace app\controllers;
+use \app\models\User;
+use \lithium\data\Connections;}}}
-**Useful information:**
+Then inside your action methods you can use the following
-- [Read more about EntityManager](http://www.doctrine-project.org/documentation/manual/2_0/en/configuration#bootstrapping:obtaining-an-entitymanager)
+{{{$em = Connections::get('default')->getEntityManager();
+$user = new User();
+$user->setName('Lithium Guy');
+$em->persist($user);
+$em->flush();}}}