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.
Afficher le fichier Open project: vanilla/vanilla

Protected Properties

Свойство Type Description
$_Dependencies The property dependancies for the factory.
$_Objects The object definitions for the factory.

Méthodes publiques

Méthode 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.

Méthodes protégées

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

Private Methods

Méthode Description
setDependancies ( $Alias, $Object )

Method Details

__construct() public méthode

public __construct ( )

_instantiateObject() protected méthode

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 méthode

Get all currently defined factories
public all ( ) : array
Résultat array

cleanup() public méthode

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

exists() public méthode

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

factory() public méthode

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 méthode

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 méthode

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 méthode

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

uninstallDependency() public méthode

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