Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Mvc / View / Http / CreateViewModelListener.php
blob8bffadb0f282bd1e5c935f28f558db5c2b6ff291
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Mvc\View\Http;
12 use Zend\EventManager\AbstractListenerAggregate;
13 use Zend\EventManager\EventManagerInterface as Events;
14 use Zend\Mvc\MvcEvent;
15 use Zend\Stdlib\ArrayUtils;
16 use Zend\View\Model\ViewModel;
18 class CreateViewModelListener extends AbstractListenerAggregate
20 /**
21 * {@inheritDoc}
23 public function attach(Events $events)
25 $this->listeners[] = $events->attach('dispatch', array($this, 'createViewModelFromArray'), -80);
26 $this->listeners[] = $events->attach('dispatch', array($this, 'createViewModelFromNull'), -80);
29 /**
30 * Inspect the result, and cast it to a ViewModel if an assoc array is detected
32 * @param MvcEvent $e
33 * @return void
35 public function createViewModelFromArray(MvcEvent $e)
37 $result = $e->getResult();
38 if (!ArrayUtils::hasStringKeys($result, true)) {
39 return;
42 $model = new ViewModel($result);
43 $e->setResult($model);
46 /**
47 * Inspect the result, and cast it to a ViewModel if null is detected
49 * @param MvcEvent $e
50 * @return void
52 public function createViewModelFromNull(MvcEvent $e)
54 $result = $e->getResult();
55 if (null !== $result) {
56 return;
59 $model = new ViewModel;
60 $e->setResult($model);