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