/usr/share/php/Nette/deprecated/Callback.php is in php-nette 2.4-20160731-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | <?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
namespace Nette;
use Nette;
/**
* @deprecated
*/
class Callback extends Object
{
/** @var callable */
private $cb;
/**
* Factory. Workaround for missing (new Callback)->invoke() in PHP 5.3.
* @param mixed class, object, callable
* @param string method
* @return Callback
*/
public static function create($callback, $m = NULL)
{
return new self($callback, $m);
}
/**
* @param mixed class, object, callable
* @param string method
*/
public function __construct($cb, $m = NULL)
{
trigger_error(__CLASS__ . ' is deprecated.', E_USER_DEPRECATED);
if ($m !== NULL) {
$cb = array($cb, $m);
} elseif ($cb instanceof self) { // prevents wrapping itself
$this->cb = $cb->cb;
return;
}
if (!is_callable($cb, TRUE)) {
throw new InvalidArgumentException('Invalid callback.');
}
$this->cb = $cb;
}
/**
* Invokes callback. Do not call directly.
* @return mixed
*/
public function __invoke()
{
if (!is_callable($this->cb)) {
throw new InvalidStateException("Callback '$this' is not callable.");
}
return call_user_func_array($this->cb, func_get_args());
}
/**
* Invokes callback.
* @return mixed
*/
public function invoke()
{
if (!is_callable($this->cb)) {
throw new InvalidStateException("Callback '$this' is not callable.");
}
return call_user_func_array($this->cb, func_get_args());
}
/**
* Invokes callback with an array of parameters.
* @param array
* @return mixed
*/
public function invokeArgs(array $args)
{
if (!is_callable($this->cb)) {
throw new InvalidStateException("Callback '$this' is not callable.");
}
return call_user_func_array($this->cb, $args);
}
/**
* Verifies that callback can be called.
* @return bool
*/
public function isCallable()
{
return is_callable($this->cb);
}
/**
* Returns PHP callback pseudotype.
* @return string|array|\Closure
*/
public function getNative()
{
return $this->cb;
}
/**
* Returns callback reflection.
* @return Nette\Reflection\GlobalFunction|Nette\Reflection\Method
*/
public function toReflection()
{
if (is_string($this->cb) && strpos($this->cb, '::')) {
return new Nette\Reflection\Method($this->cb);
} elseif (is_array($this->cb)) {
return new Nette\Reflection\Method($this->cb[0], $this->cb[1]);
} elseif (is_object($this->cb) && !$this->cb instanceof \Closure) {
return new Nette\Reflection\Method($this->cb, '__invoke');
} else {
return new Nette\Reflection\GlobalFunction($this->cb);
}
}
/**
* @return bool
*/
public function isStatic()
{
return is_array($this->cb) ? is_string($this->cb[0]) : is_string($this->cb);
}
/**
* Duplicates the callback with a new bound object.
* @return Callback
*/
public function bindTo($newthis)
{
if (is_string($this->cb) && strpos($this->cb, '::')) {
$this->cb = explode('::', $this->cb);
} elseif (!is_array($this->cb)) {
throw new InvalidStateException("Callback '$this' have not any bound object.");
}
return new static($newthis, $this->cb[1]);
}
/**
* @return string
*/
public function __toString()
{
if ($this->cb instanceof \Closure) {
return '{closure}';
} elseif (is_string($this->cb) && $this->cb[0] === "\0") {
return '{lambda}';
} else {
is_callable($this->cb, TRUE, $textual);
return $textual;
}
}
}
|