Packages

  • 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
  • DateTime53
  • Framework
  • FreezableObject
  • Image
  • Object
  • ObjectMixin

Interfaces

  • IFreezable

Exceptions

  • ArgumentOutOfRangeException
  • DeprecatedException
  • DirectoryNotFoundException
  • FatalErrorException
  • FileNotFoundException
  • InvalidStateException
  • IOException
  • MemberAccessException
  • NotImplementedException
  • NotSupportedException
  • StaticClassException
  • UnknownImageFileException
  • Overview
  • Package
  • 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:  * @package Nette
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * PHP callback encapsulation.
 17:  *
 18:  * @author     David Grudl
 19:  * @property-read bool $callable
 20:  * @property-read string|array|Closure $native
 21:  * @property-read bool $static
 22:  * @package Nette
 23:  */
 24: final class Callback extends Object
 25: {
 26:     /** @var string|array|Closure */
 27:     private $cb;
 28: 
 29: 
 30: 
 31:     /**
 32:      * Do not call directly, use callback() function.
 33:      * @param  mixed   class, object, function, callback
 34:      * @param  string  method
 35:      */
 36:     public function __construct($t, $m = NULL)
 37:     {
 38:         if ($m === NULL) {
 39:             if (is_string($t)) {
 40:                 $t = explode('::', $t, 2);
 41:                 $this->cb = isset($t[1]) ? $t : $t[0];
 42:             } elseif (is_object($t)) {
 43:                 $this->cb = $t instanceof Closure ? $t : array($t, '__invoke');
 44:             } else {
 45:                 $this->cb = $t;
 46:             }
 47: 
 48:         } else {
 49:             $this->cb = array($t, $m);
 50:         }
 51: 
 52:         // remove class namespace
 53:         if (is_string($this->cb) && $a = strrpos($this->cb, '\\')) {
 54:             $this->cb = substr($this->cb, $a + 1);
 55: 
 56:         } elseif (is_array($this->cb) && is_string($this->cb[0]) && $a = strrpos($this->cb[0], '\\')) {
 57:             $this->cb[0] = substr($this->cb[0], $a + 1);
 58:         }
 59: 
 60:         if (!is_callable($this->cb, TRUE)) {
 61:             throw new InvalidArgumentException("Invalid callback.");
 62:         }
 63:     }
 64: 
 65: 
 66: 
 67:     /**
 68:      * Invokes callback. Do not call directly.
 69:      * @return mixed
 70:      */
 71:     public function __invoke()
 72:     {
 73:         if (!is_callable($this->cb)) {
 74:             throw new InvalidStateException("Callback '$this' is not callable.");
 75:         }
 76:         $args = func_get_args();
 77:         return call_user_func_array($this->cb, $args);
 78:     }
 79: 
 80: 
 81: 
 82:     /**
 83:      * Invokes callback.
 84:      * @return mixed
 85:      */
 86:     public function invoke()
 87:     {
 88:         if (!is_callable($this->cb)) {
 89:             throw new InvalidStateException("Callback '$this' is not callable.");
 90:         }
 91:         $args = func_get_args();
 92:         return call_user_func_array($this->cb, $args);
 93:     }
 94: 
 95: 
 96: 
 97:     /**
 98:      * Invokes callback with an array of parameters.
 99:      * @param  array
100:      * @return mixed
101:      */
102:     public function invokeArgs(array $args)
103:     {
104:         if (!is_callable($this->cb)) {
105:             throw new InvalidStateException("Callback '$this' is not callable.");
106:         }
107:         return call_user_func_array($this->cb, $args);
108:     }
109: 
110: 
111: 
112:     /**
113:      * Verifies that callback can be called.
114:      * @return bool
115:      */
116:     public function isCallable()
117:     {
118:         return is_callable($this->cb);
119:     }
120: 
121: 
122: 
123:     /**
124:      * Returns PHP callback pseudotype.
125:      * @return string|array|Closure
126:      */
127:     public function getNative()
128:     {
129:         return $this->cb;
130:     }
131: 
132: 
133: 
134:     /**
135:      * Returns callback reflection.
136:      * @return FunctionReflection|MethodReflection
137:      */
138:     public function toReflection()
139:     {
140:         if (is_array($this->cb)) {
141:             return new MethodReflection($this->cb[0], $this->cb[1]);
142:         } else {
143:             return new FunctionReflection($this->cb);
144:         }
145:     }
146: 
147: 
148: 
149:     /**
150:      * @return bool
151:      */
152:     public function isStatic()
153:     {
154:         return is_array($this->cb) ? is_string($this->cb[0]) : is_string($this->cb);
155:     }
156: 
157: 
158: 
159:     /**
160:      * @return string
161:      */
162:     public function __toString()
163:     {
164:         if ($this->cb instanceof Closure) {
165:             return '{closure}';
166:         } elseif (is_string($this->cb) && $this->cb[0] === "\0") {
167:             return '{lambda}';
168:         } else {
169:             is_callable($this->cb, TRUE, $textual);
170:             return $textual;
171:         }
172:     }
173: 
174: }
175: 
Nette Framework 2.0.1 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.7.0