Skip to content

Wiki Cls

Danijel Galić edited this page Jan 23, 2024 · 1 revision
final class \FireHub\Core\Support\LowLevel\Cls()

Important

This class is marked as final.

### Class low-level proxy class

Class allows you to obtain information about classes.

This class was created by Danijel Galić <danijel.galic@outlook.com>
Copyright: 2024 FireHub Web Application Framework
License: <https://opensource.org/licenses/OSL-3.0> OSL Open Source License version 3
Version: GIT: $Id$ Blob checksum.

Fully Qualified Class Name:  \FireHub\Core\Support\LowLevel\Cls
Source code:  view source code
Blame:  view blame
History:  view history

Methods

Type Name Title
public static isClass ### Checks if class name exists
public static isInterface ### Checks if interface name exists
public static isEnum ### Checks if enum name exists
public static isTrait ### Checks if trait name exist
public static alias ### Creates an alias for a class
public static properties ### Gets the class public properties and their default values
inherited public static methodExist ### Checks if the class method exists
inherited public static propertyExist ### Checks if the object or class has a property
inherited public static ofClass ### Checks whether the object or class is of a given type or subtype
inherited public static subClassOf ### Checks if class has this class as one of its parents or implements it
inherited public static methods ### Gets the class or object methods names
inherited public static parentClass ### Retrieves the parent class name for an object or class
inherited public static parents ### Return the parent classes of the given class
inherited public static implements ### Return the interfaces which are implemented by the given class or interface
inherited public static uses ### Return the traits used by the given class
public static Cls::isClass(string $name, bool $autoload = true):bool

### Checks if class name exists

This method checks whether the given class has been defined.

Source code:  view source code
Blame:  view blame

Parameters

  • string $name - class-string The class name.
  • bool $autoload = true - [optional] Whether to autoload if not already loaded.

Returns

  • bool - True if class exist, false otherwise.
public static Cls::isInterface(string $name, bool $autoload = true):bool

### Checks if interface name exists

Checks if the given interface has been defined.

Source code:  view source code
Blame:  view blame

Parameters

  • string $name - class-string The interface name.
  • bool $autoload = true - [optional] Whether to autoload if not already loaded.

Returns

  • bool - True if the interface exists, false otherwise.
public static Cls::isEnum(string $name, bool $autoload = true):bool

### Checks if enum name exists

This method checks whether the given enum has been defined.

Source code:  view source code
Blame:  view blame

Parameters

  • string $name - class-string The enum name.
  • bool $autoload = true - [optional] Whether to autoload if not already loaded.

Returns

  • bool - True if enum exists, false otherwise.
public static Cls::isTrait(string $name, bool $autoload = true):bool

### Checks if trait name exist

Source code:  view source code
Blame:  view blame

Parameters

  • string $name - class-string The trait name.
  • bool $autoload = true - [optional] Whether to autoload if not already loaded.

Returns

  • bool - True if trait exists, false otherwise.
public static Cls::alias(string $class, string $alias, bool $autoload = true):true

Note

Class names are case-insensitive in PHP, and this is reflected in this function. Aliases created by Cls#alias() are declared in lowercase. This means that for a class MyClass, the [[Cls#alias('MyClass', 'MyClassAlias')]] call will declare a new class alias named myclassalias.

### Creates an alias for a class

Creates an alias named alias based on the user-defined class. The aliased class is exactly the same as the original class.

Source code:  view source code
Blame:  view blame

Parameters

  • string $class - class-string The original class.
  • string $alias - class-string The alias name for the class.
  • bool $autoload = true - [optional] Whether to autoload if the original class is not found.

Throws

  • \Error - If failed to alias the class.

Returns

  • true - True on success.
public static Cls::properties(string $class):array

Note

The result depends on the current scope.> [!NOTE] Using this function will use any registered autoloaders if the class is not already known.

### Gets the class public properties and their default values

Source code:  view source code
Blame:  view blame

Parameters

  • string $class - class-string The class name.

Throws

  • \Error - If $class is not valid class name.

Returns

  • array - array<array-key, mixed> Returns an associative array of declared properties visible from the current scope, with their default value.
public static ClsObj::methodExist(string|object $object_or_class, string $method):bool

Note

Using this function will use any registered autoloaders if the class is not already known.

### Checks if the class method exists

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object An object instance or a class name.
  • string $method - non-empty-string The method name.

Returns

  • bool - True if the method given by method has been defined for the given object_or_class, false otherwise.
final public static ClsObj::propertyExist(string|object $object_or_class, string $property):bool

Important

This method is marked as final.

Note

As opposed with isset(), ClsObj#propertyExist() returns true even if the property has the value null.> [!NOTE] This method cannot detect properties that are magically accessible using the __get magic method.> [!NOTE] Using this function will use any registered autoloaders if the class is not already known.

### Checks if the object or class has a property

This method checks if the given property exists in the specified class.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object The class name or an object of the class to test for.
  • string $property - non-empty-string The name of the property.

Throws

  • \Error - If there was an error trying to get property.

Returns

  • bool - True if the property exists, false if it doesn't exist.
public static ClsObj::ofClass(string|object $object_or_class, string $class, bool $autoload = true):bool

### Checks whether the object or class is of a given type or subtype

Checks if the given $object_or_class is of this object type or has this object type as one of its supertypes.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object A class name or an object instance.
  • string $class - The class or interface name.
  • bool $autoload = true - _[optional] Whether to allow this function to load the class automatically through the _autoload magic method.

Returns

  • bool - True if the object is of this object type or has this object type as one of its supertypes, false otherwise.
public static ClsObj::subClassOf(string|object $object_or_class, string $class, bool $autoload = true):bool

### Checks if class has this class as one of its parents or implements it

Checks if the given object_or_class has the class $class as one of its parents or implements it.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object The tested class. No error is generated if the class does not exist.
  • string $class - The class or interface name.
  • bool $autoload = true - _[optional] Whether to allow this function to load the class automatically through the _autoload magic method.

Returns

  • bool - True if the object is of this object or lass type or has this object type as one of its supertypes, false otherwise.
final public static ClsObj::methods(string|object $object_or_class):array

Important

This method is marked as final.

Note

The result depends on the current scope.

### Gets the class or object methods names

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object The class name or an object instance.

Throws

  • \TypeError - If $object_or_class is not an object or a valid class name.

Returns

  • array - array Returns an array of method names defined for the class.
final public static ClsObj::parentClass(string|object $object_or_class):string|false

Important

This method is marked as final.

### Retrieves the parent class name for an object or class

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object The tested object or class name. This parameter is optional if called from the object's method.

Returns

  • string or false - class-string|false The name of the parent class for the class that $object_or_class is an instance or the name, or false if object_or_class doesn't have a parent.
final public static ClsObj::parents(string|object $object_or_class, bool $autoload = true):array

Important

This method is marked as final.

### Return the parent classes of the given class

This function returns an array with the name of the parent classes of the given object_or_class.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object An object (class instance) or a string (class or interface name).
  • bool $autoload = true - _[optional] Whether to allow this function to load the class automatically through the _autoload magic method.

Throws

  • \Error - If $object_or_class does not exist and could not be loaded.

Returns

  • array - array<string, class-string> An array on success.
final public static ClsObj::implements(string|object $object_or_class, bool $autoload = true):array

Important

This method is marked as final.

### Return the interfaces which are implemented by the given class or interface

This function returns an array with the names of the interfaces that the given object_or_class and its parents implement.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object An object (class instance) or a string (class or interface name).
  • bool $autoload = true - _[optional] Whether to allow this function to load the class automatically through the _autoload magic method.

Throws

  • \Error - If $object_or_class does not exist and could not be loaded.

Returns

  • array - array<string, class-string> An array.
final public static ClsObj::uses(string|object $object_or_class, bool $autoload = true):array

Important

This method is marked as final.

### Return the traits used by the given class

This function returns an array with the names of the traits that the given object_or_class uses. This does, however, not include any traits used by a parent class.

Source code:  view source code
Blame:  view blame

Parameters

  • string or object $object_or_class - class-string|object An object (class instance) or a string (class or interface name).
  • bool $autoload = true - _[optional] Whether to allow this function to load the class automatically through the _autoload magic method.

Throws

  • \Error - If $object_or_class does not exist and could not be loaded.

Returns

  • array - array<string, class-string> An array.
Clone this wiki locally