1
0
mirror of synced 2025-02-07 15:59:27 +03:00

refactored plugins

This commit is contained in:
zYne 2007-10-13 09:01:03 +00:00
parent 780c0deb1b
commit 657d656614
4 changed files with 29 additions and 45 deletions

View File

@ -36,6 +36,7 @@ class Doctrine_AuditLog extends Doctrine_Plugin
'versionColumn' => 'version', 'versionColumn' => 'version',
'generateFiles' => false, 'generateFiles' => false,
'table' => false, 'table' => false,
'pluginTable' => false,
); );
protected $_auditTable; protected $_auditTable;
@ -96,13 +97,10 @@ class Doctrine_AuditLog extends Doctrine_Plugin
$options = array('className' => $className); $options = array('className' => $className);
$builder = new Doctrine_Import_Builder(); $this->generateDefinition($options, $columns, array());
$def = $builder->buildDefinition($options, $columns); $this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']);
if ( ! $this->_options['generateFiles']) {
eval($def);
}
return true; return true;
} }
} }

View File

@ -106,13 +106,8 @@ class Doctrine_I18n extends Doctrine_Plugin
$options = array('className' => $this->_options['className'], $options = array('className' => $this->_options['className'],
'queryParts' => array('indexBy' => 'lang')); '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'] = $table->getConnection()->getTable($this->_options['className']);
$this->_options['pluginTable']->bindQueryPart('indexBy', 'lang'); $this->_options['pluginTable']->bindQueryPart('indexBy', 'lang');

View File

@ -35,7 +35,7 @@ class Doctrine_Plugin
/** /**
* @var array $_options an array of plugin specific options * @var array $_options an array of plugin specific options
*/ */
protected $_options = array(); protected $_options = array('generateFiles' => false);
/** /**
* __get * __get
* an alias for getOption * an alias for getOption
@ -98,4 +98,23 @@ class Doctrine_Plugin
{ {
return $this->_options; return $this->_options;
} }
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);
}
}
} }

View File

@ -30,7 +30,7 @@
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Search class Doctrine_Search extends Doctrine_Plugin
{ {
protected $_options = array('generateFiles' => false, protected $_options = array('generateFiles' => false,
'className' => '%CLASS%Index', '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) public function analyze($text)
{ {
return $this->_options['analyzer']->analyze($text); return $this->_options['analyzer']->analyze($text);
} }
public function setOption($option, $value)
{
$this->_options[$option] = $value;
return $this;
}
/** /**
* updateIndex * updateIndex
* updates the index * updates the index
@ -199,21 +185,7 @@ class Doctrine_Search
$columns += $fk; $columns += $fk;
$builder = new Doctrine_Import_Builder(); $this->generateClass($options, $columns, $relations);
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->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']); $this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']);