Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • Callback
  • Configurator
  • Environment
  • Framework
  • FreezableObject
  • Object

Interfaces

  • IFreezable

Traits

  • SmartObject
  • StaticClass

Exceptions

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