Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/4448'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed May 9, 2013
206 parents 2cd6240 + 3d722b0 + 58d95bc + c9c40bb + 5f29760 + 714d1a8 + 84b0297 + cbc5f03 + 76361f8 + e7209df + 87630e0 + df43daf + f7d6cbb + 7e2b798 + 3ed1ead + 87505b6 + c229265 + eb61c8f + efcb00e + 0a0842f + b6d0c88 + 7edee62 + 60ea64c + a08bcca + b40ec3e + 63172ed + 448f428 + 92a516a + 5ecbc99 + a2df21b + 4de87f2 + 7c259ec + a22bdcb + 084ad9f + 9414e5a + 489be93 + cb39e7e + 54a28dc + c9c769e + dda791d + 70d382a + 8bbad0e + 9321185 + 7ab35a6 + b93694e + 3ea7087 + 0fe3d3a + bd5e189 + d1cba17 + 8d75392 + 3fb5b55 + 6cb0ccb + 30aa565 + 8409977 + 8074ba0 + 8f92486 + 94860d1 + 05d33c4 + 425826b + f0e91f0 + e31468f + 7d2af87 + 2e4dc80 + 19d128f + 1b9e4b2 + 1c46483 + fdda3f2 + 595fcd1 + 213395c + 8e514a8 + 2f30186 + bb4ed65 + 132d5b6 + 030ff33 + f2f20f3 + a50e133 + 4c554ee + dbfb1b8 + ccab83f + 00b350f + 78945d0 + f0e5f4b + ceb7d8c + 9e124d1 + 3de5912 + b6a974a + 10a6438 + cb6c1e7 + 18afd6c + 3baf1bd + c800904 + f52dcb8 + 126ccb2 + e7d6206 + e2d24ab + ec1abfc + 290ea90 + 9f4ca1b + edaa760 + c4c0c95 + d21f055 + 5b18029 + e6b97af + 010fb36 + 64c7b8d + 636523e + 4cc2cd6 + e34098a + 16367cd + 943c77f + 8226e5b + 0b47726 + 3cd8a03 + cc4782c + 9c653a6 + 656dbe5 + 9bce1ba + 7dc18ca + 861130d + 2d2ffbd + 4f413a5 + 2e1067a + 1d082e4 + e8aeb79 + b562091 + ff2fdc3 + 4aa72c0 + 1bb67ac + cd015c8 + 5e89910 + 0c21258 + dd54faf + 57f9063 + b88ce2e + af68643 + 06cd3b4 + 2c71b71 + ee02c35 + 9456314 + 5a77a7b + e98a077 + 738f2e6 + cb1e63c + 736df07 + d0a0154 + 990523c + 78687de + a5b6e79 + 6e9dfe9 + e201a1c + d9b45ef + 76222ad + 16d67da + 1ab2258 + b81d711 + ed2e9bc + 61efe82 + f353ea5 + 1f02519 + 58c1fe8 + ed502d9 + 2defba6 + 4885013 + 06a8384 + 17d9eed + 3b21b5d + c62101c + 909ef34 + 13d376a + 8a75367 + 98a3cf5 + 270f2c4 + 3038cfa + 1112202 + c8fb359 + 8d37cd0 + 4d868a7 + 555cb91 + 7ac5858 + 8103f1f + 9fe9c96 + a3ecac6 + 10e77c1 + e0d3e13 + 19ad608 + e0d665c + 1a5b402 + 56ae12a + 9073fc1 + 2d5b32f + a8e6198 + 83e8f34 + 8248c0b + c9f0cd0 + 30eb247 + 6204c2f + c3855a9 + 4baf625 + dc26d92 + c989091 + bc6d8c5 + ec25337 + 6934141 + 18f8ecc + 5bede1d + 98d293c commit c382628
Show file tree
Hide file tree
Showing 10 changed files with 927 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/Hydrator/Aggregate/AggregateHydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Stdlib\Hydrator\Aggregate;

use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\Stdlib\Exception;
use Zend\Stdlib\Hydrator\Filter\FilterComposite;
use Zend\Stdlib\Hydrator\HydratorInterface;

/**
* Aggregate hydrator that composes multiple hydrators via events
*/
class AggregateHydrator implements HydratorInterface, EventManagerAwareInterface
{
const DEFAULT_PRIORITY = 1;

/**
* @var \Zend\EventManager\EventManagerInterface|null
*/
protected $eventManager;

/**
* Attaches the provided hydrator to the list of hydrators to be used while hydrating/extracting data
*
* @param \Zend\Stdlib\Hydrator\HydratorInterface $hydrator
* @param int $priority
*/
public function add(HydratorInterface $hydrator, $priority = self::DEFAULT_PRIORITY)
{
$this->getEventManager()->attachAggregate(new HydratorListener($hydrator), $priority);
}

/**
* {@inheritDoc}
*/
public function extract($object)
{
$event = new ExtractEvent($this, $object);

$this->getEventManager()->trigger($event);

return $event->getExtractedData();
}

/**
* {@inheritDoc}
*/
public function hydrate(array $data, $object)
{
$event = new HydrateEvent($this, $object, $data);

$this->getEventManager()->trigger($event);

return $event->getHydratedObject();
}

/**
* {@inheritDoc}
*/
public function setEventManager(EventManagerInterface $eventManager)
{
$eventManager->setIdentifiers(array(__CLASS__, get_class($this)));

$this->eventManager = $eventManager;
}

/**
* {@inheritDoc}
*/
public function getEventManager()
{
if (null === $this->eventManager) {
$this->setEventManager(new EventManager());
}

return $this->eventManager;
}
}
99 changes: 99 additions & 0 deletions src/Hydrator/Aggregate/ExtractEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Stdlib\Hydrator\Aggregate;


use Zend\EventManager\Event;

/**
* Event triggered when the {@see \Zend\Stdlib\Hydrator\Aggregate\AggregateHydrator} extracts
* data from an object
*/
class ExtractEvent extends Event
{
const EVENT_EXTRACT = 'extract';

/**
* {@inheritDoc}
*/
protected $name = self::EVENT_EXTRACT;

/**
* @var object
*/
protected $extractionObject;

/**
* @var array
*/
protected $extractedData = array();

/**
* @param object $target
* @param object $extractionObject
*/
public function __construct($target, $extractionObject)
{
$this->target = $target;
$this->extractionObject = $extractionObject;
}

/**
* Retrieves the object from which data is extracted
*
* @return object
*/
public function getExtractionObject()
{
return $this->extractionObject;
}

/**
* @param object $extractionObject
*
* @return void
*/
public function setExtractionObject($extractionObject)
{
$this->extractionObject = $extractionObject;
}

/**
* Retrieves the data that has been extracted
*
* @return array
*/
public function getExtractedData()
{
return $this->extractedData;
}

/**
* @param array $extractedData
*
* @return void
*/
public function setExtractedData(array $extractedData)
{
$this->extractedData = $extractedData;
}

/**
* Merge provided data with the extracted data
*
* @param array $additionalData
*
* @return void
*/
public function mergeExtractedData(array $additionalData)
{
$this->extractedData = array_merge($this->extractedData, $additionalData);
}
}
85 changes: 85 additions & 0 deletions src/Hydrator/Aggregate/HydrateEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Stdlib\Hydrator\Aggregate;


use Zend\EventManager\Event;

/**
* Event triggered when the {@see \Zend\Stdlib\Hydrator\Aggregate\AggregateHydrator} hydrates
* data into an object
*/
class HydrateEvent extends Event
{
const EVENT_HYDRATE = 'hydrate';

/**
* {@inheritDoc}
*/
protected $name = self::EVENT_HYDRATE;

/**
* @var object
*/
protected $hydratedObject;

/**
* @var array
*/
protected $hydrationData;

/**
* @param object $target
* @param object $hydratedObject
* @param array $hydrationData
*/
public function __construct($target, $hydratedObject, array $hydrationData)
{
$this->target = $target;
$this->hydratedObject = $hydratedObject;
$this->hydrationData = $hydrationData;
}

/**
* Retrieves the object that is being hydrated
*
* @return object
*/
public function getHydratedObject()
{
return $this->hydratedObject;
}

/**
* @param object $hydratedObject
*/
public function setHydratedObject($hydratedObject)
{
$this->hydratedObject = $hydratedObject;
}

/**
* Retrieves the data that is being used for hydration
*
* @return array
*/
public function getHydrationData()
{
return $this->hydrationData;
}

/**
* @param array $hydrationData
*/
public function setHydrationData(array $hydrationData)
{
$this->hydrationData = $hydrationData;
}
}
81 changes: 81 additions & 0 deletions src/Hydrator/Aggregate/HydratorListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Stdlib\Hydrator\Aggregate;


use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventManagerInterface;
use Zend\Stdlib\Hydrator\HydratorInterface;

/**
* Aggregate listener wrapping around a hydrator. Listens
* to {@see \Zend\Stdlib\Hydrator\Aggregate::EVENT_HYDRATE} and
* {@see \Zend\Stdlib\Hydrator\Aggregate::EVENT_EXTRACT}
*/
class HydratorListener extends AbstractListenerAggregate
{
/**
* @var \Zend\Stdlib\Hydrator\HydratorInterface
*/
protected $hydrator;

/**
* @param \Zend\Stdlib\Hydrator\HydratorInterface $hydrator
*/
public function __construct(HydratorInterface $hydrator)
{
$this->hydrator = $hydrator;
}

/**
* {@inheritDoc}
*/
public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach(HydrateEvent::EVENT_HYDRATE, array($this, 'onHydrate'));
$this->listeners[] = $events->attach(ExtractEvent::EVENT_EXTRACT, array($this, 'onExtract'));
}

/**
* Callback to be used when {@see \Zend\Stdlib\Hydrator\Aggregate\HydrateEvent::EVENT_HYDRATE} is triggered
*
* @param \Zend\Stdlib\Hydrator\Aggregate\HydrateEvent $event
*
* @return object
*
* @internal
*/
public function onHydrate(HydrateEvent $event)
{
$object = $this->hydrator->hydrate($event->getHydrationData(), $event->getHydratedObject());

$event->setHydratedObject($object);

return $object;
}

/**
* Callback to be used when {@see \Zend\Stdlib\Hydrator\Aggregate\ExtractEvent::EVENT_EXTRACT} is triggered
*
* @param \Zend\Stdlib\Hydrator\Aggregate\ExtractEvent $event
*
* @return array
*
* @internal
*/
public function onExtract(ExtractEvent $event)
{
$data = $this->hydrator->extract($event->getExtractionObject());

$event->mergeExtractedData($data);

return $data;
}
}
Loading

0 comments on commit c382628

Please sign in to comment.