| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfPropelBehavior |
|---|
| 20 |
{ |
|---|
| 21 |
static protected |
|---|
| 22 |
$loaded = array(), |
|---|
| 23 |
$behaviors = array(); |
|---|
| 24 |
|
|---|
| 25 |
static public function registerMethods($name, $callables) |
|---|
| 26 |
{ |
|---|
| 27 |
if (!isset(self::$behaviors[$name])) |
|---|
| 28 |
{ |
|---|
| 29 |
self::$behaviors[$name] = array('methods' => array(), 'hooks' => array()); |
|---|
| 30 |
} |
|---|
| 31 |
foreach ($callables as $callable) |
|---|
| 32 |
{ |
|---|
| 33 |
self::$behaviors[$name]['methods'][] = $callable; |
|---|
| 34 |
} |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
static public function registerHooks($name, $hooks) |
|---|
| 38 |
{ |
|---|
| 39 |
if (!isset(self::$behaviors[$name])) |
|---|
| 40 |
{ |
|---|
| 41 |
self::$behaviors[$name] = array('methods' => array(), 'hooks' => array()); |
|---|
| 42 |
} |
|---|
| 43 |
foreach ($hooks as $hook => $callable) |
|---|
| 44 |
{ |
|---|
| 45 |
if (!isset(self::$behaviors[$name]['hooks'])) |
|---|
| 46 |
{ |
|---|
| 47 |
self::$behaviors[$name]['hooks'][$hook] = array(); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
self::$behaviors[$name]['hooks'][$hook][] = $callable; |
|---|
| 51 |
} |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
static public function add($class, $behaviors) |
|---|
| 55 |
{ |
|---|
| 56 |
foreach ($behaviors as $name => $parameters) |
|---|
| 57 |
{ |
|---|
| 58 |
if (is_int($name)) |
|---|
| 59 |
{ |
|---|
| 60 |
|
|---|
| 61 |
$name = $parameters; |
|---|
| 62 |
} |
|---|
| 63 |
else |
|---|
| 64 |
{ |
|---|
| 65 |
|
|---|
| 66 |
foreach ($parameters as $key => $value) |
|---|
| 67 |
{ |
|---|
| 68 |
sfConfig::set('propel_behavior_'.$name.'_'.$class.'_'.$key, $value); |
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
if (!isset(self::$behaviors[$name])) |
|---|
| 73 |
{ |
|---|
| 74 |
throw new sfConfigurationException(sprintf('Propel behavior "%s" is not registered', $name)); |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
foreach (self::$behaviors[$name]['hooks'] as $hook => $callables) |
|---|
| 79 |
{ |
|---|
| 80 |
foreach ($callables as $callable) |
|---|
| 81 |
{ |
|---|
| 82 |
$key = 'Base'.$class.$hook.'//'.self::callableToString($callable); |
|---|
| 83 |
if (!isset(self::$loaded[$key])) |
|---|
| 84 |
{ |
|---|
| 85 |
sfMixer::register('Base'.$class.$hook, $callable); |
|---|
| 86 |
self::$loaded[$key] = true; |
|---|
| 87 |
} |
|---|
| 88 |
} |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
foreach (self::$behaviors[$name]['methods'] as $callable) |
|---|
| 93 |
{ |
|---|
| 94 |
$key = 'Base'.$class.'//'.self::callableToString($callable); |
|---|
| 95 |
if (!isset(self::$loaded[$key])) |
|---|
| 96 |
{ |
|---|
| 97 |
sfMixer::register('Base'.$class, $callable); |
|---|
| 98 |
self::$loaded[$key] = true; |
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
static protected function callableToString($callable) |
|---|
| 105 |
{ |
|---|
| 106 |
return is_array($callable) ? (is_object($callable[0]) ? get_class($callable[0]) : $callable[0]).'::'.$callable[1] : var_export($callable, true); |
|---|
| 107 |
} |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|