/** * Retrieve layout object * * @return IfwPsn_Vendor_Zend_Layout */ public function getLayout() { if (null === $this->_layout) { $this->_layout = IfwPsn_Vendor_Zend_Layout::startMvc($this->getOptions()); } return $this->_layout; }
/** * Encode data as JSON, disable layouts, and set response header * * If $keepLayouts is true, does not disable layouts. * If $encodeJson is false, does not JSON-encode $data * * @param mixed $data * @param bool $keepLayouts * NOTE: if boolean, establish $keepLayouts to true|false * if array, admit params for IfwPsn_Vendor_Zend_Json::encode as enableJsonExprFinder=>true|false * this array can contains a 'keepLayout'=>true|false and/or 'encodeData'=>true|false * that will not be passed to IfwPsn_Vendor_Zend_Json::encode method but will be used here * @param bool $encodeData * @return string|void */ public function json($data, $keepLayouts = false, $encodeData = true) { $options = array(); if (is_array($keepLayouts)) { $options = $keepLayouts; $keepLayouts = false; if (array_key_exists('keepLayouts', $options)) { $keepLayouts = $options['keepLayouts']; unset($options['keepLayouts']); } if (array_key_exists('encodeData', $options)) { $encodeData = $options['encodeData']; unset($options['encodeData']); } } if ($encodeData) { $data = IfwPsn_Vendor_Zend_Json::encode($data, null, $options); } if (!$keepLayouts) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Layout.php'; $layout = IfwPsn_Vendor_Zend_Layout::getMvcInstance(); if ($layout instanceof IfwPsn_Vendor_Zend_Layout) { $layout->disableLayout(); } } $response = IfwPsn_Vendor_Zend_Controller_Front::getInstance()->getResponse(); $response->setHeader('Content-Type', 'application/json', true); return $data; }
/** * Get layout object * * @return IfwPsn_Vendor_Zend_Layout */ public function getLayout() { if (null === $this->_layout) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Layout.php'; $this->_layout = IfwPsn_Vendor_Zend_Layout::getMvcInstance(); if (null === $this->_layout) { // Implicitly creates layout object $this->_layout = new IfwPsn_Vendor_Zend_Layout(); } } return $this->_layout; }
/** * Disable layouts and view renderer * * @return IfwPsn_Vendor_Zend_Controller_Action_Helper_AutoComplete_Abstract Provides a fluent interface */ public function disableLayouts() { /** * @see IfwPsn_Vendor_Zend_Layout */ require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Layout.php'; if (null !== ($layout = IfwPsn_Vendor_Zend_Layout::getMvcInstance())) { $layout->disableLayout(); } IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); return $this; }
/** * Sends mail to recipient(s) if log entries are present. Note that both * plaintext and HTML portions of email are handled here. * * @return void */ public function shutdown() { // If there are events to mail, use them as message body. Otherwise, // there is no mail to be sent. if (empty($this->_eventsToMail)) { return; } if ($this->_subjectPrependText !== null) { // Tack on the summary of entries per-priority to the subject // line and set it on the IfwPsn_Vendor_Zend_Mail object. $numEntries = $this->_getFormattedNumEntriesPerPriority(); $this->_mail->setSubject("{$this->_subjectPrependText} ({$numEntries})"); } // Always provide events to mail as plaintext. $this->_mail->setBodyText(implode('', $this->_eventsToMail)); // If a IfwPsn_Vendor_Zend_Layout instance is being used, set its "events" // value to the lines formatted for use with the layout. if ($this->_layout) { // Set the required "messages" value for the layout. Here we // are assuming that the layout is for use with HTML. $this->_layout->events = implode('', $this->_layoutEventsToMail); // If an exception occurs during rendering, convert it to a notice // so we can avoid an exception thrown without a stack frame. try { $this->_mail->setBodyHtml($this->_layout->render()); } catch (Exception $e) { trigger_error("exception occurred when rendering layout; " . "unable to set html body for message; " . "message = {$e->getMessage()}; " . "code = {$e->getCode()}; " . "exception class = " . get_class($e), E_USER_NOTICE); } } // Finally, send the mail. If an exception occurs, convert it into a // warning-level message so we can avoid an exception thrown without a // stack frame. try { $this->_mail->send(); } catch (Exception $e) { trigger_error("unable to send log entries via email; " . "message = {$e->getMessage()}; " . "code = {$e->getCode()}; " . "exception class = " . get_class($e), E_USER_WARNING); } }
/** * Prepare data for autocompletion * * @param mixed $data * @param boolean $keepLayouts * @return string */ public function prepareAutoCompletion($data, $keepLayouts = false) { if (!$data instanceof IfwPsn_Vendor_Zend_Dojo_Data) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Dojo/Data.php'; $items = array(); foreach ($data as $key => $value) { $items[] = array('label' => $value, 'name' => $value); } $data = new IfwPsn_Vendor_Zend_Dojo_Data('name', $items); } if (!$keepLayouts) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/HelperBroker.php'; IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Layout.php'; $layout = IfwPsn_Vendor_Zend_Layout::getMvcInstance(); if ($layout instanceof IfwPsn_Vendor_Zend_Layout) { $layout->disableLayout(); } } $response = IfwPsn_Vendor_Zend_Controller_Front::getInstance()->getResponse(); $response->setHeader('Content-Type', 'application/json'); return $data->toJson(); }
/** * Initialize context detection and switching * * @param mixed $format * @throws IfwPsn_Vendor_Zend_Controller_Action_Exception * @return void */ public function initContext($format = null) { $this->_currentContext = null; $controller = $this->getActionController(); $request = $this->getRequest(); $action = $request->getActionName(); // Return if no context switching enabled, or no context switching // enabled for this action $contexts = $this->getActionContexts($action); if (empty($contexts)) { return; } // Return if no context parameter provided if (!($context = $request->getParam($this->getContextParam()))) { if ($format === null) { return; } $context = $format; $format = null; } // Check if context allowed by action controller if (!$this->hasActionContext($action, $context)) { return; } // Return if invalid context parameter provided and no format or invalid // format provided if (!$this->hasContext($context)) { if (empty($format) || !$this->hasContext($format)) { return; } } // Use provided format if passed if (!empty($format) && $this->hasContext($format)) { $context = $format; } $suffix = $this->getSuffix($context); $this->_getViewRenderer()->setViewSuffix($suffix); $headers = $this->getHeaders($context); if (!empty($headers)) { $response = $this->getResponse(); foreach ($headers as $header => $content) { $response->setHeader($header, $content); } } if ($this->getAutoDisableLayout()) { /** * @see IfwPsn_Vendor_Zend_Layout */ require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Layout.php'; $layout = IfwPsn_Vendor_Zend_Layout::getMvcInstance(); if (null !== $layout) { $layout->disableLayout(); } } if (null !== ($callback = $this->getCallback($context, self::TRIGGER_INIT))) { if (is_string($callback) && method_exists($this, $callback)) { $this->{$callback}(); } elseif (is_string($callback) && function_exists($callback)) { $callback(); } elseif (is_array($callback)) { call_user_func($callback); } else { /** * @see IfwPsn_Vendor_Zend_Controller_Action_Exception */ require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/Exception.php'; throw new IfwPsn_Vendor_Zend_Controller_Action_Exception(sprintf('Invalid context callback registered for context "%s"', $context)); } } $this->_currentContext = $context; }
/** * Reset MVC instance * * Unregisters plugins and helpers, and destroys MVC layout instance. * * @return void */ public static function resetMvcInstance() { if (null !== self::$_mvcInstance) { $layout = self::$_mvcInstance; $pluginClass = $layout->getPluginClass(); $front = IfwPsn_Vendor_Zend_Controller_Front::getInstance(); if ($front->hasPlugin($pluginClass)) { $front->unregisterPlugin($pluginClass); } if (IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::hasHelper('layout')) { IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::removeHelper('layout'); } unset($layout); self::$_mvcInstance = null; } }