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 / Console / CreateViewModelListener.php
blob4e9d67e6aa10983bcc69c09e85fa0926ecb9d90d
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\Console;
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\ConsoleModel;
18 class CreateViewModelListener extends AbstractListenerAggregate
20 /**
21 * {@inheritDoc}
23 public function attach(Events $events)
25 $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'createViewModelFromString'), -80);
26 $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'createViewModelFromArray'), -80);
27 $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'createViewModelFromNull'), -80);
30 /**
31 * Inspect the result, and cast it to a ViewModel if a string is detected
33 * @param MvcEvent $e
34 * @return void
36 public function createViewModelFromString(MvcEvent $e)
38 $result = $e->getResult();
39 if (!is_string($result)) {
40 return;
43 // create Console model
44 $model = new ConsoleModel;
46 // store the result in a model variable
47 $model->setVariable(ConsoleModel::RESULT, $result);
48 $e->setResult($model);
51 /**
52 * Inspect the result, and cast it to a ViewModel if an assoc array is detected
54 * @param MvcEvent $e
55 * @return void
57 public function createViewModelFromArray(MvcEvent $e)
59 $result = $e->getResult();
60 if (!ArrayUtils::hasStringKeys($result, true)) {
61 return;
64 $model = new ConsoleModel($result);
65 $e->setResult($model);
68 /**
69 * Inspect the result, and cast it to a ViewModel if null is detected
71 * @param MvcEvent $e
72 * @return void
74 public function createViewModelFromNull(MvcEvent $e)
76 $result = $e->getResult();
77 if (null !== $result) {
78 return;
81 $model = new ConsoleModel;
82 $e->setResult($model);