Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types 2.0 - Allow extract from ArrayAcces interface #73

Open
slischka opened this issue Nov 6, 2020 · 4 comments
Open

Types 2.0 - Allow extract from ArrayAcces interface #73

slischka opened this issue Nov 6, 2020 · 4 comments
Labels
2.0 Types 2.0

Comments

@slischka
Copy link
Contributor

slischka commented Nov 6, 2020

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
@slischka slischka added the 2.0 Types 2.0 label Nov 6, 2020
@slischka slischka changed the title Types 2.0 RFC - Allow extract from ArrayAcces interface Types 2.0 - Allow extract from ArrayAcces interface Nov 7, 2020
@mstrouhal
Copy link
Member

Why was this closed?

@slischka
Copy link
Contributor Author

slischka commented Jul 11, 2023

IDK :D But this would be nice.
I think I can prepare PR.

@mstrouhal
Copy link
Member

Could you, please?

@mstrouhal mstrouhal reopened this Jul 11, 2023
@slischka
Copy link
Contributor Author

It's already working...

/**
	 * @param array<mixed>|\ArrayAccess<mixed, mixed> $data
	 * @return self
	 * @throws \SmartEmailing\Types\InvalidTypeException
	 */
	public static function extract(
		$data,
		string $key
	) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0 Types 2.0
Projects
None yet
Development

No branches or pull requests

2 participants