Documentation

ConfigItemsList extends ArrayList
in package

Represents a node in a configuration file.

This class extends the ArrayList class and provides functionality to represent a node in a configuration file.

Table of Contents

Constants

JsonSchema  = ['type' => 'array', 'items' => ['type' => 'object', 'patternProperties' => ['.*' => ['type' => ['number', 'string', 'boolean', 'object', 'array', 'null']]]]]
JSON schema

Properties

$data  : mixed
Data
$_file  : string

Methods

__construct()  : mixed
Constructor
Add()  : mixed
Adds item to array list
Append()  : void
Appends an items to array list
Clear()  : void
Clears an array list
Contains()  : bool
Check when item contains in internal array
Count()  : int
Returns internal array count
Delete()  : bool
Deletes an item
DeleteAt()  : array<string|int, mixed>
Deletes an item by index
Filter()  : ArrayList
Filters an array list by closure
Find()  : mixed
Finds an item by closure
First()  : mixed
Returns first item of array list
getIterator()  : ArrayListIterator
Gets an interator
IndexOf()  : int
Returns index by item
InsertAt()  : void
Inserts an item to specified index
Item()  : Config
Get Item by Index
jsonSerialize()  : array<string|int, mixed>
Return internal array for json conversion
Last()  : mixed
Returns last item of array list
Map()  : ArrayList
Executes an closure for every item and returns new array list
offsetExists()  : bool
Checks if offset exists in array list (used for ArrayAccess)
offsetGet()  : mixed
Returns an item at offset position
offsetSet()  : void
Sets an item by index (used for ArrayAccess)
offsetUnset()  : void
Deletes an item from array list by index (used for ArrayAccess)
Set()  : mixed
Sets an item to specified place in array list
Sort()  : void
Sorts an array list by using internal object field by key
SortByClosure()  : self
Sorts an array using sort function
ToArray()  : array<string|int, mixed>
Returns internal array
ToString()  : string
Returns string representation of array list

Constants

JsonSchema

JSON schema

public mixed JsonSchema = ['type' => 'array', 'items' => ['type' => 'object', 'patternProperties' => ['.*' => ['type' => ['number', 'string', 'boolean', 'object', 'array', 'null']]]]]

Properties

Methods

__construct()

Constructor

public __construct([array<string|int, mixed> $data = array() ][, string $file = '' ]) : mixed

Initializes a new instance of the ConfigItemsList class.

Parameters
$data : array<string|int, mixed> = array()

The data for the configuration items list.

$file : string = ''

The file associated with the configuration items list.

Add()

Adds item to array list

public Add(mixed $value) : mixed
Parameters
$value : mixed

The item to add.

Tags
example
$array = new ArrayList([1,2,3]);
$array->Add(5) and ArrayList then will contain [1,2,3,5]
Return values
mixed

The updated collection after adding the item.

Append()

Appends an items to array list

public Append(mixed $values) : void
Parameters
$values : mixed
Tags
example
$array = new ArrayList([1,2,3]);
$array->Append([5,6,7]) and ArrayList then will contain [1,2,3,5,6,7]

Clear()

Clears an array list

public Clear() : void
Tags
example
$array = new ArrayList([1,2,3]);
$array->Clear() and ArrayList then will not contain any item

Contains()

Check when item contains in internal array

public Contains(mixed $item) : bool
Parameters
$item : mixed
Tags
example
$array = new ArrayList([1,2,3]);
$array->Contains(3) returns true
$array->Contains(5) returns false
Return values
bool

Count()

Returns internal array count

public Count() : int
Tags
example
$array = new ArrayList([1,2,3]);
$array->Count() returns 3
Return values
int

Delete()

Deletes an item

public Delete(mixed $value) : bool
Parameters
$value : mixed

The item to delete.

Tags
example
$array = new ArrayList([1,2,3]);
$array->Delete(2) and ArrayList then will contain [1,3]
Return values
bool

True if the item was successfully deleted, false otherwise.

DeleteAt()

Deletes an item by index

public DeleteAt(int $index) : array<string|int, mixed>
Parameters
$index : int

The index of the item to delete.

Tags
example
$array = new ArrayList([1,2,3]);
$array->DeleteAt(2) and ArrayList then will contain [1,2]
Return values
array<string|int, mixed>

The updated collection after removing the item.

Filter()

Filters an array list by closure

public Filter(Closure $closure) : ArrayList
Parameters
$closure : Closure
Tags
example
$array = new ArrayList([1,2,3]);
$array->Filter(fn($v) => $v==3) returns [3]
Return values
ArrayList

Find()

Finds an item by closure

public Find(Closure $closure) : mixed
Parameters
$closure : Closure
Tags
example
$array = new ArrayList([1,2,3]);
$array->Filter(fn($v) => $v==3) returns 3

First()

Returns first item of array list

public First() : mixed
Tags
example
$array = new ArrayList([1,2,3]);
$array->First() returns 1

getIterator()

Gets an interator

public getIterator() : ArrayListIterator
Tags
example
For example

$array = new ArrayList();
foreach($array as $item) { ... }

or

foreach($array->getIterator() as $item) { ... }

Return values
ArrayListIterator

IndexOf()

Returns index by item

public IndexOf(mixed $item) : int
Parameters
$item : mixed
Tags
example
$array = new ArrayList([1,2,3]);
$array->IndexOf(3) returns 2
$array->IndexOf(5) returns -1
Return values
int

InsertAt()

Inserts an item to specified index

public InsertAt(mixed $value, int $toIndex) : void
Parameters
$value : mixed
$toIndex : int
Tags
example
$array = new ArrayList([1,2,3]);
$array->Insert(9, 1) and ArrayList then will contain [1,9,2,3]

Item()

Get Item by Index

public Item(int $index) : Config

Retrieves the configuration item at the specified index.

Parameters
$index : int

The index of the configuration item to retrieve.

Return values
Config

The configuration item at the specified index.

jsonSerialize()

Return internal array for json conversion

public jsonSerialize() : array<string|int, mixed>
Tags
example
$array = new ArrayList([1,2,3]);
$array->jsonSerialize() returns [1,2,3]
Return values
array<string|int, mixed>

Last()

Returns last item of array list

public Last() : mixed
Tags
example
$array = new ArrayList([1,2,3]);
$array->Last() returns 3

Map()

Executes an closure for every item and returns new array list

public Map(Closure $closure) : ArrayList
Parameters
$closure : Closure
Tags
example
$array = new ArrayList([1,2,3]);
$array->Filter(fn($v) => $v*2) returns [2,4,6]
Return values
ArrayList

offsetExists()

Checks if offset exists in array list (used for ArrayAccess)

public offsetExists(int $offset) : bool
Parameters
$offset : int
Tags
example
$array = new ArrayList([1,2,3]);
$array->offsetExists(2) returns true
$array->offsetExists(4) returns false
Return values
bool

offsetGet()

Returns an item at offset position

public offsetGet(int $offset) : mixed
Parameters
$offset : int
Tags
example
$array = new ArrayList([1,2,3]);
$array->offsetGet(2) returns 3
testFunction

testDataTableOffsetGet (used for ArrayAccess)

offsetSet()

Sets an item by index (used for ArrayAccess)

public offsetSet(int $offset, mixed $value) : void
Parameters
$offset : int
$value : mixed
Tags
example
$array = new ArrayList([1,2,3]);
$array->offsetSet(2,4) returns [1,4,3]

offsetUnset()

Deletes an item from array list by index (used for ArrayAccess)

public offsetUnset(int $offset) : void
Parameters
$offset : int
Tags
example
$array = new ArrayList([1,2,3]);
$array->offsetUnset(1) array goes to be [1,3]

Set()

Sets an item to specified place in array list

public Set(int $index, mixed $value) : mixed
Parameters
$index : int
$value : mixed
Tags
example
$array = new ArrayList([1,2,3]);
$array->Set(1, 6) and ArrayList then will contain [1,6,3]

Sort()

Sorts an array list by using internal object field by key

public Sort([string $k = null ][, int $sorttype = SORT_ASC ]) : void
Parameters
$k : string = null
$sorttype : int = SORT_ASC
Tags
example
$array = new ArrayList([
  (object)['field1' => 1, 'field2' => 2],
  (object)['field1' => 2, 'field2' => 3],
  (object)['field1' => 5, 'field2' => 1],
  (object)['field1' => 7, 'field2' => 1],
  (object)['field1' => 2, 'field2' => 3],
]);

$array->Sort('field1', SORT_ASC) returns

ArrayList([
  (object)['field1' => 1, 'field2' => 2],
  (object)['field1' => 2, 'field2' => 3],
  (object)['field1' => 2, 'field2' => 3],
  (object)['field1' => 5, 'field2' => 1],
  (object)['field1' => 7, 'field2' => 1],
])

$array->Sort('field1', SORT_DESC) returns

ArrayList([
  (object)['field1' => 7, 'field2' => 1],
  (object)['field1' => 5, 'field2' => 1],
  (object)['field1' => 2, 'field2' => 3],
  (object)['field1' => 2, 'field2' => 3],
  (object)['field1' => 1, 'field2' => 2],
])

SortByClosure()

Sorts an array using sort function

public SortByClosure(Closure $closure) : self
Parameters
$closure : Closure
Tags
example
$array = new ArrayList([3,2,1]);
$array->SortByClosure(fn($a, $b) => $a <=> $b) returns [1,2,3]

$array = new ArrayList([1,3,2]);
$array->SortByClosure(fn($a, $b) => $a > $b ? -1 : 1) returns [3,2,1]
Return values
self

ToArray()

Returns internal array

public ToArray() : array<string|int, mixed>
Tags
example
$array = new ArrayList([1,2,3]);
$array->ToArray() returns [1,2,3]
Return values
array<string|int, mixed>

ToString()

Returns string representation of array list

public ToString([string $splitter = ',' ]) : string
Parameters
$splitter : string = ','

The delimiter to use when joining elements.

Tags
example
$array = new ArrayList([1,2,3]);
$array->ToString() returns '1,2,3'
$array->ToString(';') returns '1;2;3'
Return values
string

The string representation of the object.


        
On this page

Search results