ExtendableTrait 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.

See Also

Protected Properties

protected array $extensionData

extensionData contains class reflection information, including behaviors

protected static array $extendableStaticMethods

extendableStaticMethods is a collection of static methods used by behaviors

protected static bool $extendableGuardProperties

extendableGuardProperties indicates if dynamic properties can be created

Public Methods

public addDynamicMethod()

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

addDynamicMethod programmatically adds a method to the extendable class

public addDynamicProperty()

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

addDynamicProperty programmatically adds a property to the extendable class

public asExtension()

public asExtension(string $shortName): mixed 

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


public static clearExtendedClasses()

public static clearExtendedClasses(): void

public extendClassWith()

public extendClassWith(string $extensionName): void 

extendClassWith dynamically extends a class with a specified behavior

public extendableCall()

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

extendableCall magic method for __call()

public static extendableCallStatic()

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

extendableCallStatic magic method for __callStatic()

public extendableConstruct()

public extendableConstruct(): void

extendableConstruct should be called as part of the constructor

public extendableDestruct()

public extendableDestruct(): void

extendableDestruct should be called when serializing the object

public static extendableExtendCallback()

public static extendableExtendCallback(callable $callback): void 

extendableExtendCallback is a helper method for ::extend() static method

public extendableGet()

public extendableGet(string $name): string 

extendableGet magic method for __get()

public extendableSet()

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

extendableSet magic method for __set()

public getClassExtension()

public getClassExtension(string $name): mixed 

getClassExtension returns a behavior object from an extendable class, example:


public getClassMethodAsReflector()

public getClassMethodAsReflector($name): ReflectionFunctionAbstract 

public getClassMethods()

public getClassMethods(): array 

getClassMethods gets a list of class methods, extension equivalent of get_class_methods()

public getDynamicProperties()

public getDynamicProperties(): array 

getDynamicProperties returns all dynamic properties and their values

public implementClassWith()

public implementClassWith($extensionName): void

implementClassWith will implement an extension using non-interference and should be used with the static extend() method.

public isClassExtendedWith()

public isClassExtendedWith(string $name): boolean 

isClassExtendedWith checks if extendable class is extended with a behavior object

public isClassInstanceOf()

public isClassInstanceOf($interface): bool 

isClassInstanceOf checks if the class implements the supplied interface methods.

public methodExists()

public methodExists(string $name): boolean 

methodExists checks if a method exists, extension equivalent of method_exists()

public propertyExists()

public propertyExists(string $name): boolean 

propertyExists checks if a property exists, extension equivalent of property_exists()

Protected Methods

protected extendableIsAccessible()

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

extendableIsAccessible checks if a property is accessible, property equivalent of is_callable()

protected extendableIsSettingDynamicProperty()

protected extendableIsSettingDynamicProperty(): bool 

extendableIsSettingDynamicProperty returns true if a dynamic property action is taking place

protected extensionExtractImplements()

protected extensionExtractImplements(): array 

extensionExtractImplements will return classes to implement.

protected extensionExtractMethods()

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

extensionExtractMethods extracts the available methods from a behavior and adds it to the list of callable methods

protected getExtendableMethodFromDynamicMethods()

protected getExtendableMethodFromDynamicMethods($name): callable|null 

protected getExtendableMethodFromExtensions()

protected getExtendableMethodFromExtensions($name): array|null