Changeset View
Changeset View
Standalone View
Standalone View
support/php/JavelinHelper.php
| Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | public static function renderAjaxResponse($payload, $error = null) { | ||||
| if ($javelin->behavior) { | if ($javelin->behavior) { | ||||
| $response['javelin_behaviors'] = $javelin->behavior; | $response['javelin_behaviors'] = $javelin->behavior; | ||||
| $javelin->behavior = array(); | $javelin->behavior = array(); | ||||
| } | } | ||||
| if ($javelin->onload) { | if ($javelin->onload) { | ||||
| throw new Exception( | throw new Exception( | ||||
| "Javelin onload functions have been registered, but the response is ". | 'Javelin onload functions have been registered, but the response is '. | ||||
| "being rendered as an Ajax response. This is invalid; use behaviors ". | 'being rendered as an Ajax response. This is invalid; use behaviors '. | ||||
| "instead."); | 'instead.'); | ||||
| } | } | ||||
| $javelin->dirty = false; | $javelin->dirty = false; | ||||
| $response = 'for (;;);'.json_encode($response); | $response = 'for (;;);'.json_encode($response); | ||||
| return $response; | return $response; | ||||
| } | } | ||||
| protected function __construct() { | protected function __construct() { | ||||
| if (isset($_REQUEST['__metablock__'])) { | if (isset($_REQUEST['__metablock__'])) { | ||||
| $this->block = $_REQUEST['__metablock__']; | $this->block = $_REQUEST['__metablock__']; | ||||
| } | } | ||||
| } | } | ||||
| public function __destruct() { | public function __destruct() { | ||||
| if ($this->dirty) { | if ($this->dirty) { | ||||
| throw new Exception( | throw new Exception( | ||||
| "Javelin has behaviors, metadata or onload functions to include in ". | 'Javelin has behaviors, metadata or onload functions to include in '. | ||||
| "the response but you did not call renderHTMLFooter() or ". | 'the response but you did not call renderHTMLFooter() or '. | ||||
| "renderAjaxResponse() after registering them."); | 'renderAjaxResponse() after registering them.'); | ||||
| } | } | ||||
| } | } | ||||
| protected static function getInstance() { | protected static function getInstance() { | ||||
| if (empty(self::$instance)) { | if (empty(self::$instance)) { | ||||
| self::$instance = new JavelinHelper(); | self::$instance = new JavelinHelper(); | ||||
| } | } | ||||
| return self::$instance; | return self::$instance; | ||||
| } | } | ||||
| } | } | ||||