Source of file JsonModel.php
Size: 1,568 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/View/Model/JsonModel.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\View\Model; use Traversable; use Zend\Json\Json; use Zend\Stdlib\ArrayUtils; class JsonModel extends ViewModel { /** * JSON probably won't need to be captured into a * a parent container by default. * * @var string */ protected $captureTo = null; /** * JSONP callback (if set, wraps the return in a function call) * * @var string */ protected $jsonpCallback = null; /** * JSON is usually terminal * * @var bool */ protected $terminate = true; /** * Set the JSONP callback function name * * @param string $callback * @return JsonModel */ public function setJsonpCallback($callback) { $this->jsonpCallback = $callback; return $this; } /** * Serialize to JSON * * @return string */ public function serialize() { $variables = $this->getVariables(); if ($variables instanceof Traversable) { $variables = ArrayUtils::iteratorToArray($variables); } if (null !== $this->jsonpCallback) { return $this->jsonpCallback.'('.Json::encode($variables).');'; } return Json::encode($variables); } } |