DIContainerTrait

trait atk4\core\DIContainerTrait
A class with this trait will have setDefaults() method that can
be passed list of default properties.
$view->setDefaults([‘ui’ => ‘segment’]);

Typically you would want to do that inside your constructor. The
default handling of the properties is:

- only apply properties that are defined
- only set property if it’s current value is null
- ignore defaults that have null value
- if existing property and default have array, then both arrays will be merged

Several classes may opt to extend setDefaults, for example in Agile UI
setDefaults is extended to support classes and content:

$segment->setDefaults([‘Hello There’, ‘red’, ‘ui’=>’segment’]);

WARNING: Do not use this trait unless you have a lot of properties
to inject. Also follow the guidelines on

Relying on this trait excessively may cause anger management issues to
some code reviewers.
Source:vendor/atk4/core/src/DIContainerTrait.php#31

Properties

public static property atk4\core\DIContainerTrait::$_DIContainerTrait
Check this property to see if trait is present in the object.
Source:vendor/atk4/core/src/DIContainerTrait.php#38
Type:bool

Methods

public atk4\core\DIContainerTrait::setDefaults($properties=[], $passively=false)
Call from __construct() to initialize the properties allowing
developer to pass Dependency Injector Container.
Source:

vendor/atk4/core/src/DIContainerTrait.php#47

Parameters:
  • $properties (array)
  • $passively (bool) if true, existing non-null argument values will be kept
protected atk4\core\DIContainerTrait::setMissingProperty($key, $value)
Sets object property.
Throws exception.
Source:

vendor/atk4/core/src/DIContainerTrait.php#76

Parameters:
  • $key (mixed)
  • $value (mixed)