| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the symfony package.
|
|
|
5 |
* (c) Jonathan H. Wage <jonwage@gmail.com>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* sfDoctrinePluginConfiguration Class
|
|
|
13 |
*
|
|
|
14 |
* @package symfony
|
|
|
15 |
* @subpackage doctrine
|
|
|
16 |
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
|
17 |
* @version SVN: $Id: sfDoctrinePluginConfiguration.class.php 30445 2010-07-28 04:37:32Z Kris.Wallsmith $
|
|
|
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 (!class_exists('Doctrine_Core', false))
|
|
|
41 |
{
|
|
|
42 |
require_once sfConfig::get('sf_doctrine_dir', realpath(dirname(__FILE__).'/../lib/vendor/doctrine')).'/Doctrine/Core.php';
|
|
|
43 |
}
|
|
|
44 |
spl_autoload_register(array('Doctrine_Core', 'autoload'));
|
|
|
45 |
|
|
|
46 |
$manager = Doctrine_Manager::getInstance();
|
|
|
47 |
$manager->setAttribute(Doctrine_Core::ATTR_EXPORT, Doctrine_Core::EXPORT_ALL);
|
|
|
48 |
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_NONE);
|
|
|
49 |
$manager->setAttribute(Doctrine_Core::ATTR_RECURSIVE_MERGE_FIXTURES, true);
|
|
|
50 |
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
|
|
|
51 |
$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
|
|
|
52 |
|
|
|
53 |
// apply default attributes
|
|
|
54 |
$manager->setDefaultAttributes();
|
|
|
55 |
|
|
|
56 |
if (method_exists($this->configuration, 'configureDoctrine'))
|
|
|
57 |
{
|
|
|
58 |
$this->configuration->configureDoctrine($manager);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
$this->dispatcher->notify(new sfEvent($manager, 'doctrine.configure'));
|
|
|
62 |
|
|
|
63 |
// make sure the culture is intercepted
|
|
|
64 |
$this->dispatcher->connect('user.change_culture', array('sfDoctrineRecord', 'listenToChangeCultureEvent'));
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Returns options for the Doctrine schema builder.
|
|
|
69 |
*
|
|
|
70 |
* @return array
|
|
|
71 |
*/
|
|
|
72 |
public function getModelBuilderOptions()
|
|
|
73 |
{
|
|
|
74 |
$options = array(
|
|
|
75 |
'generateBaseClasses' => true,
|
|
|
76 |
'generateTableClasses' => true,
|
|
|
77 |
'packagesPrefix' => 'Plugin',
|
|
|
78 |
'suffix' => '.class.php',
|
|
|
79 |
'baseClassesDirectory' => 'base',
|
|
|
80 |
'baseClassName' => 'sfDoctrineRecord',
|
|
|
81 |
);
|
|
|
82 |
|
|
|
83 |
// for BC
|
|
|
84 |
$options = array_merge($options, sfConfig::get('doctrine_model_builder_options', array()));
|
|
|
85 |
|
|
|
86 |
// filter options through the dispatcher
|
|
|
87 |
$options = $this->dispatcher->filter(new sfEvent($this, 'doctrine.filter_model_builder_options'), $options)->getReturnValue();
|
|
|
88 |
|
|
|
89 |
return $options;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
* Returns a configuration array for the Doctrine CLI.
|
|
|
94 |
*
|
|
|
95 |
* @return array
|
|
|
96 |
*/
|
|
|
97 |
public function getCliConfig()
|
|
|
98 |
{
|
|
|
99 |
$config = array(
|
|
|
100 |
'data_fixtures_path' => array_merge(array(sfConfig::get('sf_data_dir').'/fixtures'), $this->configuration->getPluginSubPaths('/data/fixtures')),
|
|
|
101 |
'models_path' => sfConfig::get('sf_lib_dir').'/model/doctrine',
|
|
|
102 |
'migrations_path' => sfConfig::get('sf_lib_dir').'/migration/doctrine',
|
|
|
103 |
'sql_path' => sfConfig::get('sf_data_dir').'/sql',
|
|
|
104 |
'yaml_schema_path' => sfConfig::get('sf_config_dir').'/doctrine',
|
|
|
105 |
);
|
|
|
106 |
|
|
|
107 |
// filter config through the dispatcher
|
|
|
108 |
$config = $this->dispatcher->filter(new sfEvent($this, 'doctrine.filter_cli_config'), $config)->getReturnValue();
|
|
|
109 |
|
|
|
110 |
return $config;
|
|
|
111 |
}
|
|
|
112 |
}
|