本文整理匯總了PHP中Uri::shiftPathParam方法的典型用法代碼示例。如果您正苦於以下問題:PHP Uri::shiftPathParam方法的具體用法?PHP Uri::shiftPathParam怎麽用?PHP Uri::shiftPathParam使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Uri
的用法示例。
在下文中一共展示了Uri::shiftPathParam方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: dispatch
public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_)
{
if (!($method = $uri_->shiftPathParam())) {
throw new Http_Exception('rest/resource', null, Http_Exception::NOT_FOUND);
}
$resource = get_called_class();
if (null === self::$m_methods || false === isset(self::$m_methods[$resource][$method])) {
self::initializeMethods();
if (false === isset(self::$m_methods[$resource][$method])) {
throw new Http_Exception('rest/resource', null, Http_Exception::NOT_FOUND);
}
}
$method = self::$m_methods[$resource][$method];
if (false === isset($method['methods'][$context_->getRequest()->getMethod()])) {
throw new Http_Exception('rest/resource', null, Http_Exception::NOT_FOUND);
}
if (isset($method['path']) && count($uri_->getPathParams()) < count($method['path'])) {
throw new Http_Exception('rest/resource', null, Http_Exception::NOT_FOUND);
}
/* @var $resource \Components\Rest_Resource */
$resource = new $resource();
$resource->request = $context_->getRequest();
$resource->response = $context_->getResponse();
$params = [];
if (isset($method['path']) || isset($method['query'])) {
$marshaller = Object_Marshaller::forMimetype($resource->response->getMimetype());
foreach ($method['path'] as $name => $type) {
$params[$name] = $marshaller->unmarshal($uri_->shiftPathParam(), $type);
}
if (isset($method['query'])) {
foreach ($method['query'] as $name => $options) {
if ($uri_->hasQueryParam($options['name'])) {
$params[$name] = $marshaller->unmarshal($uri_->getQueryParam($options['name']), $options['type']);
} else {
if ($options['value']) {
$params[$name] = $marshaller->unmarshal($options['value'], $options['type']);
} else {
$params[$name] = null;
}
}
}
}
}
if ($result = call_user_func_array([$resource, $method['name']], $params)) {
echo $marshaller->marshal($result);
}
}
示例2: dispatchImpl
private function dispatchImpl(Uri $uri_, $method_ = null)
{
$this->m_contextUri = Uri::valueOf($this->m_contextRoot);
$this->m_request = new Http_Scriptlet_Request(clone $uri_);
if (null !== $method_) {
$this->m_request->setMethod($method_);
}
$mimeType = $this->m_request->getMimetype();
header('Content-Type: ' . $mimeType->name() . ';charset=' . $mimeType->charset()->name(), true, 200);
$this->m_response = new Http_Scriptlet_Response($mimeType);
if ('/' !== $this->m_contextRoot) {
$contextRoot = rtrim($this->m_contextRoot, '/');
$contextRoot = ltrim($contextRoot, '/');
$contextRootSegments = explode('/', $contextRoot);
while (count($contextRootSegments)) {
if (array_shift($contextRootSegments) !== $uri_->shiftPathParam()) {
throw new Http_Exception('http/scriptlet/context', null, Http_Exception::NOT_FOUND);
}
}
}
if (!($component = $uri_->shiftPathParam())) {
throw new Http_Exception('http/scriptlet/context', null, Http_Exception::NOT_FOUND);
}
$this->m_contextUri->pushPathParam($component);
if ($this->m_contextUri->hasFileExtension()) {
Config::get($this->m_contextUri->getFilename(true));
} else {
Config::get($component);
}
Http_Scriptlet::dispatch($this, $uri_);
}