CollectionTrait¶
-
trait
atk4\core\
CollectionTrait
¶ - This trait makes it possible for you to add child objectsinto your object, but unlike “ContainerTrait” you can usemultiple collections stored as different array properties.This class does not offer automatic naming, so if you tryto add another element with same name, it will result inexception.
Source: vendor/atk4/core/src/CollectionTrait.php#14
Methods¶
-
public
atk4\core\CollectionTrait::
_addIntoCollection
($name, $object, $collection)¶ - Use this method trait like this:.function addField($name, $definition) {$field = $this->factory($definition, [], ‘\atk4\data\Field’);return $this->_addIntoCollection($name, $field, ‘fields’);}
Source: Parameters: - $name (string) Name that can be used to reference object
- $object (object) New element to add
- $collection (string) string String corresponding to the name of the property
Throws: Returns: object | mixed $obect
-
public
atk4\core\CollectionTrait::
_removeFromCollection
($name, $collection)¶ - Removes element from specified collection.
Source: Parameters: - $name (string)
- $collection (string)
Throws:
-
public
atk4\core\CollectionTrait::
_cloneCollection
($collection)¶ - Call this on collections after cloning object. This will clone all collectionelements (which are objects).
Source: Parameters: - $collection (string) to be cloned
-
public
atk4\core\CollectionTrait::
_hasInCollection
($name, $collection)¶ - Returns object from collection or false if object is not found.
Source: Parameters: - $name (string)
- $collection (string)
Returns: object | bool
-
public
atk4\core\CollectionTrait::
_getFromCollection
($name, $collection)¶ Source: Parameters: - $name (string)
- $collection (string)
Throws: Returns: object
-
protected
atk4\core\CollectionTrait::
_shorten_ml
($desired)¶ - Method used internally for shortening object namesIdentical implementation to ContainerTrait::_shortern.
Source: Parameters: - $desired (string) Desired name of new object.
Returns: string Shortened name of new object.