Development

/branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/sfPropel.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/sfPropel.class.php

Revision 10328, 2.4 kB (checked in by fabien, 6 years ago)

fixed plugin model overriding (closes #3227)

  • Property svn:mime-type set to text/x-php
  • 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) Fabien Potencier <fabien.potencier@symfony-project.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  * @package    symfony
13  * @subpackage propel
14  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
15  * @version    SVN: $Id$
16  */
17 class sfPropel
18 {
19   static protected
20     $initialized    = false,
21     $defaultCulture = 'en';
22
23   static public function initialize(sfEventDispatcher $dispatcher, $culture = null)
24   {
25     $dispatcher->connect('user.change_culture', array('sfPropel', 'listenToChangeCultureEvent'));
26
27     if (!is_null($culture))
28     {
29       self::setDefaultCulture($culture);
30     }
31     else if (class_exists('sfContext', false) && sfContext::hasInstance() && $user = sfContext::getInstance()->getUser())
32     {
33       self::setDefaultCulture($user->getCulture());
34     }
35
36     self::$initialized = true;
37   }
38
39   static public function setDefaultCulture($culture)
40   {
41     self::$defaultCulture = $culture;
42   }
43
44   static public function getDefaultCulture()
45   {
46     if (!self::$initialized && class_exists('sfProjectConfiguration', false))
47     {
48       self::initialize(sfProjectConfiguration::getActive()->getEventDispatcher());
49     }
50
51     return self::$defaultCulture;
52   }
53
54   /**
55    * Listens to the user.change_culture event.
56    *
57    * @param sfEvent An sfEvent instance
58    *
59    */
60   static public function listenToChangeCultureEvent(sfEvent $event)
61   {
62     self::setDefaultCulture($event['culture']);
63   }
64
65   /**
66    * Include once a file specified in DOT notation and return unqualified classname.
67    *
68    * This method is the same as in Propel::import().
69    * The only difference is that this one takes the autoloading into account.
70    *
71    * @see Propel::import()
72    */
73   public static function import($path)
74   {
75     // extract classname
76     if (($pos = strrpos($path, '.')) === false)
77     {
78       $class = $path;
79     }
80     else
81     {
82       $class = substr($path, $pos + 1);
83     }
84
85     // check if class exists
86     if (class_exists($class, true))
87     {
88       return $class;
89     }
90
91     // turn to filesystem path
92     $path = strtr($path, '.', DIRECTORY_SEPARATOR).'.php';
93
94     // include class
95     $ret = include_once($path);
96     if ($ret === false)
97     {
98       throw new PropelException("Unable to import class: ".$class." from ".$path);
99     }
100
101     // return qualified name
102     return $class;
103   }
104 }
105
Note: See TracBrowser for help on using the browser.