7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
16
* @package Zend_Controller
17
* @subpackage Zend_Controller_Action_Helper
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: Abstract.php 9098 2008-03-30 19:29:10Z thomas $
24
* @see Zend_Controller_Action_Helper_Abstract
26
require_once 'Zend/Controller/Action/Helper/Abstract.php';
29
* Create and send autocompletion lists
31
* @uses Zend_Controller_Action_Helper_Abstract
33
* @package Zend_Controller
34
* @subpackage Zend_Controller_Action_Helper
35
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
36
* @license http://framework.zend.com/license/new-bsd New BSD License
38
abstract class Zend_Controller_Action_Helper_AutoComplete_Abstract extends Zend_Controller_Action_Helper_Abstract
41
* Suppress exit when sendJson() called
45
public $suppressExit = false;
48
* Validate autocompletion data
53
abstract public function validateData($data);
56
* Prepare autocompletion data
59
* @param boolean $keepLayouts
62
abstract public function prepareAutoCompletion($data, $keepLayouts = false);
65
* Disable layouts and view renderer
67
* @return Zend_Controller_Action_Helper_AutoComplete_Abstract Provides a fluent interface
69
public function disableLayouts()
74
require_once 'Zend/Layout.php';
75
if (null !== ($layout = Zend_Layout::getMvcInstance())) {
76
$layout->disableLayout();
79
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
88
* @param bool $keepLayouts
89
* @throws Zend_Controller_Action_Exception
92
public function encodeJson($data, $keepLayouts = false)
94
if ($this->validateData($data)) {
95
return Zend_Controller_Action_HelperBroker::getStaticHelper('Json')->encodeJson($data, $keepLayouts);
99
* @see Zend_Controller_Action_Exception
101
require_once 'Zend/Controller/Action/Exception.php';
102
throw new Zend_Controller_Action_Exception('Invalid data passed for autocompletion');
106
* Send autocompletion data
108
* Calls prepareAutoCompletion, populates response body with this
109
* information, and sends response.
112
* @param bool $keepLayouts
113
* @return string|void
115
public function sendAutoCompletion($data, $keepLayouts = false)
117
$data = $this->prepareAutoCompletion($data, $keepLayouts);
119
$response = $this->getResponse();
120
$response->setBody($data);
122
if (!$this->suppressExit) {
123
$response->sendResponse();
131
* Strategy pattern: allow calling helper as broker method
133
* Prepares autocompletion data and, if $sendNow is true, immediately sends
137
* @param bool $sendNow
138
* @param bool $keepLayouts
139
* @return string|void
141
public function direct($data, $sendNow = true, $keepLayouts = false)
144
return $this->sendAutoCompletion($data, $keepLayouts);
147
return $this->prepareAutoCompletion($data, $keepLayouts);