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
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy
    • Bridges
      • Nette

Classes

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

Interfaces

  • IFreezable

Exceptions

  • ArgumentOutOfRangeException
  • DeprecatedException
  • DirectoryNotFoundException
  • FileNotFoundException
  • InvalidArgumentException
  • InvalidStateException
  • IOException
  • MemberAccessException
  • NotImplementedException
  • NotSupportedException
  • OutOfRangeException
  • StaticClassException
  • UnexpectedValueException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
  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: use Nette\Utils\ObjectMixin;
 12: 
 13: 
 14: /**
 15:  * Nette\Object is the ultimate ancestor of all instantiable classes.
 16:  *
 17:  * It defines some handful methods and enhances object core of PHP:
 18:  *   - access to undeclared members throws exceptions
 19:  *   - support for conventional properties with getters and setters
 20:  *   - support for event raising functionality
 21:  *   - ability to add new methods to class (extension methods)
 22:  *
 23:  * Properties is a syntactic sugar which allows access public getter and setter
 24:  * methods as normal object variables. A property is defined by a getter method
 25:  * or setter method (no setter method means read-only property).
 26:  * <code>
 27:  * $val = $obj->label;     // equivalent to $val = $obj->getLabel();
 28:  * $obj->label = 'Nette';  // equivalent to $obj->setLabel('Nette');
 29:  * </code>
 30:  * Property names are case-sensitive, and they are written in the camelCaps
 31:  * or PascalCaps.
 32:  *
 33:  * Event functionality is provided by declaration of property named 'on{Something}'
 34:  * Multiple handlers are allowed.
 35:  * <code>
 36:  * public $onClick;                // declaration in class
 37:  * $this->onClick[] = 'callback';  // attaching event handler
 38:  * if (!empty($this->onClick)) ... // are there any handlers?
 39:  * $this->onClick($sender, $arg);  // raises the event with arguments
 40:  * </code>
 41:  *
 42:  * Adding method to class (i.e. to all instances) works similar to JavaScript
 43:  * prototype property. The syntax for adding a new method is:
 44:  * <code>
 45:  * MyClass::extensionMethod('newMethod', function (MyClass $obj, $arg, ...) { ... });
 46:  * $obj = new MyClass;
 47:  * $obj->newMethod($x);
 48:  * </code>
 49:  *
 50:  * @property-read Nette\Reflection\ClassType|\ReflectionClass $reflection
 51:  */
 52: abstract class Object
 53: {
 54: 
 55:     /**
 56:      * Access to reflection.
 57:      * @return Nette\Reflection\ClassType|\ReflectionClass
 58:      */
 59:     public static function getReflection()
 60:     {
 61:         $class = class_exists('Nette\Reflection\ClassType') ? 'Nette\Reflection\ClassType' : 'ReflectionClass';
 62:         return new $class(get_called_class());
 63:     }
 64: 
 65: 
 66:     /**
 67:      * Call to undefined method.
 68:      * @param  string  method name
 69:      * @param  array   arguments
 70:      * @return mixed
 71:      * @throws MemberAccessException
 72:      */
 73:     public function __call($name, $args)
 74:     {
 75:         return ObjectMixin::call($this, $name, $args);
 76:     }
 77: 
 78: 
 79:     /**
 80:      * Call to undefined static method.
 81:      * @param  string  method name (in lower case!)
 82:      * @param  array   arguments
 83:      * @return mixed
 84:      * @throws MemberAccessException
 85:      */
 86:     public static function __callStatic($name, $args)
 87:     {
 88:         return ObjectMixin::callStatic(get_called_class(), $name, $args);
 89:     }
 90: 
 91: 
 92:     /**
 93:      * Adding method to class.
 94:      * @param  string  method name
 95:      * @param  callable
 96:      * @return mixed
 97:      */
 98:     public static function extensionMethod($name, $callback = NULL)
 99:     {
100:         if (strpos($name, '::') === FALSE) {
101:             $class = get_called_class();
102:         } else {
103:             list($class, $name) = explode('::', $name);
104:             $rc = new \ReflectionClass($class);
105:             $class = $rc->getName();
106:         }
107:         if ($callback === NULL) {
108:             return ObjectMixin::getExtensionMethod($class, $name);
109:         } else {
110:             ObjectMixin::setExtensionMethod($class, $name, $callback);
111:         }
112:     }
113: 
114: 
115:     /**
116:      * Returns property value. Do not call directly.
117:      * @param  string  property name
118:      * @return mixed   property value
119:      * @throws MemberAccessException if the property is not defined.
120:      */
121:     public function &__get($name)
122:     {
123:         return ObjectMixin::get($this, $name);
124:     }
125: 
126: 
127:     /**
128:      * Sets value of a property. Do not call directly.
129:      * @param  string  property name
130:      * @param  mixed   property value
131:      * @return void
132:      * @throws MemberAccessException if the property is not defined or is read-only
133:      */
134:     public function __set($name, $value)
135:     {
136:         ObjectMixin::set($this, $name, $value);
137:     }
138: 
139: 
140:     /**
141:      * Is property defined?
142:      * @param  string  property name
143:      * @return bool
144:      */
145:     public function __isset($name)
146:     {
147:         return ObjectMixin::has($this, $name);
148:     }
149: 
150: 
151:     /**
152:      * Access to undeclared property.
153:      * @param  string  property name
154:      * @return void
155:      * @throws MemberAccessException
156:      */
157:     public function __unset($name)
158:     {
159:         ObjectMixin::remove($this, $name);
160:     }
161: 
162: }
163: 
Nette 2.3.8 API API documentation generated by ApiGen 2.8.0