Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • ArrayHash
  • ArrayList
  • Callback
  • DateTime
  • Framework
  • FreezableObject
  • Image
  • Object
  • ObjectMixin

Interfaces

  • IFreezable

Exceptions

  • ArgumentOutOfRangeException
  • DeprecatedException
  • DirectoryNotFoundException
  • FatalErrorException
  • FileNotFoundException
  • InvalidArgumentException
  • InvalidStateException
  • IOException
  • MemberAccessException
  • NotImplementedException
  • NotSupportedException
  • OutOfRangeException
  • StaticClassException
  • UnexpectedValueException
  • UnknownImageFileException
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: namespace Nette;
 13: 
 14: use Nette;
 15: 
 16: 
 17: 
 18: /**
 19:  * PHP callback encapsulation.
 20:  *
 21:  * @author     David Grudl
 22:  * @property-read bool $callable
 23:  * @property-read string|array|\Closure $native
 24:  * @property-read bool $static
 25:  */
 26: final class Callback extends Object
 27: {
 28:     /** @var callable */
 29:     private $cb;
 30: 
 31: 
 32: 
 33:     /**
 34:      * Do not call directly, use callback() function.
 35:      * @param  callable
 36:      */
 37:     public function __construct($cb, $m = NULL)
 38:     {
 39:         if ($m !== NULL) {
 40:             $cb = array($cb, $m); // back-compatibility
 41:         }
 42:         if (!is_callable($cb, TRUE)) {
 43:             throw new InvalidArgumentException("Invalid callback.");
 44:         }
 45:         $this->cb = $cb;
 46:     }
 47: 
 48: 
 49: 
 50:     /**
 51:      * Invokes callback. Do not call directly.
 52:      * @return mixed
 53:      */
 54:     public function __invoke()
 55:     {
 56:         if (!is_callable($this->cb)) {
 57:             throw new InvalidStateException("Callback '$this' is not callable.");
 58:         }
 59:         $args = func_get_args();
 60:         return call_user_func_array($this->cb, $args);
 61:     }
 62: 
 63: 
 64: 
 65:     /**
 66:      * Invokes callback.
 67:      * @return mixed
 68:      */
 69:     public function invoke()
 70:     {
 71:         if (!is_callable($this->cb)) {
 72:             throw new InvalidStateException("Callback '$this' is not callable.");
 73:         }
 74:         $args = func_get_args();
 75:         return call_user_func_array($this->cb, $args);
 76:     }
 77: 
 78: 
 79: 
 80:     /**
 81:      * Invokes callback with an array of parameters.
 82:      * @param  array
 83:      * @return mixed
 84:      */
 85:     public function invokeArgs(array $args)
 86:     {
 87:         if (!is_callable($this->cb)) {
 88:             throw new InvalidStateException("Callback '$this' is not callable.");
 89:         }
 90:         return call_user_func_array($this->cb, $args);
 91:     }
 92: 
 93: 
 94: 
 95:     /**
 96:      * Verifies that callback can be called.
 97:      * @return bool
 98:      */
 99:     public function isCallable()
100:     {
101:         return is_callable($this->cb);
102:     }
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:     /**
118:      * Returns callback reflection.
119:      * @return Nette\Reflection\GlobalFunction|Nette\Reflection\Method
120:      */
121:     public function toReflection()
122:     {
123:         if (is_string($this->cb) && strpos($this->cb, '::')) {
124:             return new Nette\Reflection\Method($this->cb);
125:         } elseif (is_array($this->cb)) {
126:             return new Nette\Reflection\Method($this->cb[0], $this->cb[1]);
127:         } elseif (is_object($this->cb) && !$this->cb instanceof \Closure) {
128:             return new Nette\Reflection\Method($this->cb, '__invoke');
129:         } else {
130:             return new Nette\Reflection\GlobalFunction($this->cb);
131:         }
132:     }
133: 
134: 
135: 
136:     /**
137:      * @return bool
138:      */
139:     public function isStatic()
140:     {
141:         return is_array($this->cb) ? is_string($this->cb[0]) : is_string($this->cb);
142:     }
143: 
144: 
145: 
146:     /**
147:      * @return string
148:      */
149:     public function __toString()
150:     {
151:         if ($this->cb instanceof \Closure) {
152:             return '{closure}';
153:         } elseif (is_string($this->cb) && $this->cb[0] === "\0") {
154:             return '{lambda}';
155:         } else {
156:             is_callable($this->cb, TRUE, $textual);
157:             return $textual;
158:         }
159:     }
160: 
161: }
162: 
Nette Framework 2.0.3 API API documentation generated by ApiGen 2.7.0