/** * Render values as XML * * @param string|ModelInterface $nameOrModel The script/resource process, or a view model * @param null|array|\ArrayAccess $values Values to use during rendering * @return string The script output. */ public function render($nameOrModel, $values = null) { if ($nameOrModel instanceof XmlModel) { return $nameOrModel->serialize(); } // use case 3: Both $nameOrModel and $values are populated throw new Exception\DomainException(sprintf('%s: Do not know how to handle operation when both $nameOrModel and $values are populated', __METHOD__)); }
/** * Renders values as Icalendar * * @param string|\Zend\View\Model\ModelInterface $oNameOrModel : the script/resource process, or a view model * @param null|array|\ArrayAccess $aValues : values to use during rendering * * @throws \DomainException * @return string The script output. */ public function render($oNameOrModel, $aValues = null) { // Use case 1: View Models // Serialize variables in view model if (!$oNameOrModel instanceof IcalendarModel) { throw new \DomainException(__METHOD__ . ': Do not know how to handle operation when both $oNameOrModel and $aValues are populated'); } return $oNameOrModel->serialize(); }
/** * Renders values as JSON * * @todo Determine what use case exists for accepting both $nameOrModel and $values * @param string|Model $nameOrModel The script/resource process, or a view model * @param null|array|\ArrayAccess $values Values to use during rendering * @throws Exception\DomainException * @return string The script output. */ public function render($nameOrModel, $values = null) { // use case 1: View Models // Serialize variables in view model if ($nameOrModel instanceof Model) { if ($nameOrModel instanceof JsonModel) { $values = $nameOrModel->serialize(); } else { $values = $this->recurseModel($nameOrModel); $values = Json::encode($values); } if ($this->hasJsonpCallback()) { $values = $this->jsonpCallback . '(' . $values . ');'; } return $values; } // use case 2: $nameOrModel is populated, $values is not // Serialize $nameOrModel if (null === $values) { if (!is_object($nameOrModel) || $nameOrModel instanceof JsonSerializable) { $return = Json::encode($nameOrModel); } elseif ($nameOrModel instanceof Traversable) { $nameOrModel = ArrayUtils::iteratorToArray($nameOrModel); $return = Json::encode($nameOrModel); } else { $return = Json::encode(get_object_vars($nameOrModel)); } if ($this->hasJsonpCallback()) { $return = $this->jsonpCallback . '(' . $return . ');'; } return $return; } // use case 3: Both $nameOrModel and $values are populated throw new Exception\DomainException(sprintf('%s: Do not know how to handle operation when both $nameOrModel and $values are populated', __METHOD__)); }
/** * Renders values as XML * * @todo Determine what use case exists for accepting both $nameOrModel and $values * @param string|Model $nameOrModel The script/resource process, or a view model * @param null|array|\ArrayAccess $values Values to use during rendering * @throws Exception\DomainException * @return string The script output. */ public function render($nameOrModel, $values = null) { if ($nameOrModel instanceof \ShinyRest\View\Model\XmlModel) { return $nameOrModel->serialize(); } #echo "<pre>"; #print_r($nameOrModel); throw new \DomainException(get_class($nameOrModel) . " is not an instance of XmlModel"); }