ExtendableTrait

This extension trait is used when access to the underlying base class is not available, such as classes that belong to the foundation framework (Laravel). It is currently used by the Controller and Model classes.

 trait Winter\Storm\Extension\ExtendableTrait

Properties

protected static $extendableCallbacks : array

Used to extend the constructor of an extendable class. Eg:

Class::extend(function($obj) { })

protected static $extendableClassLoader : ClassLoader | null

Class loader instance.

protected static $extendableGuardProperties : bool

Indicates if dynamic properties can be created.

protected static $extendableStaticMethods : array

Collection of static methods used by behaviors.

protected $extensionData : array

Class reflection information, including behaviors.

Methods

public addDynamicMethod (string $dynamicName, callable $method, string $extension = null)

Programmatically adds a method to the extendable class

Parameters
Property Description
$dynamicName
string
$method
callable
$extension
string
Returns
mixed

public addDynamicProperty (string $dynamicName, mixed $value = null) : void

Programmatically adds a property to the extendable class

Parameters
Property Description
$dynamicName
string

The name of the property to add

$value
mixed

The value of the property

Returns
void

public asExtension (string $shortName) : mixed

Short hand for getClassExtension() method, except takes the short extension name, example:

$this->asExtension('FormController')

Parameters
Property Description
$shortName
string
Returns
mixed

public static clearExtendedClasses () : void

Clear the list of extended classes so they will be re-extended.

Returns
void

public extendClassWith (string $extensionName) : void

Dynamically extend a class with a specified behavior

Parameters
Property Description
$extensionName
string
Returns
void

public extendableCall (string $name, array $params = null) : mixed

Magic method for __call().

Callback priority is as follows:

  • "Dynamic Methods" added locally to the object via addDynamicMethod($name, $callable)
  • Methods available on Behaviors that have been implemented by the object
  • Pass it to the parent's __call() method if it defines one
Parameters
Property Description
$name
string
$params
array
Returns
mixed

public static extendableCallStatic (string $name, array $params = null) : mixed

Magic method for __callStatic()

Parameters
Property Description
$name
string
$params
array
Returns
mixed

public extendableConstruct ()

This method should be called as part of the constructor.

Returns
mixed

public static extendableExtendCallback (callable $callback, boolean $scoped = false, $outerScope = null) : void

Helper method for ::extend() static method.

Parameters
Property Description
$callback
callable
$scoped
boolean
$outerScope
mixed
Returns
void

public extendableGet (string $name) : mixed | null

Magic method for __get()

Parameters
Property Description
$name
string
Returns
mixed | null

public extendableSet (string $name, mixed $value) : void

Magic method for __set()

Parameters
Property Description
$name
string
$value
mixed
Returns
void

public getClassExtension (string $name) : mixed

Returns a behavior object from an extendable class, example:

$this->getClassExtension('Backend.Behaviors.FormController')

Parameters
Property Description
$name
string

Fully qualified behavior name

Returns
mixed

public getClassMethods () : array

Get a list of class methods, extension equivalent of get_class_methods()

Returns
array

public getDynamicProperties () : array

Returns all dynamic properties and their values

Returns
array

['property' => 'value']

public isClassExtendedWith (string $name) : bool

Check if extendable class is extended with a behavior object

Parameters
Property Description
$name
string

Fully qualified behavior name

Returns
bool

public methodExists (string $name) : bool

Checks if a method exists, extension equivalent of method_exists()

Parameters
Property Description
$name
string
Returns
bool

public propertyExists (string $name) : bool

Checks if a property exists, extension equivalent of property_exists()

Parameters
Property Description
$name
string
Returns
bool

protected extendableIsAccessible (mixed $class, string $propertyName) : bool

Checks if a property is accessible, property equivalent of is_callable()

Parameters
Property Description
$class
mixed
$propertyName
string
Returns
bool

protected extensionExtractMethods (string $extensionName, object $extensionObject) : void

Extracts the available methods from a behavior and adds it to the list of callable methods.

Parameters
Property Description
$extensionName
string
$extensionObject
object
Returns
void

protected extensionGetClassLoader () : Winter\Storm\Support\ClassLoader | null

Gets the class loader

Returns
Winter\Storm\Support\ClassLoader | null

protected extensionNormalizeClassName (string $name) : string

Normalizes the provided extension name allowing for the ClassLoader to inject aliased classes

Parameters
Property Description
$name
string
Returns
string
Copyright © 2024 Winter CMS