https://github.com/oppodelldog/yield-sample
some exmaple for using PHP - yield
https://github.com/oppodelldog/yield-sample
Last synced: 3 months ago
JSON representation
some exmaple for using PHP - yield
- Host: GitHub
- URL: https://github.com/oppodelldog/yield-sample
- Owner: Oppodelldog
- Created: 2019-12-11T22:01:19.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-11T22:01:43.000Z (over 5 years ago)
- Last Synced: 2025-01-02T19:52:48.402Z (5 months ago)
- Language: PHP
- Size: 1.95 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Example for PHP **yield**
Recently I stumbled over the PHP keyword **yield** and wanted to
try it out.**So here's a concrete use case to use yield**
1. Assume there's a Repository that returns a list of items.
2. Each items also is defined as an array.
3. Assume you want to convert the raw array data into some ModelDive into the code [here](index.php)
The use of yield here is to compose an enhanced Repository ```GeneratorItemRepository``` that returns a List of DataModels instead of a list of arrays.
To achieve this the new Repository calls the appropriate original function to get the raw data, but then, **on the fly**, it generates
Data Models from the raw data while it is accessed in a **foreach** iteration.