refactored plugins
This commit is contained in:
parent
780c0deb1b
commit
657d656614
@ -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());
|
||||||
|
|
||||||
|
$this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']);
|
||||||
|
|
||||||
$def = $builder->buildDefinition($options, $columns);
|
|
||||||
|
|
||||||
if ( ! $this->_options['generateFiles']) {
|
|
||||||
eval($def);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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');
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -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
|
||||||
@ -198,22 +184,8 @@ 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']);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user