PHP Класс Gdn_Factory, vanilla

A factory used to create most objects in the core library. If you have your own object that implements some base portion of the library you can install it in the factory make sure your own object has the same properties/methods as the core object and then install it into this factory.
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$_Dependencies The property dependancies for the factory.
$_Objects The object definitions for the factory.

Открытые методы

Метод Описание
__construct ( )
all ( ) : array Get all currently defined factories
cleanup ( ) Clean up the factory's objects
exists ( string $Alias ) : boolean Checks whether or not a factory alias exists.
factory ( $Alias, $Args = null ) Creates an object with mapped to the name.
install ( string $Alias, string $ClassName, string $Path = '', string $FactoryType = Gdn::FactorySingleton, $Data = null ) Install a class to the factory.
installDependency ( string $Alias, string $PropertyName, string $SourceAlias ) Install a dependency for the factory.
search ( string $search ) : array Search installed factories by fnmatch
uninstall ( string $Alias ) Uninstall a factory definition.
uninstallDependency ( string $Alias, string $PropertyName = null ) Uninstall a dependency definition.

Защищенные методы

Метод Описание
_instantiateObject ( $Alias, string $ClassName, array $Args = null ) Instantiate a new object.

Приватные методы

Метод Описание
setDependancies ( $Alias, $Object )

Описание методов

__construct() публичный Метод

public __construct ( )

_instantiateObject() защищенный Метод

Instantiate a new object.
protected _instantiateObject ( $Alias, string $ClassName, array $Args = null )
$ClassName string The name of the class to instantiate.
$Args array The arguments to pass to the constructor. Note: This function currently only supports a maximum of 8 arguments.

all() публичный Метод

Get all currently defined factories
public all ( ) : array
Результат array

cleanup() публичный Метод

Also calls 'Cleanup' on compatible instances.
public cleanup ( )

exists() публичный Метод

Checks whether or not a factory alias exists.
public exists ( string $Alias ) : boolean
$Alias string The alias of the factory to check for.
Результат boolean Whether or not a factory definintion exists.

factory() публичный Метод

Creates an object with mapped to the name.
public factory ( $Alias, $Args = null )
$Alias The class code of the object to create.
$Args The arguments to pass to the constructor of the object.

install() публичный Метод

Install a class to the factory.
public install ( string $Alias, string $ClassName, string $Path = '', string $FactoryType = Gdn::FactorySingleton, $Data = null )
$Alias string An alias for the class that will be used to retreive instances of it.
$ClassName string The actual name of the class.
$Path string The path to the class' file. You can prefix the path with ~ to start at the application root (PATH_ROOT).
$FactoryType string The way objects will be instantiated for the class. One of (Gdn::FactoryInstance, Gdn::FactoryPrototype, Gdn::FactorySingleton).
  • Gdn::FactoryInstance: A new instance of the class will be created when the factory is called.
  • Gdn::FactoryPrototype: A clone of a prototype will be created when the factory is called. The prototype must be passed into the $Data argument.
  • Gdn::FactorySingleton: A singleton instance, stored in the factory will be returned when the factory is called. The instance can be passed to the $Data argument on installation, or it will be lazy created when first accessed. You can also pass an array to $Data and it will be used as the arguments for the lazy construction.

installDependency() публичный Метод

This method provides support for simple dependency injection. When an object with dependencies is created then the factory will call inline{@link Gdn_Factory::Factory()} for each dependency and set the object properties before returning it. Those dependencies can also have their own dependencies which will all be set when the object is returned.
public installDependency ( string $Alias, string $PropertyName, string $SourceAlias )
$Alias string The alias of the class that will have the dependency.
$PropertyName string The name of the property on the class that will have the dependency.
$SourceAlias string The alias of the class that will provide the value of the property when objects are instantiated.

uninstall() публичный Метод

Uninstall a factory definition.
public uninstall ( string $Alias )
$Alias string The object alias to uninstall.

uninstallDependency() публичный Метод

Uninstall a dependency definition.
public uninstallDependency ( string $Alias, string $PropertyName = null )
$Alias string The object alias to uninstall the dependency for.
$PropertyName string The name of the property dependency to uninstall. Note: If $PropertyName is null then all of the dependencies will be uninstalled for $Alias.

Описание свойств

$_Dependencies защищенное свойство

The property dependancies for the factory.
protected $_Dependencies

$_Objects защищенное свойство

The object definitions for the factory.
protected $_Objects