/** * Call a remote REST web service URI and return the Zend_Http_Response object * * @param string $path The path to append to the URI * @throws Zend_Service_Exception * @return void */ private final function _prepareRest($path, $query) { // Get the URI object and configure it if (!$this->_uri instanceof Zend_Uri) { throw new Zend_Service_Exception('URI object must be set before performing call'); } // @todo this needs to be revisited if ($path[0] != '/' && $this->_uri[strlen($this->_uri) - 1] != '/') { $path = '/' . $path; } $this->_uri->setPath($path); if (!is_null($query) && is_string($query)) { $this->_uri->setQueryString($query); } elseif (is_array($query)) { $this->_uri->setQueryArray($query); } /** * Get the HTTP client and configure it for the endpoint URI. Do this each time * because the Zend_Http_Client instance is shared among all Zend_Service_Abstract subclasses. */ self::getHttpClient()->setUri($this->_uri); }
public function generateUrl($parameters, Zend_Uri_Http $url) { $parts = $this->getParts(); $n = count($parts); $path = $parts[0]; for ($i = 1; $i < $n; $i += 3) { $type = $parts[$i]; $name = $parts[$i + 1]; $static = $parts[$i + 2]; if (isset($parameters[$name])) { $path .= $this->encode($type, $parameters[$name]); unset($parameters[$name]); } else { if (array_key_exists($name, $this->defaults)) { if (is_null($this->defaults[$name])) { // Remove rest of params so they dont appear in querystring for (; $i < $n; $i += 3) { unset($parameters[$parts[$i + 1]]); } break; } else { $path .= $this->encode($type, $this->defaults[$name]); } } else { throw new Zend_Controller_Router_Exception("Missing required parameter {$name}"); } } $path .= $static; } // Validate the path (and therefore parameters used so far) for this route if (0 == preg_match($this->getRegularExpression(), $path)) { throw new Zend_Controller_Router_Exception("{$path} does not match route {$this->getName()} {$this->getRegularExpression()}"); } // Remove parameters that are at their defaults for this route if (!empty($this->defaults)) { $parameters = array_diff_assoc($parameters, $this->defaults); } $url->setPath($path); $url->setQueryArray($parameters); return $url; }