PHP Class 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.
Mostrar archivo Open project: vanilla/vanilla

Protected Properties

Property Type Description
$_Dependencies The property dependancies for the factory.
$_Objects The object definitions for the factory.

Public Methods

Method Description
__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.

Protected Methods

Method Description
_instantiateObject ( $Alias, string $ClassName, array $Args = null ) Instantiate a new object.

Private Methods

Method Description
setDependancies ( $Alias, $Object )

Method Details

__construct() public method

public __construct ( )

_instantiateObject() protected method

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() public method

Get all currently defined factories
public all ( ) : array
return array

cleanup() public method

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

exists() public method

Checks whether or not a factory alias exists.
public exists ( string $Alias ) : boolean
$Alias string The alias of the factory to check for.
return boolean Whether or not a factory definintion exists.

factory() public method

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() public method

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() public method

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() public method

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

uninstallDependency() public method

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.

Property Details

$_Dependencies protected_oe property

The property dependancies for the factory.
protected $_Dependencies

$_Objects protected_oe property

The object definitions for the factory.
protected $_Objects