| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
class sfFunctionCache extends sfFileCache |
|---|
| 25 |
{ |
|---|
| 26 |
|
|---|
| 27 |
* Calls a cacheable function or method (or not if there is already a cache for it). |
|---|
| 28 |
* |
|---|
| 29 |
* Arguments of this method are read with func_get_args. So it doesn't appear in the function definition. Synopsis : |
|---|
| 30 |
* call('functionName', $arg1, $arg2, ...) |
|---|
| 31 |
* (arg1, arg2... are arguments of 'functionName') |
|---|
| 32 |
* |
|---|
| 33 |
* @return mixed The result of the function/method |
|---|
| 34 |
*/ |
|---|
| 35 |
public function call() |
|---|
| 36 |
{ |
|---|
| 37 |
$arguments = func_get_args(); |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
$id = md5(serialize($arguments)); |
|---|
| 41 |
|
|---|
| 42 |
$data = $this->get($id); |
|---|
| 43 |
if ($data !== null) |
|---|
| 44 |
{ |
|---|
| 45 |
$array = unserialize($data); |
|---|
| 46 |
$output = $array['output']; |
|---|
| 47 |
$result = $array['result']; |
|---|
| 48 |
} |
|---|
| 49 |
else |
|---|
| 50 |
{ |
|---|
| 51 |
$target = array_shift($arguments); |
|---|
| 52 |
ob_start(); |
|---|
| 53 |
ob_implicit_flush(false); |
|---|
| 54 |
if (is_string($target) && strstr($target, '::')) |
|---|
| 55 |
{ |
|---|
| 56 |
|
|---|
| 57 |
list($class, $method) = explode('::', $target); |
|---|
| 58 |
try |
|---|
| 59 |
{ |
|---|
| 60 |
class_exists($class); |
|---|
| 61 |
$result = call_user_func_array(array($class, $method), $arguments); |
|---|
| 62 |
} |
|---|
| 63 |
catch (Exception $e) |
|---|
| 64 |
{ |
|---|
| 65 |
ob_end_clean(); |
|---|
| 66 |
throw $e; |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
else if (is_string($target) && strstr($target, '->')) |
|---|
| 70 |
{ |
|---|
| 71 |
|
|---|
| 72 |
// use a stupid name ($objet_123456789 because) of problems when the object |
|---|
| 73 |
// name is the same as this var name |
|---|
| 74 |
list($object_123456789, $method) = explode('->', $target); |
|---|
| 75 |
global $$object_123456789; |
|---|
| 76 |
try |
|---|
| 77 |
{ |
|---|
| 78 |
$result = call_user_func_array(array($$object_123456789, $method), $arguments); |
|---|
| 79 |
} |
|---|
| 80 |
catch (Exception $e) |
|---|
| 81 |
{ |
|---|
| 82 |
ob_end_clean(); |
|---|
| 83 |
throw $e; |
|---|
| 84 |
} |
|---|
| 85 |
} |
|---|
| 86 |
else |
|---|
| 87 |
{ |
|---|
| 88 |
|
|---|
| 89 |
$result = call_user_func_array($target, $arguments); |
|---|
| 90 |
} |
|---|
| 91 |
$output = ob_get_contents(); |
|---|
| 92 |
ob_end_clean(); |
|---|
| 93 |
|
|---|
| 94 |
$array['output'] = $output; |
|---|
| 95 |
$array['result'] = $result; |
|---|
| 96 |
|
|---|
| 97 |
$this->set($id, '', serialize($array)); |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
echo($output); |
|---|
| 101 |
return $result; |
|---|
| 102 |
} |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|