|
Revision 11534, 1.7 kB
(checked in by fabien, 5 years ago)
|
[1.1, 1.2] fixed sfCallable error message when you pass an object as a callable
|
- 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 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfCallable |
|---|
| 20 |
{ |
|---|
| 21 |
protected |
|---|
| 22 |
$callable = null; |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
* Constructor. |
|---|
| 26 |
* |
|---|
| 27 |
* @param mixed $callable A valid PHP callable (must be valid when calling the call() method) |
|---|
| 28 |
*/ |
|---|
| 29 |
public function __construct($callable) |
|---|
| 30 |
{ |
|---|
| 31 |
$this->callable = $callable; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
* Returns the current callable. |
|---|
| 36 |
* |
|---|
| 37 |
* @param mixed The current callable |
|---|
| 38 |
*/ |
|---|
| 39 |
public function getCallable() |
|---|
| 40 |
{ |
|---|
| 41 |
return $this->callable; |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
* Calls the current callable with the given arguments. |
|---|
| 46 |
* |
|---|
| 47 |
* The callable is called with the arguments given to this method. |
|---|
| 48 |
* |
|---|
| 49 |
* This method throws an exception if the callable is not valid. |
|---|
| 50 |
* This check is not done during the object construction to allow |
|---|
| 51 |
* you to load the callable as late as possible. |
|---|
| 52 |
*/ |
|---|
| 53 |
public function call() |
|---|
| 54 |
{ |
|---|
| 55 |
if (!is_callable($this->callable)) |
|---|
| 56 |
{ |
|---|
| 57 |
throw new sfException(sprintf('"%s" is not a valid callable.', is_array($this->callable) ? sprintf('%s:%s', is_object($this->callable[0]) ? get_class($this->callable[0]) : $this->callable[0], $this->callable[1]) : (is_object($this->callable) ? sprintf('Object(%s)', get_class($this->callable)) : var_export($this->callable, true)))); |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
$arguments = func_get_args(); |
|---|
| 61 |
|
|---|
| 62 |
return call_user_func_array($this->callable, $arguments); |
|---|
| 63 |
} |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|