| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfDoctrinePluginConfiguration extends sfPluginConfiguration |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* @see sfPluginConfiguration |
|---|
| 23 |
*/ |
|---|
| 24 |
public function initialize() |
|---|
| 25 |
{ |
|---|
| 26 |
sfConfig::set('sf_orm', 'doctrine'); |
|---|
| 27 |
|
|---|
| 28 |
if (!sfConfig::get('sf_admin_module_web_dir')) |
|---|
| 29 |
{ |
|---|
| 30 |
sfConfig::set('sf_admin_module_web_dir', '/sfDoctrinePlugin'); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
if (sfConfig::get('sf_web_debug')) |
|---|
| 34 |
{ |
|---|
| 35 |
require_once dirname(__FILE__).'/../lib/debug/sfWebDebugPanelDoctrine.class.php'; |
|---|
| 36 |
|
|---|
| 37 |
$this->dispatcher->connect('debug.web.load_panels', array('sfWebDebugPanelDoctrine', 'listenToAddPanelEvent')); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
if (!sfConfig::has('sf_doctrine_dir')) |
|---|
| 41 |
{ |
|---|
| 42 |
|
|---|
| 43 |
if (sfConfig::has('sfDoctrinePlugin_doctrine_lib_path')) |
|---|
| 44 |
{ |
|---|
| 45 |
sfConfig::set('sf_doctrine_dir', realpath(dirname(sfConfig::get('sfDoctrinePlugin_doctrine_lib_path')))); |
|---|
| 46 |
} |
|---|
| 47 |
else |
|---|
| 48 |
{ |
|---|
| 49 |
sfConfig::set('sf_doctrine_dir', realpath(dirname(__FILE__).'/../lib/vendor/doctrine')); |
|---|
| 50 |
} |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
if (!class_exists('Doctrine_Core', false)) |
|---|
| 54 |
{ |
|---|
| 55 |
require_once sfConfig::get('sf_doctrine_dir').'/Doctrine/Core.php'; |
|---|
| 56 |
} |
|---|
| 57 |
spl_autoload_register(array('Doctrine_Core', 'autoload')); |
|---|
| 58 |
|
|---|
| 59 |
$manager = Doctrine_Manager::getInstance(); |
|---|
| 60 |
$manager->setAttribute(Doctrine_Core::ATTR_EXPORT, Doctrine_Core::EXPORT_ALL); |
|---|
| 61 |
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_NONE); |
|---|
| 62 |
$manager->setAttribute(Doctrine_Core::ATTR_RECURSIVE_MERGE_FIXTURES, true); |
|---|
| 63 |
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true); |
|---|
| 64 |
$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true); |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
$manager->setDefaultAttributes(); |
|---|
| 68 |
|
|---|
| 69 |
if (method_exists($this->configuration, 'configureDoctrine')) |
|---|
| 70 |
{ |
|---|
| 71 |
$this->configuration->configureDoctrine($manager); |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
$this->dispatcher->notify(new sfEvent($manager, 'doctrine.configure')); |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
$this->dispatcher->connect('user.change_culture', array('sfDoctrineRecord', 'listenToChangeCultureEvent')); |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
* Returns options for the Doctrine schema builder. |
|---|
| 82 |
* |
|---|
| 83 |
* @return array |
|---|
| 84 |
*/ |
|---|
| 85 |
public function getModelBuilderOptions() |
|---|
| 86 |
{ |
|---|
| 87 |
$options = array( |
|---|
| 88 |
'generateBaseClasses' => true, |
|---|
| 89 |
'generateTableClasses' => true, |
|---|
| 90 |
'packagesPrefix' => 'Plugin', |
|---|
| 91 |
'suffix' => '.class.php', |
|---|
| 92 |
'baseClassesDirectory' => 'base', |
|---|
| 93 |
'baseClassName' => 'sfDoctrineRecord', |
|---|
| 94 |
); |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
$options = array_merge($options, sfConfig::get('doctrine_model_builder_options', array())); |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
$options = $this->dispatcher->filter(new sfEvent($this, 'doctrine.filter_model_builder_options'), $options)->getReturnValue(); |
|---|
| 101 |
|
|---|
| 102 |
return $options; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
* Returns a configuration array for the Doctrine CLI. |
|---|
| 107 |
* |
|---|
| 108 |
* @return array |
|---|
| 109 |
*/ |
|---|
| 110 |
public function getCliConfig() |
|---|
| 111 |
{ |
|---|
| 112 |
$config = array( |
|---|
| 113 |
'data_fixtures_path' => array_merge(array(sfConfig::get('sf_data_dir').'/fixtures'), $this->configuration->getPluginSubPaths('/data/fixtures')), |
|---|
| 114 |
'models_path' => sfConfig::get('sf_lib_dir').'/model/doctrine', |
|---|
| 115 |
'migrations_path' => sfConfig::get('sf_lib_dir').'/migration/doctrine', |
|---|
| 116 |
'sql_path' => sfConfig::get('sf_data_dir').'/sql', |
|---|
| 117 |
'yaml_schema_path' => sfConfig::get('sf_config_dir').'/doctrine', |
|---|
| 118 |
); |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
$config = $this->dispatcher->filter(new sfEvent($this, 'doctrine.filter_cli_config'), $config)->getReturnValue(); |
|---|
| 122 |
|
|---|
| 123 |
return $config; |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|