From 657d656614566d6b6e9db49fc4b73347dea53ba8 Mon Sep 17 00:00:00 2001 From: zYne <zYne@625475ce-881a-0410-a577-b389adb331d8> Date: Sat, 13 Oct 2007 09:01:03 +0000 Subject: [PATCH] refactored plugins --- lib/Doctrine/AuditLog.php | 10 ++++------ lib/Doctrine/I18n.php | 7 +------ lib/Doctrine/Plugin.php | 23 +++++++++++++++++++++-- lib/Doctrine/Search.php | 34 +++------------------------------- 4 files changed, 29 insertions(+), 45 deletions(-) diff --git a/lib/Doctrine/AuditLog.php b/lib/Doctrine/AuditLog.php index 2f421df1c..a64cf2746 100644 --- a/lib/Doctrine/AuditLog.php +++ b/lib/Doctrine/AuditLog.php @@ -36,6 +36,7 @@ class Doctrine_AuditLog extends Doctrine_Plugin 'versionColumn' => 'version', 'generateFiles' => false, 'table' => false, + 'pluginTable' => false, ); protected $_auditTable; @@ -96,13 +97,10 @@ class Doctrine_AuditLog extends Doctrine_Plugin $options = array('className' => $className); - $builder = new Doctrine_Import_Builder(); + $this->generateDefinition($options, $columns, array()); + + $this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']); - $def = $builder->buildDefinition($options, $columns); - - if ( ! $this->_options['generateFiles']) { - eval($def); - } return true; } } diff --git a/lib/Doctrine/I18n.php b/lib/Doctrine/I18n.php index 08beab164..1cdd6dc1a 100644 --- a/lib/Doctrine/I18n.php +++ b/lib/Doctrine/I18n.php @@ -106,13 +106,8 @@ class Doctrine_I18n extends Doctrine_Plugin $options = array('className' => $this->_options['className'], 'queryParts' => array('indexBy' => 'lang')); - $builder = new Doctrine_Import_Builder(); + $this->generateClass($options, $columns, $relations); - $def = $builder->buildDefinition($options, $columns, $relations); - - if ( ! $this->_options['generateFiles']) { - eval($def); - } $this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']); $this->_options['pluginTable']->bindQueryPart('indexBy', 'lang'); diff --git a/lib/Doctrine/Plugin.php b/lib/Doctrine/Plugin.php index 453db1d0e..787b5d619 100644 --- a/lib/Doctrine/Plugin.php +++ b/lib/Doctrine/Plugin.php @@ -35,7 +35,7 @@ class Doctrine_Plugin /** * @var array $_options an array of plugin specific options */ - protected $_options = array(); + protected $_options = array('generateFiles' => false); /** * __get * an alias for getOption @@ -98,4 +98,23 @@ class Doctrine_Plugin { return $this->_options; } -} \ No newline at end of file + + public function generateClass($options, $columns, $relations) + { + $builder = new Doctrine_Import_Builder(); + + if ($this->_options['generateFiles']) { + if (isset($this->_options['generatePath']) && $this->_options['generatePath']) { + $builder->setTargetPath($this->_options['generatePath']); + + $builder->buildRecord($options, $columns, $relations); + } else { + throw new Doctrine_Plugin_Exception('If you wish to generate files then you must specify the path to generate the files in.'); + } + } else { + $def = $builder->buildDefinition($options, $columns, $relations); + + eval($def); + } + } +} diff --git a/lib/Doctrine/Search.php b/lib/Doctrine/Search.php index 4f7326725..77f4139b2 100644 --- a/lib/Doctrine/Search.php +++ b/lib/Doctrine/Search.php @@ -30,7 +30,7 @@ * @link www.phpdoctrine.com * @since 1.0 */ -class Doctrine_Search +class Doctrine_Search extends Doctrine_Plugin { protected $_options = array('generateFiles' => false, 'className' => '%CLASS%Index', @@ -48,26 +48,12 @@ class Doctrine_Search } } - public function getOption($option) - { - if (isset($this->_options[$option])) { - return $this->_options[$option]; - } - - throw new Doctrine_Search_Exception('Unknown option ' . $option); - } public function analyze($text) { return $this->_options['analyzer']->analyze($text); } - public function setOption($option, $value) - { - $this->_options[$option] = $value; - - return $this; - } /** * updateIndex * updates the index @@ -198,22 +184,8 @@ class Doctrine_Search $columns += $fk; - - $builder = new Doctrine_Import_Builder(); - - if ($this->_options['generateFiles']) { - if (isset($this->_options['generatePath']) && $this->_options['generatePath']) { - $builder->setTargetPath($this->_options['generatePath']); - - $builder->buildRecord($options, $columns, $relations); - } else { - throw new Doctrine_Search_Exception('If you wish to generate files then you must specify the path to generate the files in.'); - } - } else { - $def = $builder->buildDefinition($options, $columns, $relations); - - eval($def); - } + + $this->generateClass($options, $columns, $relations); $this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']);