resolver = $resolver; return $this; } /** * Renders values as JSON * * @todo Determine what use case exists for accepting only $nameOrModel * @param string|Model $nameOrModel The script/resource process, or a view model * @param null|array|ArrayAccess $values Values to use during rendering * @throws Exception\InvalidArgumentException * @return string The script output. */ public function render($nameOrModel, $values = null) { if ($nameOrModel instanceof Model) { // Use case 1: View Model provided // Non-FeedModel: cast to FeedModel if (! $nameOrModel instanceof FeedModel) { $vars = $nameOrModel->getVariables(); $options = $nameOrModel->getOptions(); $type = $this->getFeedType(); if (isset($options['feed_type'])) { $type = $options['feed_type']; } else { $this->setFeedType($type); } $nameOrModel = new FeedModel($vars, ['feed_type' => $type]); } } elseif (is_string($nameOrModel)) { // Use case 2: string $nameOrModel + array|Traversable|Feed $values $nameOrModel = new FeedModel($values, (array) $nameOrModel); } else { // Use case 3: failure throw new Exception\InvalidArgumentException(sprintf( '%s expects a ViewModel or a string feed type as the first argument; received "%s"', __METHOD__, is_object($nameOrModel) ? get_class($nameOrModel) : gettype($nameOrModel) )); } // Get feed and type $feed = $nameOrModel->getFeed(); $type = $nameOrModel->getFeedType(); if (! $type) { $type = $this->getFeedType(); } else { $this->setFeedType($type); } // Render feed return $feed->export($type); } /** * Set feed type ('rss' or 'atom') * * @param string $feedType * @throws Exception\InvalidArgumentException * @return FeedRenderer */ public function setFeedType($feedType) { $feedType = strtolower($feedType); if (! in_array($feedType, ['rss', 'atom'])) { throw new Exception\InvalidArgumentException(sprintf( '%s expects a string of either "rss" or "atom"', __METHOD__ )); } $this->feedType = $feedType; return $this; } /** * Get feed type * * @return string */ public function getFeedType() { return $this->feedType; } }