本文整理汇总了PHP中Slim\Http\Request::getPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getPath方法的具体用法?PHP Request::getPath怎么用?PHP Request::getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Request
的用法示例。
在下文中一共展示了Request::getPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
/**
* This function outputs the given $data as valid HAL+JSON to the client
* and sets the HTTP Response Code to the given $statusCode.
*
* @param array|SlimBootstrap\DataObject $data The data to output to
* the client
* @param int $statusCode The status code to set
* in the reponse
*/
public function write($data, $statusCode = 200)
{
$path = $this->_request->getPath();
$hal = new hal\Hal($path);
if (true === is_array($data)) {
$pathData = explode('/', $path);
unset($pathData[0]);
$endpointName = end($pathData);
$endpointUri = '/' . implode('/', $pathData) . '/';
foreach ($data as $entry) {
/** @var SlimBootstrap\DataObject $entry */
$identifiers = $entry->getIdentifiers();
$resourceName = $endpointUri . implode('/', array_values($identifiers));
$resource = new hal\Hal($resourceName, $entry->getData() + $entry->getIdentifiers());
$this->_addAdditionalLinks($resource, $entry->getLinks());
$hal->addLink($endpointName, $resourceName);
$hal->addResource($endpointName, $resource);
}
} else {
$hal->setData($data->getData() + $data->getIdentifiers());
$this->_addAdditionalLinks($hal, $data->getLinks());
}
$body = $this->_jsonEncode($hal);
if (false === $body) {
$this->_response->setStatus(500);
$this->_response->setBody("Error encoding requested data.");
return;
}
$this->_headers->set('Content-Type', 'application/hal+json; charset=UTF-8');
$this->_response->setStatus($statusCode);
$this->_response->setBody($hal->asJson());
}
示例2: call
/**
* Call
*
* This method finds and iterates all route objects that match the current request URI.
*/
public function call()
{
try {
if (isset($this->environment['slim.flash'])) {
$this->view()->setData('flash', $this->environment['slim.flash']);
}
$this->applyHook('slim.before');
ob_start();
$this->applyHook('slim.before.router');
$dispatched = false;
$httpMethodsAllowed = array();
$this->router->setResourceUri($this->request->getResourceUri());
$this->router->getMatchedRoutes();
foreach ($this->router as $route) {
if ($route->supportsHttpMethod($this->environment['REQUEST_METHOD'])) {
try {
$this->applyHook('slim.before.dispatch');
$dispatched = $this->router->dispatch($route);
$this->applyHook('slim.after.dispatch');
if ($dispatched) {
break;
}
} catch (\Slim\Exception\Pass $e) {
continue;
}
} else {
$httpMethodsAllowed = array_merge($httpMethodsAllowed, $route->getHttpMethods());
}
}
if (!$dispatched) {
if ($httpMethodsAllowed) {
$this->response['Allow'] = implode(' ', $httpMethodsAllowed);
$this->halt(405, 'HTTP method not allowed for the requested resource. Use one of these instead: ' . implode(', ', $httpMethodsAllowed));
} else {
$this->notFound();
}
}
$this->applyHook('slim.after.router');
$this->stop();
} catch (\Slim\Exception\Stop $e) {
$this->response()->write(ob_get_clean());
$this->applyHook('slim.after');
} catch (\Slim\Exception\RequestSlash $e) {
$this->response->redirect($this->request->getPath() . '/', 301);
} catch (\Exception $e) {
if ($this->config('debug')) {
throw $e;
} else {
try {
$this->error($e);
} catch (\Slim\Exception\Stop $e) {
// Do nothing
}
}
}
}
示例3: requestedObject
/**
* When having configured a wildcard route for an operation this function
* may be used to retrieve requested object (eg. 'users/*' => 'SomeOperation')
* @return string
*/
protected function requestedObject()
{
if ($this->requestedObject === null) {
$requestPath = $this->request->getPath();
if (basename(dirname($requestPath)) != basename($this->path)) {
$this->requestedObject = false;
} else {
$this->requestedObject = current(array_slice(explode('/', $requestPath), -1));
}
}
return $this->requestedObject;
}