| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the symfony package.
|
|
|
5 |
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* sfCallable represents a PHP callable.
|
|
|
13 |
*
|
|
|
14 |
* @package symfony
|
|
|
15 |
* @subpackage util
|
|
|
16 |
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
17 |
* @version SVN: $Id: sfCallable.class.php 21875 2009-09-11 05:54:39Z fabien $
|
|
|
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 |
* @return 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 |
}
|