33

Object

The Object class implements the base messages of the So-o model. All the other classes inherit from the Object class.

All the code for the So-o Object class is in the file Object.php.

  1. namespace Object;
  2.  
  3. use \InvalidArgumentException as InvalidArgumentException;

Places the code of the Object class in its own namespace.

  1. require_once 'OL.php';

Loads the code of the Object Layer.

  1. define(__NAMESPACE__ . '\InvalidClassProperty', '%s::%s Invalid class property');
  2. define(__NAMESPACE__ . '\InvalidClassMessage', '%s::%s Invalid class message');
  3. define(__NAMESPACE__ . '\InvalidInstanceProperty', '%s::%s Invalid instance property');
  4. define(__NAMESPACE__ . '\InvalidInstanceMessage', '%s::%s Invalid instance message');
  5.  
  6. define(__NAMESPACE__ . '\NotImplemented', '%s::%s Not implemented');
  7. define(__NAMESPACE__ . '\SubclassResponsibility', '%s::%s Subclass responsibility');

Defines the texts of the error messages returned by the Object class.

  1. defclass('Object',
  2.         // superclass
  3.         null,
  4.         // revision
  5.         1,
  6.         // class properties
  7.         null,
  8.         // instance properties
  9.         null,
  10.         // class messages
  11.         array('get', 'set', 'make', 'new', 'initialize', 'free', 'class', 'name', 'superclass', 'classMessages', 'instanceMessages', 'classProperties', 'instanceProperties', 'classMethodFor', 'instanceMethodFor', 'perform', 'read', 'write', 'error', 'doesNotContain', 'doesNotRecognize', 'notImplemented', 'subclassResponsibility', 'revision', 'addInstanceMessage', 'removeInstanceMessage', 'addClassMessage', 'removeClassMessage', 'addInstanceProperty', 'removeInstanceProperty', 'addClassProperty', 'removeClassProperty', 'check'),
  12.         // instance messages
  13.         array('get', 'set', 'init', 'free', 'class', 'superclass', 'perform', 'delegate', 'setDelegate', 'respondsTo', 'methodFor', 'isKindOf', 'copy', 'read', 'write', 'assume', 'toString', 'print', 'error', 'doesNotContain', 'doesNotRecognize', 'notImplemented', 'subclassResponsibility', 'messages', 'properties')
  14.         );

The Object class is the only class which doesn't inherit from a superclass. It doesn't have any class or instance properties. It implements all the base messages of the So-o model.

CLASS METHODS

free
SYNOPSIS

free($self)

DESCRIPTION

free is automatically sent by the Object Layer to a class which is not referenced anymore. The free method defined by the Object class does nothing.

IMPORTANT: If you decide to remove the __destruct method from the Definition class of the Object Layer, the container for a class, free will not be sent automatically.

CODE
  1. function c_free($self) {
  2. }

free does nothing.

initialize
SYNOPSIS

initialize($self)

DESCRIPTION

initialize is automatically sent by defclass to a new class. The initialize method defined by the Object class does nothing.

initialize is usually redefined by a class which must initialize its class properties.

CODE
  1. function c_initialize ($self) {
  2.     return $self;
  3. }

initialize does nothing and returns $self.

class
name
revision
superclass
SYNOPSIS

class($self)

name($self)

revision($self)

superclass($self)

DESCRIPTION

class returns the class of the class $self, i.e. $self.

name returns the name of the class $self.

revision returns the revision number of the class $self.

superclass returns the superclass of the class $self, null if $self is $Object, the Object class.

CODE
  1. function c_class($self) {
  2.     return $self;
  3. }
  4.  
  5. function c_name($self) {
  6.     return \OL\class_name($self);
  7. }
  8.  
  9. function c_revision($self) {
  10.     return \OL\class_revision($self);
  11. }
  12.  
  13. function c_superclass($self) {
  14.     return \OL\class_superclass($self);
  15. }

class returns $self. name, revision and superclass return the result of the functions class_name, class_revision and class_superclass of the Object Layer.

get
set
SYNOPSIS

get($self, $attribute)

set($self, $attribute, $value)

DESCRIPTION

get returns the value of the property $attribute of $self.

set sets the value of the property $attribute of $self to $value.

IMPORTANT: get returns a value, not a reference to a value. To modify the content of an attribute whose value is an array, obtain its value with get, modify it then change the value of the property with set.

CODE
  1. function c_get($self, $attribute) {
  2.     return \OL\class_get($self, $attribute);
  3. }
  4.  
  5. function c_set($self, $attribute, $value) {
  6.     return \OL\class_set($self, $attribute, $value);
  7. }

get and set return the result of the functions class_get and class_set of the Object Layer.

make
new
SYNOPSIS

make($self)

new($self[, $arg ...])

DESCRIPTION

make returns a new instance of $self.

new creates an instance of $self, sends it the message init with all the parameters of the message following $self and returns the new initialized instance.

IMPORTANT: Always create an instance with new.

CODE
  1. function c_make($self) {
  2.     return \OL\class_make($self);
  3. }
  4.  
  5. function c_new($self) {
  6.     return \OL\object_send_message(\OL\class_send_message($self, 'make'), 'init', array_slice(func_get_args(), 1));
  7. }

make returns the result of the function class_make of the Object Layer.

new creates an instance by sending make to $self, sends it init with the parameters of the message following self and returns the new instance.

perform
SYNOPSIS

perform($self, $message, $args=false)

DESCRIPTION

perform returns the result of sending the message $message to $self with $args in argument. $args is an array. By default, the message has no argument.

CODE
  1. function c_perform($self, $message, $args=false) {
  2.     return \OL\class_send_message($self, $message, $args);
  3. }

perform returns the result of sending $message and $args to $self.

read
write
SYNOPSIS

read($self, $data)

write($self)

DESCRIPTION

write returns the serialization of the attributes of $self.

read initializes the attributes of $self with $data. $data is a serialized array of values.

CODE
  1. function c_read($self, $data) {
  2.     $properties=\OL\class_send_message($self, 'classProperties', array(true));
  3.  
  4.     if (!$properties) {
  5.         return $self;
  6.     }
  7.  
  8.     $data=unserialize($data);
  9.     if (!is_array($data)) {
  10.         throw new InvalidArgumentException();
  11.     }
  12.  
  13.     $attributes=array();
  14.     foreach ($properties as $prop) {
  15.         if (isset($data[$prop])) {
  16.             $attributes[$prop]=$data[$prop];
  17.         }
  18.     }
  19.  
  20.     return \OL\class_set_attributes($self, $attributes);
  21. }
  22.  
  23. function c_write($self) {
  24.     return serialize(\OL\class_attributes($self));
  25. }

write calls the function serialize with in argument the array of attributes of $self and returns the result. read obtains the list of properties of $self, calls the function unserialize with $data in argument, checks if the result is an array, then initializes every attribute of $self with the corresponding value extracted from this array.

classMessages
instanceMessages
classMethodFor
instanceMethodFor
addClassMessage
removeClassMessage
addInstanceMessage
removeInstanceMessage
SYNOPSIS

classMessages($self, $inherit=true)

instanceMessages($self, $inherit=true)

classMethodFor($self, $message)

instanceMethodFor($self, $message)

addClassMessage($self, $message)

removeClassMessage($self, $message)

addInstanceMessage($self, $message)

removeInstanceMessage($self, $message)

DESCRIPTION

classMessages returns the class messages of $self in an array. If $inherit is true, classMessages also returns the class messages inherited from all the superclasses of $self.

instanceMessages returns the instance messages of $self in an array. If $inherit is true, instanceMessages also returns the instance messages inherited from all the superclasses of $self.

classMethodFor returns the function which implements the class message $message of $self.

instanceMethodFor returns the function which implements the instance message $message of $self.

addClassMessage adds the class message $message to $self.

removeClassMessage removes the class message $message from $self.

addInstanceMessage adds the instance message $message to $self.

removeInstanceMessage removes the instance message $message from $self.

CODE
  1. function c_classMessages($self, $inherit=true) {
  2.     $messages=\OL\class_class_messages($self);
  3.  
  4.     if ($messages) {
  5.         $messages=array_keys($messages);
  6.     }
  7.  
  8.     if ($inherit) {
  9.         $superclass=\OL\class_superclass($self);
  10.  
  11.         if ($superclass) {
  12.             $inherited_messages=\OL\class_send_message($superclass, 'classMessages', array(true));
  13.  
  14.             if ($inherited_messages) {
  15.                 $messages=$messages ? array_unique(array_merge($messages, $inherited_messages)) : $inherited_messages;
  16.             }
  17.         }
  18.     }
  19.  
  20.     return $messages;
  21. }
  22.  
  23. function c_instanceMessages($self, $inherit=true) {
  24.     $messages=\OL\class_instance_messages($self);
  25.  
  26.     if ($messages) {
  27.         $messages=array_keys($messages);
  28.     }
  29.  
  30.     if ($inherit) {
  31.         $superclass=\OL\class_superclass($self);
  32.  
  33.         if ($superclass) {
  34.             $inherited_messages=\OL\class_send_message($superclass, 'instanceMessages', array(true));
  35.  
  36.             if ($inherited_messages) {
  37.                 $messages=$messages ? array_unique(array_merge($messages, $inherited_messages)) : $inherited_messages;
  38.             }
  39.         }
  40.     }
  41.  
  42.     return $messages;
  43. }
  44.  
  45. function c_classMethodFor($self, $message) {
  46.     return \OL\class_find_class_method($self, $message);
  47. }
  48.  
  49. function c_instanceMethodFor($self, $message) {
  50.     return \OL\class_find_instance_method($self, $message);
  51. }
  52.  
  53. function c_addClassMessage($self, $message) {
  54.     return \OL\class_add_class_message($self, $message);
  55. }
  56.  
  57. function c_removeClassMessage($self, $message) {
  58.     return \OL\class_remove_class_message($self, $message);
  59. }

classMessages sets $messages to the list of the class messages of $self, adds the class messages of the superclasses of $self, deleting duplicates, if $inherit is true then returns $messages. instanceMessages sets $messages to the list of the instance messages of $self, adds the instance messages of the superclasses of $self, deleting duplicates, if $inherit is true then returns $messages. classMethodFor, instanceMethodFor, addClassMessage, removeClassMessage, addInstanceMessage and removeInstanceMessage return the result of the functions class_find_class_method, class_find_instance_method, class_add_class_message, class_remove_class_message, class_add_instance_message and class_remove_instance_message of the Object Layer.

classProperties
instanceProperties
addClassProperty
removeClassProperty
addInstanceProperty
removeInstanceProperty
SYNOPSIS

classProperties($self, $inherit=true)

instanceProperties($self, $inherit=true)

classMethodFor($self, $property)

instanceMethodFor($self, $property)

addClassProperty($self, $property)

removeClassProperty($self, $property)

addInstanceProperty($self, $property)

removeInstanceProperty($self, $property)

DESCRIPTION

classProperties returns the class properties of $self in an array. If $inherit is true, classProperties also returns the class properties inherited from all the superclasses of $self.

instanceProperties returns the instance properties of $self in an array. If $inherit is true, instanceProperties also returns the instance properties inherited from all the superclasses of $self.

addClassProperty adds the class property $property to $self.

removeClassProperty removes the class property $property from $self.

addInstanceProperty adds the instance property $property to $self.

removeInstanceProperty removes the instance property $property from $self.

CODE
  1. function c_addInstanceMessage($self, $message) {
  2.     return \OL\class_add_instance_message($self, $message);
  3. }
  4.  
  5. function c_removeInstanceMessage($self, $message) {
  6.     return \OL\class_remove_instance_message($self, $message);
  7. }
  8.  
  9. function c_classProperties($self, $inherit=true) {
  10.     $properties=\OL\class_class_properties($self);
  11.  
  12.     if ($properties) {
  13.         $properties=array_keys($properties);
  14.     }
  15.  
  16.     if ($inherit) {
  17.         $superclass=\OL\class_superclass($self);
  18.  
  19.         if ($superclass) {
  20.             $inherited_properties=\OL\class_send_message($superclass, 'classProperties', array(true));
  21.  
  22.             if ($inherited_properties) {
  23.                 $properties=$properties ? array_unique(array_merge($properties, $inherited_properties)) : $inherited_properties;
  24.             }
  25.         }
  26.     }
  27.  
  28.     return $properties;
  29. }
  30.  
  31. function c_instanceProperties($self, $inherit=true) {
  32.     $properties=\OL\class_instance_properties($self);
  33.  
  34.     if ($properties) {
  35.         $properties=array_keys($properties);
  36.     }
  37.  
  38.     if ($inherit) {
  39.         $superclass=\OL\class_superclass($self);
  40.  
  41.         if ($superclass) {
  42.             $inherited_properties=\OL\class_send_message($superclass, 'instanceProperties', array(true));
  43.  
  44.             if ($inherited_properties) {
  45.                 $properties=$properties ? array_unique(array_merge($properties, $inherited_properties)) : $inherited_properties;
  46.             }
  47.         }
  48.     }
  49.  
  50.     return $properties;
  51. }

classProperties sets $properties to the list of the class properties of $self, adds the class properties of the superclasses of $self, deleting duplicates, if $inherit is true then returns $properties. instanceProperties sets $properties to the list of the instance properties of $self, adds the instance properties of the superclasses of $self, deleting duplicates, if $inherit is true then returns $properties. addClassProperty, removeClassProperty, addInstanceProperty and removeInstanceProperty return the result of the functions class_add_class_property, class_remove_class_property, class_add_instance_property and class_remove_instance_property of the Object Layer.

error
doesNotContain
doesNotRecognize
notImplemented
subclassResponsibility
SYNOPSIS

error($self, $err[, $arg ...])

doesNotContain($self, $property)

doesNotRecognize($self, $message)

notImplemented($self, $message)

subclassResponsibility($self, $message)

DESCRIPTION

error triggers a PHP error level E_USER_ERROR whose text is formatted with the function sprintf with in argument $err and the parameters of the message following $err.

doesNotContain sends the message error to $self with in argument the constant InvalidClassProperty, the name of the class $self and $property.

doesNotRecognize sends the message error to $self with in argument the constant InvalidClassMessage, the name of the class $self and $message.

notImplemented sends the message error to $self with in argument the constant NotImplemented, the name of the class $self and $message.

subclassResponsibility sends the message error to $self with in argument the constant SubclassResponsibility, the name of the class $self and $message.

doesNotContain and doesNotRecognize are sent by the Object Layer. notImplemented is generally sent by a method which isn't coded yet while subclassResponsibility is sent by a method which must be implemented by a subclass of an abstract class.

CODE
  1. function c_addClassProperty($self, $property) {
  2.     return \OL\class_add_class_property($self, $property);
  3. }
  4.  
  5. function c_removeClassProperty($self, $property) {
  6.     return \OL\class_remove_class_property($self, $property);
  7. }
  8.  
  9. function c_addInstanceProperty($self, $property) {
  10.     return \OL\class_add_instance_property($self, $property);
  11. }
  12.  
  13. function c_removeInstanceProperty($self, $property) {
  14.     return \OL\class_remove_instance_property($self, $property);
  15. }
  16.  
  17. function c_error ($self, $err) {
  18.     $errmsg=call_user_func_array('sprintf', array_merge(array($err), array_slice(func_get_args(), 2)));
  19.  
  20.     return trigger_error($errmsg, E_USER_ERROR);
  21. }

error formats the error message $errmsg by passing $err and the remaining arguments of error following $err to sprintf then calls trigger_error with in argument $errmsg and the error level E_USER_ERROR. doesNotContain, doesNotRecognize, notImplemented and subclassResponsibility send the message error to $self with in argument the constant of the corresponding error message and its parameters.

check
SYNOPSIS

check($self)

DESCRIPTION

check checks the integrity of the class $self.

check returns an array of 4 arrays. The first lists the class messages which don't have a corresponding function in the namespace of the class $self. The second lists the class messages which are not mentionned in the definition of the class $self although the corresponding function has been found in its namespace. The third lists the instance messages which don't have a corresponding function in the namespace of the class $self. The fourth lists the instance messages which are not mentionned in the definition of the class $self although the corresponding function has been found in its namespace.

CODE
  1. function c_doesNotContain($self, $property) {
  2.     return \OL\class_send_message($self, 'error', array(InvalidClassProperty, \OL\class_name($self), $property));
  3. }

check returns the result of the function class_check of the Object Layer.

INSTANCE METHODS

class
superclass
messages
properties
SYNOPSIS

class($self)

superclass($self)

messages($self, $inherit=true)

properties($self, $inherit=true)

DESCRIPTION

class returns the class of $self.

superclass returns the superclass of the class of $self, null if $self is an instance of the Object class.

messages returns the messages recognized by $self in an array. If $inherit is true, messages also returns the messages inherited from all the superclasses of $self. $inherit is true by default.

instanceProperties returns the properties of $self in an array. If $inherit is true, properties also returns the properties inherited from all the superclasses of $self. $inherit is true by default.

CODE
  1. function i_class($self) {
  2.     return \OL\object_class($self);
  3. }
  4.  
  5. function i_superclass($self) {
  6.     return \OL\class_superclass(\OL\object_class($self));
  7. }
  8.  
  9. function i_messages($self, $inherit=true) {
  10.     return \OL\class_send_message(\OL\object_class($self), 'instanceMessages', array($inherit));
  11. }
  12.  
  13. function i_properties($self, $inherit=true) {
  14.     return \OL\class_send_message(\OL\object_class($self), 'instanceProperties', array($inherit));
  15. }

class returns the result of the function object_class of the Object Layer. superclass returns the result of the function class_superclass with the class of $self in argument. messages sends the message instanceMessages to the class of $self with $inherit in argument. properties sends the message instanceProperties to the class of $self with $inherit in argument.

isKindOf
methodFor
respondsTo
assume
SYNOPSIS

isKindOf($self, $class)

methodFor($self, $message)

respondsTo($self, $message)

assume($self, $class)

DESCRIPTION

isKindOf returns true if $self is an instance of the class or a subclass of $class or false if not.

methodFor returns the function which implements the message $message for $self or false if $self doesn't respond to $message.

respondsTo returns true if $self has a method for the message $message, false if not.

assume changes the class of $self to $class. The values of the properties of the former class of $self which are not part of the class $class are preserved but they are not accessible.

CODE
  1. function i_isKindOf($self, $class) {
  2.     return \OL\class_is_kind_of(\OL\object_class($self), $class);
  3. }
  4.  
  5. function i_methodFor($self, $message) {
  6.     return \OL\class_find_instance_method(\OL\object_class($self), $message);
  7. }
  8.  
  9. function i_respondsTo($self, $message) {
  10.     return \OL\class_find_instance_method(\OL\object_class($self), $message) ? true : false;
  11. }
  12.  
  13. function i_assume($self, $class) {
  14.     return \OL\object_assume($self, $class);
  15. }

isKindOf returns the result of the function class_is_kind_of of the Object Layer with in argument the class of $self and $class. methodFor returns the result of the function class_find_instance_method with in argument the class of $self and $message. respondsTo returns true if the result of the function class_find_instance_method with in argument the class of $self and $message isn't false, true otherwise. assume calls object_assume with $class in argument.

free
SYNOPSIS

free($self)

DESCRIPTION

free is automatically sent by the Object Layer to an instance which is not referenced anymore. The free method defined by the Object class does nothing.

IMPORTANT: If you decide to remove the __destruct method from the Instance class of the Object Layer, the container for an instance, free will not be sent automatically.

CODE
  1. function i_free($self) {
  2. }

free does nothing.

init
SYNOPSIS

init($self[, $arg ...])

DESCRIPTION

init is automatically sent by new to a new instance. The init method defined by the Object class does nothing.

init is usually redefined by a class which must initialize its instance properties.

CODE
  1. function i_init($self) {
  2.     return $self;
  3. }

init does nothing and returns $self.

copy
SYNOPSIS

copy($self)

DESCRIPTION

copy returns a copy of $self.

CODE
  1. function i_copy ($self) {
  2.     return \OL\object_copy($self);
  3. }

copy returns the result of the function object_copy of the Object Layer.

toString
print
SYNOPSIS

toString($self)

print($self, $eol=false)

DESCRIPTION

toString returns a readable representation of $self. The toString method of the Object class returns an empty string.

print writes the readable representation of $self to the standard output buffer. If $eol is true, print adds a newline. $eol is false by default. print returns $self.

CODE
  1. function i_toString($self) {
  2.     return '';
  3. }
  4.  
  5. function i_print($self, $eol=false) {
  6.     echo \OL\object_send_message($self, 'toString');
  7.  
  8.     if ($eol) {
  9.         echo PHP_EOL;
  10.     }
  11.  
  12.     return $self;
  13. }

toString returns an empty string. print writes the result of sending the message toString to $self to the standard output buffer, adds the value of the constant PHP_EOL if $eol is true and returns $self.

get
set
SYNOPSIS

get($self, $attribute)

set($self, $attribute, $value)

DESCRIPTION

get returns the value of the property $attribute of $self.

set sets the value of the property $attribute of $self to $value.

If $attribute isn't a property of $self, the message doesNotContain is sent to $self with $attribute in argument.

IMPORTANT: get returns a value, not a reference to a value. To modify the content of an attribute whose value is an array, obtain its value with get, modify it then change the value of the property with set.

CODE
  1. function i_get($self, $property) {
  2.     return \OL\object_get($self, $property);
  3. }
  4.  
  5. function i_set($self, $property, $value) {
  6.     return \OL\object_set($self, $property, $value);
  7. }

get returns the result of the function object_get of the Object Layer with in argument $attribute.

set returns the result of the function object_set of the Object Layer with in argument $attribute and $value.

perform
SYNOPSIS

perform($self, $message, $args=false)

DESCRIPTION

perform returns the result of sending the message $message to $self with $args in argument. $args is an array. By default, the message has no argument.

CODE
  1. function i_perform($self, $message, $args=false) {
  2.     return \OL\object_send_message($self, $message, $args);
  3. }

perform returns the result of sending $message and $args to $self.

read
write
SYNOPSIS

read($self, $data)

write($self)

DESCRIPTION

write returns the serialization of the attributs of $self.

read initializes the attributs of $self with $data. $data is a serialized array of values.

CODE
  1. function i_read($self, $data) {
  2.     $properties=\OL\class_send_message(\OL\object_class($self), 'instanceProperties', array(true));
  3.  
  4.     if (!$properties) {
  5.         return $self;
  6.     }
  7.  
  8.     $data=unserialize($data);
  9.     if (!is_array($data)) {
  10.         throw new InvalidArgumentException();
  11.     }
  12.  
  13.     $attributes=array();
  14.     foreach ($properties as $prop) {
  15.         if (isset($data[$prop])) {
  16.             $attributes[$prop]=$data[$prop];
  17.         }
  18.     }
  19.  
  20.     return \OL\object_set_attributes($self, $attributes);
  21. }
  22.  
  23. function i_write($self) {
  24.     return serialize(\OL\object_attributes($self));
  25. }

write calls the function serialize with in argument the array of attributs of $self and returns the result. read obtains the list of properties of $self, calls the function unserialize with $data in argument, checks if the result is an array, then initializes every attributs of $self with the corresponding value extracted from this array.

delegate
setDelegate
SYNOPSIS

delegate($self, $msg=false[, $arg ...])

setDelegate($self, $delegate)

DESCRIPTION

delegate returns the result of sending the message $msg and the arguments $arg following $msg to the delegate of $self. If $self doesn't have a delegate or if the delegate of $self doesn't respond to the message $msg, delegate returns false. If $msg is false, delegate returns the delegate of $self.

setDelegate initializes the delegate property of $self with $delegate.

NOTE: Sending delegate or setDelegate to an instance which does have the property delegate sends the message doesNotContain to the instance.

CODE
  1. function i_delegate($self, $msg=false) {
  2.     $delegate=\OL\object_get($self, 'delegate');
  3.  
  4.     if (!$msg) {
  5.         return $delegate;
  6.     }
  7.  
  8.     if (!$delegate) {
  9.         return false;
  10.     }
  11.  
  12.     if (!\OL\object_send_message($delegate, 'respondsTo', array($msg))) {
  13.         return false;
  14.     }
  15.  
  16.     return \OL\object_send_message($delegate, $msg, array_slice(func_get_args(), 2));
  17. }
  18.  
  19. function i_setDelegate($self, $delegate) {
  20.     if (!(is_null($delegate) or is_object($delegate))) {
  21.         throw new InvalidArgumentException();
  22.     }
  23.  
  24.     return \OL\object_set($self, 'delegate', $delegate);
  25. }

delegate sets $delegate to the valeur of the property delegate of $self, returns $delegate if $msg is false, returns false if $delegate is null or if $delegate doesn't respond to $msg, returns the result of sending $msg with the arguments of delegate following $msg to $delegate. setDelegate checks if $delegate is null or an object then sets the property delegate of $self to $delegate.

error
doesNotContain
doesNotRecognize
notImplemented
subclassResponsibility
SYNOPSIS

error($self, $err[, $arg ...])

doesNotContain($self, $property)

doesNotRecognize($self, $message)

notImplemented($self, $message)

subclassResponsibility($self, $message)

DESCRIPTION

error triggers a PHP error level E_USER_ERROR whose text is formatted with the function sprintf with in argument $err and the parameters of the message following $err.

doesNotContain sends the message error to $self with in argument the constant InvalidClassProperty, the name of the class of $self and $property.

doesNotRecognize sends the message error to $self with in argument the constant InvalidClassMessage, the name of the class of $self and $message.

notImplemented sends the message error to $self with in argument the constant NotImplemented, the name of the class of $self and $message.

subclassResponsibility sends the message error to $self with in argument the constant SubclassResponsibility, the name of the class of $self and $message.

doesNotContain and doesNotRecognize are sent by the Object Layer. notImplemented is generally sent by a method which isn't coded yet while subclassResponsibility is sent by a method which must be implemented by a subclass of an abstract class.

CODE
  1. function i_error ($self, $err) {
  2.     $errmsg=call_user_func_array('sprintf', array_merge(array($err), array_slice(func_get_args(), 2)));
  3.  
  4.     return trigger_error($errmsg, E_USER_ERROR);
  5. }
  6.  
  7. function i_doesNotContain($self, $property) {
  8.     return \OL\object_send_message($self, 'error', array(InvalidInstanceProperty, \OL\class_name(\OL\object_class($self)), $property));
  9. }
  10.  
  11. function i_doesNotRecognize($self, $message) {
  12.     return \OL\object_send_message($self, 'error', array(InvalidInstanceMessage, \OL\class_name(\OL\object_class($self)), $message));
  13. }
  14.  
  15. function i_notImplemented($self, $message) {
  16.     return \OL\object_send_message($self, 'error', array(NotImplemented, \OL\class_name(\OL\object_class($self)), $message));
  17. }
  18.  
  19. function i_subclassResponsibility($self, $message) {
  20.     return \OL\object_send_message($self, 'error', array(SubclassResponsibility, \OL\class_name(\OL\object_class($self)), $message));
  21. }

error formats the error message $errmsg by passing $err and the remaining arguments of error following $err to sprintf then calls trigger_error with in argument $errmsg and the error level E_USER_ERROR. doesNotContain, doesNotRecognize, notImplemented and subclassResponsibility send the message error to $self with in argument the constant of the corresponding error message and its parameters.

SEE ALSO

Interface, Object Layer

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].