Skip to content

Types 2.0 - Allow extract from ArrayAcces interface #73

@slischka

Description

@slischka

Extract values should be also possile from objects implementing ArrayAccess.

BC break: No
New feature: Yes

If you implement own collection or you want to extract values maybe from \Nette\Database\IRow. First you have to serialize object to array then you can extract values from array.

Example:

/** @var Nette\Database\Table\ActiveRow $databaseRow */
$databaseRow = $this->repository->fetch();

$array = iterator_to_array($databaseRow); // or $databaseRow->toArray()

$id = PrimitiveTypes::extractInt($array, 'id');

should be simplified to:

/** @var Nette\Database\Table\ActiveRow $databaseRow */
$databaseRow = $this->repository->fetch();

$id = PrimitiveTypes::extractInt($databaseRow, 'id');

So exract method should look like:

final public static function extractInt(array|ArrayAccess $data, string $key): int; // PHP 8.0 syntax

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.0Types 2.0

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions