本文整理汇总了PHP中Cake\Network\Request类的典型用法代码示例。如果您正苦于以下问题:PHP Request类的具体用法?PHP Request怎么用?PHP Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getData
/**
* Get data of the request
*
* @param Request $request
* @return array
*/
public function getData(Request $request)
{
$data = $request->data('attributes');
if ($request->data('id')) {
$data['id'] = $request->data('id');
}
return $data;
}
示例2: __construct
/**
* Permission extract constructor.
*
* @param $user
* @param Request $request
*/
public function __construct($user, Request $request)
{
$this->_request = $request;
$this->_user = (array) $user;
$this->_requestPref = $request->param('prefix');
$this->_controller = $request->param('Controller');
$this->_setAclPlugins();
$this->_setupAllowed();
}
示例3: setUp
/**
* Setup
*
* @return void
*/
public function setUp()
{
parent::setUp();
Router::connect('/:controller/:action');
$request = new Request();
$request->addParams(array('controller' => 'pages', 'action' => 'display'));
$this->View = new View($request);
$this->Toolbar = new ToolbarHelper($this->View);
}
示例4: testAuthorizeCheckFailure
/**
* test check() failing
*
* @return void
*/
public function testAuthorizeCheckFailure()
{
$request = new Request('posts/index');
$request->addParams(['controller' => 'posts', 'action' => 'index']);
$user = ['Users' => ['username' => 'mark']];
$this->_mockAcl();
$this->Acl->expects($this->once())->method('check')->with($user, 'Posts', 'read')->will($this->returnValue(false));
$this->assertFalse($this->auth->authorize($user['Users'], $request));
}
示例5: authorize
/**
* User authorize.
*
* @param array $user
* @param Request $request
* @return bool
*/
public function authorize($user, Request $request)
{
$user = new Data($user);
// Allow all for admin role.
if (Role::ADMIN_ID == $user->get('role_id', Role::PUBLIC_ID)) {
return true;
}
return (bool) $request->param('allowed');
}
示例6: _checkFields
/**
* Checks the fields to ensure they are supplied.
*
* @param \Cake\Network\Request $request The request that contains login information.
* @param array $fields The fields to be checked.
* @return bool False if the fields have not been supplied. True if they exist.
*/
protected function _checkFields(Request $request, array $fields)
{
foreach ([$fields['username'], $fields['password']] as $field) {
$value = $request->data($field);
if (empty($value) || !is_string($value)) {
return false;
}
}
return true;
}
示例7: testBeforeDispatchSkipWhenControllerSet
/**
* test setting parameters in beforeDispatch method
*
* @return void
* @triggers __CLASS__ $this, compact(request)
*/
public function testBeforeDispatchSkipWhenControllerSet()
{
$filter = new RoutingFilter();
$request = new Request("/testcontroller/testaction/params1/params2/params3");
$request->addParams(['controller' => 'articles']);
$event = new Event(__CLASS__, $this, compact('request'));
$filter->beforeDispatch($event);
$this->assertSame($request->params['controller'], 'articles');
$this->assertEmpty($request->params['action']);
}
示例8: testAuthenticateTokenHeader
/**
* test authenticate token as request header
*
* @return void
*/
public function testAuthenticateTokenHeader()
{
$request = new Request('posts/index');
$expected = ['id' => 1, 'user_name' => 'mariano', 'email' => 'mariano@example.com', 'token' => '12345', 'created' => new Time('2007-03-17 01:16:23'), 'updated' => new Time('2007-03-17 01:18:31')];
$request->env('HTTP_X_APITOKEN', '12345');
$result = $this->auth->getUser($request, $this->response);
$this->assertEquals($expected, $result);
$request->env('HTTP_X_APITOKEN', '66666');
$result = $this->auth->getUser($request, $this->response);
$this->assertFalse($result);
}
示例9: authorize
/**
* Hands authorization over to the AnnAuthorize class.
* @param array $user
* An array containing information about the user to authorize.
* @param Request $request
* Describes the request to authorize.
*/
public function authorize($user, Request $request)
{
$controller = $this->_registry->getController();
$action = $request->param('action');
$pass = $request->param('pass');
Log::debug(sprintf('Trying to authorize user %s for request %s/%s and parameters %s.', $user['username'], $controller->name, $action, json_encode($pass)));
$annAuthorization = AnnAuthorization::getInstance();
$authorized = $annAuthorization->authorizeRequest($user['id'], $controller, $action, $pass, $request);
Log::debug(sprintf('Authorization %s', $authorized ? 'was successful.' : 'failed.'));
return $authorized;
}
示例10: setUp
/**
* setup create a request object to get out of router later.
*
* @return void
*/
public function setUp()
{
parent::setUp();
Router::reload();
$request = new Request();
$request->base = '';
$request->env('HTTP_REFERER', '/referer');
Router::setRequestInfo($request);
Configure::write('debug', true);
$this->_logger = $this->getMock('Psr\\Log\\LoggerInterface');
Log::reset();
Log::config('error_test', ['engine' => $this->_logger]);
}
示例11: _getCredentials
/**
* Get user's credentials (username and password) from either session or request data
*
* @param Request $request Request instance
* @return array|bool
*/
protected function _getCredentials(Request $request)
{
$credentials = [];
foreach (['username', 'password'] as $field) {
if (!($credentials[$field] = $request->data($this->_config['fields'][$field]))) {
$credentials[$field] = $this->_decrypt($request->session()->read('TwoFactorAuth.credentials.' . $field));
}
if (empty($credentials[$field]) || !is_string($credentials[$field])) {
return false;
}
}
return $credentials;
}
示例12: get
/**
* Check and get current theme.
*
* @param Request $request
* @return string|null
*/
public static function get(Request $request)
{
$theme = Configure::read('Theme.site');
if ($request->param('prefix') == 'admin') {
$theme = Configure::read('Theme.admin');
}
$path = self::_find($theme);
if ($path !== null) {
self::loadList([$theme]);
return $theme;
}
return null;
}
示例13: authenticate
/**
* Authenticate callback
* Reads the stored cookie and auto login the user
*
* @param Request $request Cake request object.
* @param Response $response Cake response object.
* @return mixed
*/
public function authenticate(Request $request, Response $response)
{
$cookieName = Configure::read('Users.RememberMe.Cookie.name');
if (!$this->_registry->Cookie->check($cookieName)) {
return false;
}
$cookie = $this->_registry->Cookie->read($cookieName);
$this->config('fields.username', 'id');
$user = $this->_findUser($cookie['id']);
if ($user && !empty($cookie['user_agent']) && $request->header('User-Agent') === $cookie['user_agent']) {
return $user;
}
return false;
}
示例14: check
/**
* Check if the user can access to the given URL.
*
* @param array $params The params to check.
*
* @return bool
*/
public function check(array $params = [])
{
if (!$this->request->session()->read('Auth.User')) {
return false;
}
$params += ['_base' => false];
$url = Router::url($params);
$params = Router::parse($url);
$user = [$this->Authorize->config('userModel') => $this->request->session()->read('Auth.User')];
$request = new Request();
$request->addParams($params);
$action = $this->Authorize->action($request);
return $this->Acl->check($user, $action);
}
示例15: validate
/**
* {@inheritDoc}
*/
public function validate(Request $request)
{
if ($request->is('post')) {
// The (User's) Remote Address
$whatRemoteIP = env('REMOTE_ADDR') ? '&remoteip=' . env('REMOTE_ADDR') : '';
// The reCAPTCHA data is extracted from Request
$gRecaptchaResponse = $request->data('g-recaptcha-response');
// Verify reCAPTCHA data
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $this->config('secretKey') . '&response=' . $gRecaptchaResponse . $whatRemoteIP);
$response = json_decode($response, true);
// We return the Google server's response 'success' value
return (bool) $response['success'];
}
return false;
}