PHP Classes

File: kernel/coreCollections.php

Recommend this page to a friend!
  Packages of Christos Drogidis   TCollection   kernel/coreCollections.php   Download  
File: kernel/coreCollections.php
Role: Auxiliary script
Content type: text/plain
Description: Configuration script
Class: TCollection
Examples of processing collections of objects
Author: By
Last change:
Date: 3 months ago
Size: 16,912 bytes
 

Contents

Class file image Download
<?php /* dobu { file:id(`core412`),name(`collections`) { ascoos { logo {` __ _ ___ ___ ___ ___ ___ ___ ___ / _` |/ / / __/ _ \ / _ \ / / / _ \ / / | (_| |\ \| (_| (_) | (_) |\ \ | (_) |\ \ \__,_|/__/ \___\___/ \___/ /__/ \___/ /__/ `}, name {`ASCOOS OS`}, version {`1.0.0`}, category {`Web OS`}, subcategory {`Web5 / WebAI`}, description {`A Web 5.0 and Web AI Kernel for decentralized web and IoT applications`}, creator {`Drogidis Christos`}, site {`https://www.ascoos.com`}, issues {`https://issues.ascoos.com`}, support {`support@ascoos.com`}, license {`[Commercial] http://docs.ascoos.com/lics/ascoos/AGL.html`}, copyright {`Copyright (c) 2007 - 2026, AlexSoft Software.`}, }, project { package:langs { en {`Ascoos OS`}, el {`Ascoos OS`} }, subpackage:langs { en {`A simple, non-chainable collection class for managing items/objects.`}, el {`??? ????, ?? ????????? ????? ???????? ??? ?? ?????????? ????????????/????????????.`} }, category:langs { en {`Deep Core`}, el {`??????? ???????`} }, subcategory:langs { en {`Collections`}, el {`????????`} }, source {`aos/kernel/coreCollections.php`}, description:langs { en {`Lightweight collection that stores items in an internal array. Supports strict item type enforcement (instanceof check).`}, el {`??????? ??????? ??? ?????????? ??????????? ?? ??? ????????? ??????. ??????????? ??????? ??????? ????? ???????????? (??????? ?? instanceof).`} }, fileNo {`core412`}, version {`1.0.0`}, build {`16732`}, created {`2026-01-22 02:25:00`}, updated {`2026-01-22 11:13:23`}, author {`Christos Drogidis`}, authorSite {`https://www.ascoos.com`}, support {`support@ascoos.com`}, license {`AGL (ASCOOS General License)`}, since {`1.0.0`}, sincePHP {`8.4.0`} } } } */ /****************************************************************************** * @startcode TCollection *****************************************************************************/ /* dobu { class:id(`tcollection`),name(`TCollection`),extends(`TObject`),implements(`ArrayAccess, Countable, IteratorAggregate, JsonSerializable`),namespace(`Ascoos\OS\Kernel\Core\Collections`),hierarchy(`TObject, TCollection`),version(`1.0.0`),build(`16732`),since(`1.0.0`),sincePHP(`8.4.0`),license(`AGL (Ascoos General License)`) { category:langs { en {`Collections`}, el {`????????`} }, intro:langs { en {`A simple, non-chainable collection class for managing items/objects. Implements basic array-like operations with optional type checking`}, el {`????, ??-chainable ????? ???????? ??? ?????????? ?????????/????????????. ???????? ??????? ??????????? ????? array ?? ??????????? ?????? ?????.`} }, summary:langs { en {`Lightweight collection that stores items in an internal array.`}, el {`??????? ??????? ??? ?????????? ???????? ?? ????????? ??????.`} }, desc:langs { en {`Lightweight collection that stores items in an internal array. Supports strict item type enforcement (instanceof check). Does NOT use TObject's $properties for items storage.`}, el {`??????? ??????? ??? ?????????? ???????? ?? ????????? ??????. ??????????? ??????? ?????? ????? ????????? (instanceof). ??? ???????????? ?? $properties ??? TObject ??? ?????????? items.`} }, properties:active(`table {name,type,langs,default}`) { property:id(`items`),name(`$items`),access(`protected`),type(`array`),default(`[]`)langs { en {`Internal storage of collection items.`}, el {` ????????? ?????????? ??? ????????? ??? ????????.`} }, property:id(`itemtype`),name(`$itemType`),access(`protected`),type(`?string`),default(`NULL`),langs { en {`Optional class name for type strictness`}, el {`??????????? ????? ?????? ??? ??????? ????`} } }, methods:active(`idx,toc`) { method:id(`construct`),name(`__construct`),syntax(`__construct(array $initialItems = [], ?string $itemType = null, array $properties = [])`),return(`void`),langs { en {`Initialize the collection`}, el {`??????????? ?? ???????`} }, method:id(`add`),name(`add`),syntax(`add(mixed $item, mixed $key = null): void`),return(`void`),langs { en {`Add a single item to the collection`}, el {`????????? ??? ???????? ??? ???????`} }, method:id(`additems`),name(`addItems`),syntax(`addItems(array $items): void`),return(`void`),langs { en {`Add multiple items at once`}, el {`????????? ???????? ???????? ??????????`} }, method:id(`avgby`),name(`avgBy`),syntax(`avgBy(string $property): ?float`),return(`?float`),langs { en {`Calculates the average of a numeric property across all objects`}, el {`?????????? ??? ???????? ???? ??? ??????????? ????????? ?? ??? ?? ???????????`} }, method:id(`clear`),name(`clear`),syntax(`clear(): void`),return(`void`),langs { en {`Remove all items from the collection`}, el {`??????? ??? ?? ???????? ??? ?? ???????`} }, method:id(`count`),name(`count`),syntax(`count(): int`),return(`int`),langs { en {`Returns the number of items in the collection`}, el {`?????????? ??? ?????? ??? ????????? ??? ???????`} }, method:id(`countby`),name(`countBy`),syntax(`countBy(string $property): array`),return(`array`),langs { en {`Counts occurrences of each unique value for a property`}, el {`??????? ??? ?????????? ???? ????????? ????? ???? ?????????`} }, method:id(`diff`),name(`diff`),syntax(`diff(TCollection $other): array`),return(`array`),langs { en {`Returns objects present in this collection but not in $other`}, el {`?????????? ??????????? ??? ???????? ??? ???? ??? ??? $other`} }, method:id(`each`),name(`each`),syntax(`each(callable $callback): void`),return(`void`),langs { en {`Executes a callback on each object (side-effect only)`}, el {`??????? callback ?? ???? ??????????? (???? side-effect)`} }, method:id(`filter`),name(`filter`),syntax(`filter(callable $callback): array`),return(`array`),langs { en {`Filters objects based on a callback function`}, el {`????????? ??????????? ????? ?????????? callback`} }, method:id(`find`),name(`find`),syntax(`find(callable $callback, mixed $default = null): mixed`),return(`mixed`),langs { en {`Finds the first object matching the callback`}, el {`??????? ?? ????? ??????????? ??? ????????? ?? ?? callback`} }, method:id(`first`),name(`first`),syntax(`first(): mixed`),return(`mixed`),langs { en {`Returns the first item or null if empty`}, el {`?????????? ?? ????? ???????? ? null ?? ????? ?????`} }, method:id(`get`),name(`get`),syntax(`get(mixed $key, mixed $default = null): mixed`),return(`mixed`),langs { en {`Get item by key with optional default value`}, el {`?????????? ???????? ?? ???? ?? ?????? ?? ??????????? ????????????? ????`} }, method:id(`getiterator`),name(`getIterator`),syntax(`getIterator(): Traversable`),return(`Traversable`),langs { en {`Returns an iterator for the items`}, el {`?????????? iterator ??? ?? ????????`} }, method:id(`getitems`),name(`getItems`),syntax(`getItems(): array`),return(`array`),langs { en {`Returns all items as array (shallow copy)`}, el {`?????????? ??? ?? ???????? ?? ?????? (???? ?????????)`} }, method:id(`getitemtype`),name(`getItemType`),syntax(`getItemType(): ?string`),return(`?string`),langs { en {`Returns the current enforced item type (if any)`}, el {`?????????? ??? ???????? ???????????? ???? ????????? (?? ???????)`} }, method:id(`groupby`),name(`groupBy`),syntax(`groupBy(string $property): array`),return(`array`),langs { en {`Groups objects by a property value`}, el {`?????????? ??????????? ????? ????? ?????????`} }, method:id(`has`),name(`has`),syntax(`has(mixed $key): bool`),return(`bool`),langs { en {`Checks if a key exists in the collection`}, el {`??????? ?? ??????? ?????? ??? ???????`} }, method:id(`intersect`),name(`intersect`),syntax(`intersect(TCollection $other): array`),return(`array`),langs { en {`Returns objects present in both collections`}, el {`?????????? ??????????? ??? ???????? ??? ???? ??? ????????`} }, method:id(`isempty`),name(`isEmpty`),syntax(`isEmpty(): bool`),return(`bool`),langs { en {`Checks if the collection has no items`}, el {`??????? ?? ? ??????? ??? ???? ????????`} }, method:id(`jsonSerialize`),name(`jsonSerialize`),syntax(`jsonSerialize(): array`),return(`array`),langs { en {`Returns the items array for JSON encoding`}, el {`?????????? ??? ?????? ????????? ??? JSON ????????????`} }, method:id(`keyby`),name(`keyBy`),syntax(`keyBy(string $property): array`),return(`array`),langs { en {`Re-indexes the collection using a property as key`}, el {`?????-??????????? ?? ??????? ??????????????? ???????? ?? ??????`} }, method:id(`keys`),name(`keys`),syntax(`keys(): array`),return(`array`),langs { en {`Returns all keys/indexes of the collection`}, el {`?????????? ??? ?? ???????/??????? ??? ????????`} }, method:id(`last`),name(`last`),syntax(`last(): mixed`),return(`mixed`),langs { en {`Returns the last item or null if empty`}, el {`?????????? ?? ????????? ???????? ? null ?? ????? ?????`} }, method:id(`map`),name(`map`),syntax(`map(callable $callback): array`),return(`array`),langs { en {`Transforms each object using a callback function`}, el {` ?????????? ???? ??????????? ?? ???? ????????? callback`} }, method:id(`merge`),name(`merge`),syntax(`merge(TCollection $other): void`),return(`void`),langs { en {`Merges another collection into this one`}, el {`?????????? ???? ??????? ?? ?????`} }, method:id(`offsetexists`),name(`offsetExists`),syntax(`offsetExists(mixed $offset): bool`),return(`bool`),langs { en {`Check if offset exists (ArrayAccess)`}, el {`??????? ?? ??????? offset (ArrayAccess)`} }, method:id(`offsetget`),name(`offsetGet`),syntax(`offsetGet(mixed $offset): mixed`),return(`mixed`),langs { en {`Get value at offset (ArrayAccess)`}, el {`?????????? ???? ?? offset (ArrayAccess)`} }, method:id(`offsetset`),name(`offsetSet`),syntax(`offsetSet(mixed $offset, mixed $value): void`),return(`void`),langs { en {`Set value at offset (ArrayAccess)`}, el {`?????? ???? ?? offset (ArrayAccess)`} }, method:id(`offsetunset`),name(`offsetUnset`),syntax(`offsetUnset(mixed $offset): void`),return(`void`),langs { en {`Unset value at offset (ArrayAccess)`}, el {`??????? ???? ??? offset (ArrayAccess)`} }, method:id(`pluck`),name(`pluck`),syntax(`pluck(string $property): array`),return(`array`),langs { en {`Extracts a single property from all objects in the collection`}, el {`?????? ??? ???????????? ???????? ??? ??? ?? ??????????? ??? ????????`} }, method:id(`remove`),name(`remove`),syntax(`remove(mixed $key): void`),return(`void`),langs { en {`Remove item by key`}, el {`??????? ???????? ?? ???? ?? ??????`} }, method:id(`setitemtype`),name(`setItemType`),syntax(`setItemType(?string $type): void`),return(`void`),langs { en {`Set or change the enforced item type`}, el {`?????? ? ??????? ??? ???????????? ???? ?????????`} }, method:id(`sortby`),name(`sortBy`),syntax(`sortBy(string $property, string $direction = 'asc'): array`),return(`array`),langs { en {`Sorts objects by a property value`}, el {`????????? ??????????? ????? ????? ?????????`} }, method:id(`sortbydesc`),name(`sortByDesc`),syntax(`sortByDesc(string $property): array`),return(`array`),langs { en {`Sorts objects by a property in descending order`}, el {`????????? ??????????? ????? ????????? ???????? `} }, method:id(`sumby`),name(`sumBy`),syntax(`sumBy(string $property): float|int`),return(`float|int`),langs { en {`Calculates the total sum of a numeric property across all objects`}, el {`?????????? ?? ???????? ???????? ??????????? ????????? ?? ??? ?? ???????????`} }, method:id(`unique`),name(`unique`),syntax(`unique(): array`),return(`array`),langs { en {`Removes duplicate objects (strict comparison)`}, el {`??????? ????? ??????????? (??????? ????????)`} }, method:id(`uniqueby`),name(`uniqueBy`),syntax(`uniqueBy(string $property): array`),return(`array`),langs { en {`Returns unique objects based on a property value`}, el {`?????????? ???????? ??????????? ????? ????? ????????? `} }, method:id(`values`),name(`values`),syntax(`values(): array`),return(`array`),langs { en {` Returns all values as indexed array`}, el {`?????????? ???? ??? ????? ?? ?????????? ?????? `} } } } */ /****************************************************************************** * @endcode TCollection *****************************************************************************/ ?>