abstract class TexyObject

TexyObject is the ultimate ancestor of all instantiable classes.

TexyObject is copy of Nette\Object from Nette Framework (https://nette.org).

It defines some handful methods and enhances object core of PHP:

  • access to undeclared members throws exceptions
  • support for conventional properties with getters and setters
  • support for event raising functionality
  • ability to add new methods to class (extension methods)

Properties is a syntactic sugar which allows access public getter and setter methods as normal object variables. A property is defined by a getter method and optional setter method (no setter method means read-only property).

$val = $obj->label; // equivalent to $val = $obj->getLabel();
$obj->label = 'Nette'; // equivalent to $obj->setLabel('Nette');

Property names are case-sensitive, and they are written in the camelCaps or PascalCaps.

Event functionality is provided by declaration of property named 'on{Something}' Multiple handlers are allowed.

public $onClick; // declaration in class
$this->onClick[] = 'callback'; // attaching event handler
if (!empty($this->onClick)) ... // are there any handlers?
$this->onClick($sender, $arg); // raises the event with arguments

Adding method to class (i.e. to all instances) works similar to JavaScript prototype property. The syntax for adding a new method is:

MyClass::extensionMethod('newMethod', function (MyClass $obj, $arg, ...) { ... });
$obj = new MyClass;
$obj->newMethod($x);

Methods

string
getClass()

Returns the name of the class of this object.

getReflection()

Access to reflection.

mixed
__call($name, $args)

Call to undefined method.

static mixed
__callStatic($name, $args)

Call to undefined static method.

static mixed
extensionMethod($name, $callback = NULL)

Adding method to class.

mixed
__get($name)

Returns property value. Do not call directly.

void
__set($name, $value)

Sets value of a property. Do not call directly.

bool
__isset($name)

Is property defined?

void
__unset($name)

Access to undeclared property.

Details

at line 58
final string getClass()

Returns the name of the class of this object.

Return Value

string

at line 69
final ReflectionObject getReflection()

Access to reflection.

Return Value

ReflectionObject

at line 83
mixed __call($name, $args)

Call to undefined method.

Parameters

$name
$args

Return Value

mixed

Exceptions

LogicException

at line 128
static mixed __callStatic($name, $args)

Call to undefined static method.

Parameters

$name
$args

Return Value

mixed

Exceptions

LogicException

at line 142
static mixed extensionMethod($name, $callback = NULL)

Adding method to class.

Parameters

$name
$callback

Return Value

mixed

at line 206
mixed __get($name)

Returns property value. Do not call directly.

Parameters

$name

Return Value

mixed

property value

Exceptions

LogicException

at line 244
void __set($name, $value)

Sets value of a property. Do not call directly.

Parameters

$name
$value

Return Value

void

Exceptions

LogicException

at line 277
bool __isset($name)

Is property defined?

Parameters

$name

Return Value

bool

at line 291
void __unset($name)

Access to undeclared property.

Parameters

$name

Return Value

void

Exceptions

LogicException