Development

/branches/1.3/lib/plugins/sfDoctrinePlugin/config/sfDoctrinePluginConfiguration.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/plugins/sfDoctrinePlugin/config/sfDoctrinePluginConfiguration.class.php

Revision 30445, 3.9 kB (checked in by Kris.Wallsmith, 4 years ago)

[1.3, 1.4] added a check whether doctrine is already loaded to allow use of a compiled core (closes #8917, thanks gnukix)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
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$
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       // for BC
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     // apply default attributes
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     // make sure the culture is intercepted
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     // for BC
97     $options = array_merge($options, sfConfig::get('doctrine_model_builder_options', array()));
98
99     // filter options through the dispatcher
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     // filter config through the dispatcher
121     $config = $this->dispatcher->filter(new sfEvent($this, 'doctrine.filter_cli_config'), $config)->getReturnValue();
122
123     return $config;
124   }
125 }
126
Note: See TracBrowser for help on using the browser.