Building an object to array hydrator
This recipe is the converse of the Creating an array to object hydrator recipe. In this case, we need to pull values from object properties and return an associative array where the key will be the column name.
How to do it...
- For this illustration we will build upon the
Application\Generic\Hydrator\GetSet
class defined in the previous recipe:namespace Application\Generic\Hydrator; class GetSet { // code }
- After the
hydrate()
method defined in the previous recipe, we define anextract()
method, which takes an object as an argument. The logic is similar to that used withhydrate()
, except this time we're searching forgetXXX()
methods. Again,preg_match()
is used to match the method prefix and its suffix, which ...
Get PHP 7 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.