anterior  
índice  
siguiente  
Updated 2012-10-02 - Version ZF 2.0.3

Zend\Stdlib\Hydrator

Hydration is the act of populating an object from a set of data.

The Hydrator is a simple component to provide mechanisms both for hydrating objects, as well as extracting data sets from them.

The component consists of an interface, and several implementations for common use cases.

HydratorInterface

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
namespace Zend\Stdlib\Hydrator;

interface HydratorInterface
{
    /**
     * Extract values from an object
     *
     * @param  object $object
     * @return array
     */
    public function extract($object);

    /**
     * Hydrate $object with the provided $data.
     *
     * @param  array $data
     * @param  object $object
     * @return void
     */
    public function hydrate(array $data, $object);
}

Usage

Usage is quite simple: simply instantiate the hydrator, and then pass information to it.

1
2
3
4
5
6
7
8
9
use Zend\Stdlib\Hydrator;
$hydrator = new Hydrator\ArraySerializable();

$object = new ArrayObject(array());

$hydrator->hydrate($someData, $object);

// or, if the object has data we want as an array:
$data = $hydrator->extract($object);

Available Implementations

  • Zend\Stdlib\Hydrator\ArraySerializable

    Follows the definition of ArrayObject. Objects must implement either the the exchangeArray() or populate() methods to support hydration, and the getArrayCopy() method to support extraction.

  • Zend\Stdlib\Hydrator\ClassMethods

    Any data key matching a setter method will be called in order to hydrate; any method matching a getter method will be called for extraction.

  • Zend\Stdlib\Hydrator\ObjectProperty

    Any data key matching a publically accessible property will be hydrated; any public properties will be used for extration.

|

Contenidos

Tema anterior

Zend\ServiceManager Quick Start

Próximo tema

Introduction

Esta página

Nota: Es necesario estar conectado a tu cuenta GitHub para contribuir a la documentación.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Zend\Stdlib\Hydrator on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.