class FeedCollection extends Collection implements CollectionInterface, FeedsInterface, Countable, ArrayAccess, IteratorAggregate

Feed Collection class

Constants

DEFAULT_ITEMS_PER_PAGE

Properties

protected array $data Collection items data from Collection
protected array $keyMaps Item key mappings
protected string $baseUrl Feed base url
protected array|string $params Url params
protected string|null $itemsKey Feed items key
protected string $pageKey Array key in params
protected string|null $perPageKey Items per page array key

Methods

__construct(string|null $baseUrl = null, $params = [], string|null $itemsKey = null, string|null $pageKey = null, string|null $perPageKey = null)

Constructor

static Collection
create(array $data)

Create colleciton

static Collection
createFromFile(string $fileName, string|null $root = null, array|null $vars = null)

Create colection form json file

ArrayIterator
getIterator()

Return iterator

bool
has(string $key)

Return true if key exists in collection

bool
offsetExists(string $key)

Return true if key exists in collection

union(array $data)

Union arrays

replace(array $replacement)

Replace array

mixed
offsetGet(string $key)

Get item

void
offsetSet(string $key, mixed $value)

Set item

void
offsetUnset(string $key)

Remove item

remove(string $key)

Remove item

void
removeEmptyItems()

Remove empy items

integer
count()

Return collection items count.

void
setBooleanValue(string $path, integer|string $value)

Set bool value

void
setValue(string $path, mixed $value)

Set item value by path

void
merge(string $key, array $data, bool $recursive = false)

Merge collection items

void
mergeItems(array $data, bool $recursive = false)

Merge all collection items

Collection
set(string $key, mixed $value)

Set item value in collection

void
add(string $key, mixed $value)

Add item to collection

bool
push(string $key, mixed $value, string|null $subKey = null)

Push value to collection

bool
prepend(string $key, mixed $value, string|null $subKey = null)

Add value to begining of collection array

withData(array $data)

Set collection data

array
slice(array|string $keys)

Slice collecion by keys

array
toArray()

Return collection array

bool
isEmpty(string $key)

Return true if key exists and value not empty in collection

getCollection(string $key)

Get collection item

mixed
get(string $key, mixed $default = null)

Get value from collection

bool
getBool(string $key, bool|null $default = null)

Get boolean value

string|null
getString(string $key, string|null $default = null)

Get text value

int|null
getInt(string $key, int|null $default = null)

Get int value

float|null
getFloat(string $key, float|null $default = null)

Get float value

array
getArray(string $key, mixed $default = null)

Return array values

void
clear()

Clear collection data

Collection
copy()

Clone object

mixed
__get(string $key)

Get value

__set(string $key, mixed $value)

Set value

mixed
getByPath(string $path, mixed $default = null)

Get value by path

bool
addField(string $path, mixed $value)

Add value

array
getItems(bool $keyMaps = true)

Return feed items array

array|null
findItem(string $key, $value, int|null $page = null, int|null $perPage = null)

Find feed item

pageKey(string|null $key)

Set page array key for params array

string|null
getPageKey()

Get pake key

perPageKey(string|null $key)

Set per page array key for params array

baseUrl(string $url)

Set feed base url

params(array|string $params)

Set params

itemsKey(string|null $key)

Set items key

FeedCollection
fetch(int|null $page = null, int|null $perPage = Self::DEFAULT_ITEMS_PER_PAGE)

Fetch feed

void
setPage(int $page)

Set feed current page

void
setPerPage(int $perPage)

Set feed items per page

string
getUrl()

Get full url

string
getBaseUrl()

Get base url

string|null
getItemsKey()

Get items key

array|string
getUrlParams()

Get url params

array|null
getItemsArray()

Get items array

mixed
getItem(integer $index, bool $keyMaps = true)

Get feed item

void
setKeyMaps(array $keyMaps)

Set key maps

mapKey(string $key, mixed $mapTo)

Change array key

array
applyKeyMaps(array|null $items = null)

Change item array keys

array
transformItem(array $item)

Transform item

Details

at line 81
__construct(string|null $baseUrl = null, $params = [], string|null $itemsKey = null, string|null $pageKey = null, string|null $perPageKey = null)

Constructor

@param string|null $baseUrl

Parameters

string|null $baseUrl
$params
string|null $itemsKey
string|null $pageKey
string|null $perPageKey

in Collection at line 45
static Collection create(array $data)

Create colleciton

Parameters

array $data

Return Value

Collection

in Collection at line 58
static Collection createFromFile(string $fileName, string|null $root = null, array|null $vars = null)

Create colection form json file

Parameters

string $fileName
string|null $root
array|null $vars

Return Value

Collection

in Collection at line 73
ArrayIterator getIterator()

Return iterator

Return Value

ArrayIterator

in Collection at line 84
bool has(string $key)

Return true if key exists in collection

Parameters

string $key

Return Value

bool

in Collection at line 95
bool offsetExists(string $key)

Return true if key exists in collection

Parameters

string $key

Return Value

bool

in Collection at line 106
Collection union(array $data)

Union arrays

Parameters

array $data

Return Value

Collection

in Collection at line 119
Collection replace(array $replacement)

Replace array

Parameters

array $replacement

Return Value

Collection

in Collection at line 132
mixed offsetGet(string $key)

Get item

Parameters

string $key

Return Value

mixed

in Collection at line 144
void offsetSet(string $key, mixed $value)

Set item

Parameters

string $key
mixed $value

Return Value

void

in Collection at line 155
void offsetUnset(string $key)

Remove item

Parameters

string $key

Return Value

void

in Collection at line 166
Collection remove(string $key)

Remove item

Parameters

string $key

Return Value

Collection

in Collection at line 178
void removeEmptyItems()

Remove empy items

Return Value

void

in Collection at line 190
integer count()

Return collection items count.

Return Value

integer

in Collection at line 202
void setBooleanValue(string $path, integer|string $value)

Set bool value

Parameters

string $path
integer|string $value

Return Value

void

in Collection at line 221
void setValue(string $path, mixed $value)

Set item value by path

Parameters

string $path
mixed $value

Return Value

void

in Collection at line 234
void merge(string $key, array $data, bool $recursive = false)

Merge collection items

Parameters

string $key
array $data
bool $recursive

Return Value

void

in Collection at line 249
void mergeItems(array $data, bool $recursive = false)

Merge all collection items

Parameters

array $data
bool $recursive

Return Value

void

in Collection at line 261
Collection set(string $key, mixed $value)

Set item value in collection

Parameters

string $key Key Name
mixed $value Value

Return Value

Collection

in Collection at line 275
void add(string $key, mixed $value)

Add item to collection

Parameters

string $key key name
mixed $value

Return Value

void

in Collection at line 292
bool push(string $key, mixed $value, string|null $subKey = null)

Push value to collection

Parameters

string $key
mixed $value
string|null $subKey

Return Value

bool

in Collection at line 319
bool prepend(string $key, mixed $value, string|null $subKey = null)

Add value to begining of collection array

Parameters

string $key
mixed $value
string|null $subKey

Return Value

bool

in Collection at line 343
Collection withData(array $data)

Set collection data

Parameters

array $data

Return Value

Collection

in Collection at line 356
array slice(array|string $keys)

Slice collecion by keys

Parameters

array|string $keys

Return Value

array

in Collection at line 366
array toArray()

Return collection array

Return Value

array

in Collection at line 377
bool isEmpty(string $key)

Return true if key exists and value not empty in collection

Parameters

string $key

Return Value

bool

in Collection at line 388
Collection getCollection(string $key)

Get collection item

Parameters

string $key

Return Value

Collection

in Collection at line 400
mixed get(string $key, mixed $default = null)

Get value from collection

Parameters

string $key Name
mixed $default If key not exists return default value

Return Value

mixed

in Collection at line 412
bool getBool(string $key, bool|null $default = null)

Get boolean value

Parameters

string $key
bool|null $default

Return Value

bool

in Collection at line 424
string|null getString(string $key, string|null $default = null)

Get text value

Parameters

string $key
string|null $default

Return Value

string|null

in Collection at line 438
int|null getInt(string $key, int|null $default = null)

Get int value

Parameters

string $key
int|null $default

Return Value

int|null

in Collection at line 452
float|null getFloat(string $key, float|null $default = null)

Get float value

Parameters

string $key
float|null $default

Return Value

float|null

in Collection at line 466
array getArray(string $key, mixed $default = null)

Return array values

Parameters

string $key
mixed $default

Return Value

array

in Collection at line 478
void clear()

Clear collection data

Return Value

void

in Collection at line 488
Collection copy()

Clone object

Return Value

Collection

in Collection at line 499
mixed __get(string $key)

Get value

Parameters

string $key

Return Value

mixed

in Collection at line 510
__set(string $key, mixed $value)

Set value

Parameters

string $key
mixed $value

in Collection at line 522
mixed getByPath(string $path, mixed $default = null)

Get value by path

Parameters

string $path
mixed $default

Return Value

mixed

in Collection at line 536
bool addField(string $path, mixed $value)

Add value

Parameters

string $path
mixed $value

Return Value

bool

at line 309
array getItems(bool $keyMaps = true)

Return feed items array

Parameters

bool $keyMaps

Return Value

array

at line 107
array|null findItem(string $key, $value, int|null $page = null, int|null $perPage = null)

Find feed item

Parameters

string $key
$value
int|null $page
int|null $perPage

Return Value

array|null

at line 129
FeedCollection pageKey(string|null $key)

Set page array key for params array

Parameters

string|null $key

Return Value

FeedCollection

at line 141
string|null getPageKey()

Get pake key

Return Value

string|null

at line 152
FeedCollection perPageKey(string|null $key)

Set per page array key for params array

Parameters

string|null $key

Return Value

FeedCollection

at line 165
FeedCollection baseUrl(string $url)

Set feed base url

Parameters

string $url

Return Value

FeedCollection

at line 178
FeedCollection params(array|string $params)

Set params

Parameters

array|string $params

Return Value

FeedCollection

at line 191
FeedCollection itemsKey(string|null $key)

Set items key

Parameters

string|null $key

Return Value

FeedCollection

at line 205
FeedCollection fetch(int|null $page = null, int|null $perPage = Self::DEFAULT_ITEMS_PER_PAGE)

Fetch feed

Parameters

int|null $page
int|null $perPage

Return Value

FeedCollection

at line 231
void setPage(int $page)

Set feed current page

Parameters

int $page

Return Value

void

at line 244
void setPerPage(int $perPage)

Set feed items per page

Parameters

int $perPage

Return Value

void

at line 256
string getUrl()

Get full url

Return Value

string

at line 278
string getBaseUrl()

Get base url

Return Value

string

at line 288
string|null getItemsKey()

Get items key

Return Value

string|null

at line 298
array|string getUrlParams()

Get url params

Return Value

array|string

at line 321
protected array|null getItemsArray()

Get items array

Return Value

array|null

at line 337
mixed getItem(integer $index, bool $keyMaps = true)

Get feed item

Parameters

integer $index
bool $keyMaps

Return Value

mixed

at line 351
void setKeyMaps(array $keyMaps)

Set key maps

Parameters

array $keyMaps

Return Value

void

at line 363
FeedCollection mapKey(string $key, mixed $mapTo)

Change array key

Parameters

string $key
mixed $mapTo

Return Value

FeedCollection

at line 376
array applyKeyMaps(array|null $items = null)

Change item array keys

Parameters

array|null $items

Return Value

array

at line 393
protected array transformItem(array $item)

Transform item

Parameters

array $item

Return Value

array