| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfPropel |
|---|
| 20 |
{ |
|---|
| 21 |
static protected |
|---|
| 22 |
$initialized = false, |
|---|
| 23 |
$defaultCulture = 'en'; |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
* Initialize sfymfony propel |
|---|
| 27 |
* |
|---|
| 28 |
* @param sfEventDispatcher $dispatcher |
|---|
| 29 |
* @param string $culture |
|---|
| 30 |
*/ |
|---|
| 31 |
static public function initialize(sfEventDispatcher $dispatcher, $culture = null) |
|---|
| 32 |
{ |
|---|
| 33 |
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) |
|---|
| 34 |
{ |
|---|
| 35 |
|
|---|
| 36 |
Propel::setLogger(new sfPropelLogger($dispatcher)); |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
$configuration = sfPropelDatabase::getConfiguration(); |
|---|
| 41 |
if($configuration) |
|---|
| 42 |
{ |
|---|
| 43 |
Propel::setConfiguration($configuration); |
|---|
| 44 |
|
|---|
| 45 |
if(!Propel::isInit()) |
|---|
| 46 |
{ |
|---|
| 47 |
Propel::initialize(); |
|---|
| 48 |
} |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
$dispatcher->connect('user.change_culture', array('sfPropel', 'listenToChangeCultureEvent')); |
|---|
| 52 |
|
|---|
| 53 |
if (!is_null($culture)) |
|---|
| 54 |
{ |
|---|
| 55 |
self::setDefaultCulture($culture); |
|---|
| 56 |
} |
|---|
| 57 |
else if (class_exists('sfContext', false) && sfContext::hasInstance() && $user = sfContext::getInstance()->getUser()) |
|---|
| 58 |
{ |
|---|
| 59 |
self::setDefaultCulture($user->getCulture()); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
self::$initialized = true; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
* Sets the default culture |
|---|
| 67 |
* |
|---|
| 68 |
* @param string $culture |
|---|
| 69 |
*/ |
|---|
| 70 |
static public function setDefaultCulture($culture) |
|---|
| 71 |
{ |
|---|
| 72 |
self::$defaultCulture = $culture; |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
* Return the default culture |
|---|
| 77 |
* |
|---|
| 78 |
* @return string the default culture |
|---|
| 79 |
*/ |
|---|
| 80 |
static public function getDefaultCulture() |
|---|
| 81 |
{ |
|---|
| 82 |
if (!self::$initialized && class_exists('sfProjectConfiguration', false)) |
|---|
| 83 |
{ |
|---|
| 84 |
self::initialize(sfProjectConfiguration::getActive()->getEventDispatcher()); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
return self::$defaultCulture; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
* Listens to the user.change_culture event. |
|---|
| 92 |
* |
|---|
| 93 |
* @param sfEvent An sfEvent instance |
|---|
| 94 |
* |
|---|
| 95 |
*/ |
|---|
| 96 |
static public function listenToChangeCultureEvent(sfEvent $event) |
|---|
| 97 |
{ |
|---|
| 98 |
self::setDefaultCulture($event['culture']); |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
* Include once a file specified in DOT notation and return unqualified classname. |
|---|
| 103 |
* |
|---|
| 104 |
* This method is the same as in Propel::import(). |
|---|
| 105 |
* The only difference is that this one takes the autoloading into account. |
|---|
| 106 |
* |
|---|
| 107 |
* @see Propel::import() |
|---|
| 108 |
*/ |
|---|
| 109 |
public static function import($path) |
|---|
| 110 |
{ |
|---|
| 111 |
|
|---|
| 112 |
if (($pos = strrpos($path, '.')) === false) |
|---|
| 113 |
{ |
|---|
| 114 |
$class = $path; |
|---|
| 115 |
} |
|---|
| 116 |
else |
|---|
| 117 |
{ |
|---|
| 118 |
$class = substr($path, $pos + 1); |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
if (class_exists($class, true)) |
|---|
| 123 |
{ |
|---|
| 124 |
return $class; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
$path = strtr($path, '.', DIRECTORY_SEPARATOR).'.php'; |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
$ret = include_once($path); |
|---|
| 132 |
if ($ret === false) |
|---|
| 133 |
{ |
|---|
| 134 |
throw new PropelException("Unable to import class: ".$class." from ".$path); |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
return $class; |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
* Clears all instance pools. |
|---|
| 143 |
*/ |
|---|
| 144 |
static public function clearAllInstancePools() |
|---|
| 145 |
{ |
|---|
| 146 |
$files = sfFinder::type('file')->name('*MapBuilder.php')->in(sfProjectConfiguration::getActive()->getModelDirs()); |
|---|
| 147 |
foreach ($files as $file) |
|---|
| 148 |
{ |
|---|
| 149 |
$omClass = basename($file, 'MapBuilder.php'); |
|---|
| 150 |
if (class_exists($omClass) && is_subclass_of($omClass, 'BaseObject')) |
|---|
| 151 |
{ |
|---|
| 152 |
$peer = constant($omClass.'::PEER'); |
|---|
| 153 |
call_user_func(array($peer, 'clearInstancePool')); |
|---|
| 154 |
} |
|---|
| 155 |
} |
|---|
| 156 |
} |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|