Class Prototype
Subclasses of the ICanBoogie\Object
class are associated with a prototype, which can be used to
add methods as well as getters and setters to classes.
When using the ICanBoogie framework, methods can be defined using the "hooks" config and the
"prototypes" namespace:
<?php
return [
'prototypes' => [
'Icybee\Modules\Pages\Page::my_additional_method' => 'MyHookClass::my_additional_method',
'Icybee\Modules\Pages\Page::lazy_get_my_property' => 'MyHookClass::lazy_get_my_property'
]
];
-
ICanBoogie\Prototype
implements
ArrayAccess,
IteratorAggregate
Methods summary
public static
from( string|object $class
)
: ICanBoogie\Prototype
Returns the prototype associated with the specified class or object.
Returns the prototype associated with the specified class or object.
Parameters
$class
- Class name or instance.
Returns
protected
__construct( string $class
)
Creates a prototype for the specified class.
Creates a prototype for the specified class.
Parameters
protected
get_consolidated_methods( void )
: callable[]
Consolidate the methods of the prototype.
Consolidate the methods of the prototype.
The method creates a single array from the prototype methods and those of its parents.
Returns
callable[]
protected
revoke_consolidated_methods( void )
Revokes the consolidated methods of the prototype.
Revokes the consolidated methods of the prototype.
The method must be invoked when prototype methods are modified.
public
offsetSet( string $method
, callable $callback
)
Adds or replaces the specified method of the prototype.
Adds or replaces the specified method of the prototype.
Parameters
$method
- The name of the method.
$callback
Implementation of
ArrayAccess::offsetSet()
public
offsetUnset( string $method
)
Removed the specified method from the prototype.
Removed the specified method from the prototype.
Parameters
$method
- The name of the method.
Implementation of
ArrayAccess::offsetUnset()
public
offsetExists( string $method
)
: boolean
Checks if the prototype defines the specified method.
Checks if the prototype defines the specified method.
Parameters
$method
- The name of the method.
Returns
boolean
Implementation of
ArrayAccess::offsetExists()
public
offsetGet( string $method
)
: callable
Returns the callback associated with the specified method.
Returns the callback associated with the specified method.
Parameters
$method
- The name of the method.
Returns
callable
Throws
Implementation of
ArrayAccess::offsetGet()
public
getIterator( void )
Returns an iterator for the prototype methods.
Returns an iterator for the prototype methods.
Implementation of
IteratorAggregate::getIterator()
Properties summary
protected static
$prototypes
: array[string]Prototype
Prototypes built per class.
Prototypes built per class.
[]
protected static
$pool
: array[string]callable
Pool of prototype methods per class.
Pool of prototype methods per class.
protected
$class
: string
Class associated with the prototype.
Class associated with the prototype.
protected
$methods
: array[string]callable
Methods defined by the prototype.
Methods defined by the prototype.
[]
protected
$consolidated_methods
: array[string]callable
Methods defined by the prototypes chain.
Methods defined by the prototypes chain.