Factory class

Framework\Factories\Factory

Class Factory.

Defined in libraries/factories/src/Factory.php

Properties #

$classes
All class objects set in the current Factory.
$factories
Factory instances.

$classes

protected array $classes = array ( )

All class objects set in the current Factory.

$factories

protected static array $factories = array ( )

Factory instances.

Methods #

get()
Get an object based in the FQCN.
getFactory()
Get (existing or created) Factory instance based on a custom name.
getOrNew()
Try to get an existing class instance based on FQCN. If it is not set, create a new instance and return it.
new()
Create a new object based on the FQCN.
set()
Set a new object to the list of classes set.

get()

public function get(string $fqcn): ?object

Get an object based in the FQCN.

Parameters
  • string $fqcn - The Full Qualified Class Name
Returns ?object - The FQCN object or null if it was not set

getFactory()

public static function getFactory(string $name = 'default'): \Framework\Factories\Factory

Get (existing or created) Factory instance based on a custom name.

Parameters
  • string $name - The Factory name
Returns \Framework\Factories\Factory - The Factory instance

getOrNew()

public function getOrNew(string $fqcn, array $construct = array ( )): object

Try to get an existing class instance based on FQCN. If it is not set, create a new instance and return it.

Parameters
  • string $fqcn - The Full Qualified Class Name
  • array $construct - Class constructor arguments
Returns object - The existing or created object

new()

public function new(string $fqcn, array $construct = array ( )): object

Create a new object based on the FQCN.

This method will replace the class instance.

Parameters
  • string $fqcn - The Full Qualified Class Name
  • array $construct - Class constructor arguments
Returns object - The created object

set()

public function set(object $object): static

Set a new object to the list of classes set.

Parameters
  • object $object - A object
Returns static