FactoryTrait¶
-
trait
atk4\core\
FactoryTrait
¶ Source: vendor/atk4/core/src/FactoryTrait.php#5
Properties¶
-
public static property
atk4\core\FactoryTrait::$
_factoryTrait
¶ - Check this property to see if trait is present in the object.
Source: vendor/atk4/core/src/FactoryTrait.php#12 Type: bool
Methods¶
-
public
atk4\core\FactoryTrait::
mergeSeeds
($seed, $seed2, ...$more_seeds)¶ - Given two seeds (or more) will merge them, prioritizing the first argument.If object is passed on either of arguments, then it will setDefaults() remainingarguments, respecting their positioning.See full documentation.
Source: Parameters: - $seed (array | object | mixed)
- $seed2 (array | object | mixed)
- …$more_seeds (array)
Returns: object | array if at least one seed is an object, will return object
-
public
atk4\core\FactoryTrait::
factory
($seed, $defaults=[], $prefix=null)¶ - Given a Seed (see doc) as a first argument, will create object of a correspondingclass, call constructor with numerical arguments of a seed and inject key/valuearguments.Argument $defaults has the same effect as the seed, but will not contain the class.Class is always determined by seed, except if you pass object into defaults.To learn more about mechanics of factory trait, see documentation
Source: Parameters: - $seed (mixed)
- $defaults (array)
- $prefix (string) Optional prefix for class name
Returns: object
-
public
atk4\core\FactoryTrait::
normalizeClassName
($name, $prefix=null)¶ - First normalize class name, then add specified prefix toclass name. Finally if $app is defined, and has method`normalizeClassNameApp` it will also get a chance toadd prefix.Rules observed, in order:- If class starts with “.” then prefixing is always done.- If class contains “" prefixing is never done.- If class (with prefix) exists, do prefix.- don’t prefix otherwise.Example: normalizeClassName(‘User’, ‘Model’) == ‘Model\User’;Example: normalizeClassName(Test\User::class, ‘Model’) == ‘Test\User’; # or as per “use”Example: normalizeClassName(‘Test/User’, ‘Model’) == ‘Model\Test\User’;Example: normalizeClassName(‘./User’, ‘Model’) == ‘Model\User’;Example: normalizeClassName(‘User’, ‘Model’) == ‘Model\User’; # if exists, ‘User’ otherwise# If used without namespace:Example: normalizeClassName(User::class, ‘Model’) == ‘Model\User’; # if exists, ‘User’ otherwise
Source: Parameters: - $name (string) Name of class
- $prefix (string) Optional prefix for class name
Returns: string Full, normalized class name