本文整理汇总了PHP中Zend\Http\PhpEnvironment\Request类的典型用法代码示例。如果您正苦于以下问题:PHP Request类的具体用法?PHP Request怎么用?PHP Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequest
protected function getRequest()
{
$request = new Request();
$request->setUri('http://localhost/base-path/asset-path');
$request->setBasePath('/base-path');
return $request;
}
示例2: authenticate
/**
* Attempt to authenticate the current user. Throws exception if login fails.
*
* @param \Zend\Http\PhpEnvironment\Request $request Request object containing
* account credentials.
*
* @throws AuthException
* @return \VuFind\Db\Row\User Object representing logged-in user.
*/
public function authenticate($request)
{
$target = trim($request->getPost()->get('target'));
$username = trim($request->getPost()->get('username'));
$password = trim($request->getPost()->get('password'));
if ($username == '' || $password == '') {
throw new AuthException('authentication_error_blank');
}
// We should have target either separately or already embedded into username
if ($target) {
$username = "{$target}.{$username}";
}
// Connect to catalog:
try {
$patron = $this->getCatalog()->patronLogin($username, $password);
} catch (AuthException $e) {
// Pass Auth exceptions through
throw $e;
} catch (\Exception $e) {
throw new AuthException('authentication_error_technical');
}
// Did the patron successfully log in?
if ($patron) {
return $this->processILSUser($patron);
}
// If we got this far, we have a problem:
throw new AuthException('authentication_error_invalid');
}
示例3: helpAction
/**
* @param Request $request
* @return array|\Zend\Http\Response
* @throws \Exception
*/
public function helpAction($request)
{
$this->layout('layout/single-column');
$this->getNavService()->setActive('setting');
$helpForm = $this->autoFilledForm(HelpForm::class);
$helpForm->populateValues($this->user()->getArrayCopy());
if ($request->isPost()) {
if ($formValid = $helpForm->isValid()) {
$config = $this->service('Config');
if (is_array($config) && isset($config['slack']['webhook']['help-support'])) {
$formData = $helpForm->getData();
$data = ['fields' => [['name' => 'Name', 'value' => $formData['name'], 'short' => true], ['name' => 'Email', 'value' => $formData['email'], 'short' => true], ['name' => 'Contact No.', 'value' => $formData['contact_no'], 'short' => true], ['name' => 'Type', 'value' => $formData['type'], 'short' => true], ['name' => 'Severity', 'value' => $formData['severity'], 'short' => true], ['name' => 'Need Reply?', 'value' => $formData['need_reply'], 'short' => true], ['name' => 'Message', 'value' => $formData['message'], 'short' => false]]];
$json = sprintf('payload=%s', json_encode($data));
$ch = curl_init($config['slack']['webhook']['help-support']['url']);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
$this->flashMessenger()->addSuccessMessage('Terimakasih, pesan Anda telah terkirim.');
return $this->redirect()->toRoute(...$this->routeSpec('web.index.help'));
}
$this->flashMessenger()->addErrorMessage('Maaf, tidak dapat mengirim pesan Anda saat ini, mohon hubungi admin.');
return $this->redirect()->toRoute(...$this->routeSpec('web.index.help'));
}
}
return compact('helpForm', 'formValid');
}
示例4: authenticate
/**
* Attempt to authenticate the current user. Throws exception if login fails.
*
* @param \Zend\Http\PhpEnvironment\Request $request Request object containing
* account credentials.
*
* @throws AuthException
* @return \VuFind\Db\Row\User Object representing logged-in user.
*/
public function authenticate($request)
{
// Check if username is set.
$shib = $this->getConfig()->Shibboleth;
$username = $request->getServer()->get($shib->username);
if (empty($username)) {
throw new AuthException('authentication_error_admin');
}
// Check if required attributes match up:
foreach ($this->getRequiredAttributes() as $key => $value) {
if (!preg_match('/' . $value . '/', $request->getServer()->get($key))) {
throw new AuthException('authentication_error_denied');
}
}
// If we made it this far, we should log in the user!
$user = $this->getUserTable()->getByUsername($username);
// Has the user configured attributes to use for populating the user table?
$attribsToCheck = array("cat_username", "email", "lastname", "firstname", "college", "major", "home_library");
foreach ($attribsToCheck as $attribute) {
if (isset($shib->{$attribute})) {
$user->{$attribute} = $request->getServer()->get($shib->{$attribute});
}
}
// Save and return the user object:
$user->save();
return $user;
}
示例5: setRequest
/**
* @param Request $request
*/
public function setRequest(Request $request)
{
$header = $request->getHeader($this->headerName);
if ($header) {
$this->requestHeaderValue = $header->getFieldValue();
}
}
示例6: testBasePathDetection
/**
* @dataProvider baseUrlandPathProvider
* @param array $server
* @param string $baseUrl
* @param string $basePath
*/
public function testBasePathDetection(array $server, $baseUrl, $basePath)
{
$_SERVER = $server;
$request = new Request();
$this->assertEquals($baseUrl, $request->getBaseUrl());
$this->assertEquals($basePath, $request->getBasePath());
}
示例7: uploadImageAction
public function uploadImageAction()
{
$this->checkAuth();
$request = $this->getRequest();
if ($request->isPost()) {
// File upload input
$file = new FileInput('avatar');
// Special File Input type
$file->getValidatorChain()->attach(new Validator\File\UploadFile());
$file->getFilterChain()->attach(new Filter\File\RenameUpload(array('target' => './public/files/users/avatar/origin/', 'use_upload_name' => true, 'randomize' => true)));
// Merge $_POST and $_FILES data together
$request = new Request();
$postData = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
$inputFilter = new InputFilter();
$inputFilter->add($file)->setData($postData);
if ($inputFilter->isValid()) {
// FileInput validators are run, but not the filters...
$data = $inputFilter->getValues();
// This is when the FileInput filters are run.
$avatar = basename($data['avatar']['tmp_name']);
$this->databaseService->updateAvatar($this->user->id, $avatar);
$this->user->avatar = $avatar;
} else {
// error
}
}
return $this->redirect()->toRoute('profile');
}
示例8: clearCookie
/**
* Clear authorization Cookie
*
* @param string $authDomain
*/
private function clearCookie(Request $request, Response $response, $authDomain)
{
if ($request->getCookie()->offsetExists($authDomain)) {
$cookie = new SetCookie($authDomain, '', strtotime('-1 Year', time()), '/');
$response->getHeaders()->addHeader($cookie);
$response->send();
}
}
示例9: __construct
/**
* @param Request $request
* @param Di $di
*/
public function __construct(Request $request, Di $di)
{
$inputFilter = $this->getFactory()->createInputFilter(['width' => ['name' => 'width', 'required' => false, 'validators' => [['name' => 'digits'], ['name' => 'between', 'options' => ['min' => 150, 'max' => 19200]]]], 'height' => ['name' => 'height', 'required' => false, 'validators' => [['name' => 'digits'], ['name' => 'between', 'options' => ['min' => 150, 'max' => 19200]]]], 'username' => ['name' => 'username', 'required' => false, 'validators' => [['name' => 'not_empty'], ['name' => 'regex', 'options' => ['pattern' => '/^[a-zA-Z0-9._]+$/']]]], 'limit' => ['name' => 'limit', 'required' => false, 'validators' => [['name' => 'digits'], ['name' => 'between', 'options' => ['min' => 5, 'max' => 100]]]], 'hex' => ['name' => 'hex', 'required' => false, 'validators' => [['name' => 'hex']], 'filters' => [['name' => 'callback', 'options' => ['callback' => function ($value) {
return ltrim($value, '#');
}]]]], 'source' => ['name' => 'source', 'required' => true, 'validators' => [['name' => 'inarray', 'options' => ['haystack' => [SourceNameInterface::SOURCE_USER, SourceNameInterface::SOURCE_FEED]]]]], 'quality' => ['name' => 'quality', 'required' => false, 'validators' => [['name' => 'inarray', 'options' => ['haystack' => [QualityInterface::QUALITY_THUMBNAIL, QualityInterface::QUALITY_LOW_RES, QualityInterface::QUALITY_STANDARD_RES]]]]]]);
$this->merge($inputFilter);
$this->setData($this->initDefaults($request->getQuery()));
}
示例10: testHeadersWithMinus
/**
* @dataProvider serverHeaderProvider
* @param array $server
* @param string $name
* @param string $value
*/
public function testHeadersWithMinus(array $server, $name, $value)
{
$_SERVER = $server;
$request = new Request();
$header = $request->headers()->get($name);
$this->assertNotEquals($header, false);
$this->assertEquals($name, $header->getFieldName($value));
$this->assertEquals($value, $header->getFieldValue($value));
}
示例11: getRequest
public static function getRequest()
{
if (!isset(self::$serverParams)) {
self::$serverParams = ['HTTP_X_FORWARDED_FOR' => '192.168.1.1', 'HTTP_CLIENT_IP' => '192.168.1.1', 'REMOTE_ADDR' => '192.168.1.1'];
}
$httpRequest = new HttpRequest();
$httpRequest->setServer(new Parameters(self::$serverParams));
return $httpRequest;
}
示例12: getRemoteAddress
public function getRemoteAddress()
{
$request = new Request();
$serverParams = $request->getServer();
$remoteAddress = $serverParams->get('REMOTE_ADDR');
if ($remoteAddress == '') {
$remoteAddress = '127.0.0.1';
}
return $remoteAddress;
}
示例13: getSessionIdFromRequest
/**
* @param \Zend\Http\PhpEnvironment\Request $request
* @return string|null
*/
protected function getSessionIdFromRequest($request)
{
$ssid = $request->getPost(static::SESSION_ID_ALIAS);
if (!$ssid) {
$ssid = $request->getQuery(static::SESSION_ID_ALIAS);
}
if (!$ssid) {
return null;
}
return $ssid;
}
示例14: getList
/**
* @param array $search
* @param array $orderBy
* @param array $parameters
*
* @return \Zend\Paginator\Paginator
*/
public function getList($search = [], $orderBy = [], $parameters = [])
{
$query = $this->mainRepository->getAdminPage($search, $orderBy, $parameters);
$paginator = $this->paginatorFactory->getQueryPaginator($query);
$paginator->setCurrentPageNumber($this->request->getQuery(self::PAGE, 0));
$paginator->setItemCountPerPage(5);
return $paginator;
}
示例15: getPermissions
/**
* Return an array of roles which may be granted the permission based on
* the options.
*
* @param mixed $options Options provided from configuration.
*
* @return array
*/
public function getPermissions($options)
{
if ($this->request->getServer()->get('Shib-Identity-Provider') === false) {
$this->logWarning('getPermissions: Shibboleth server params missing');
return [];
}
return parent::getPermissions($options);
}