本文整理汇总了PHP中Cake\Network\Request::data方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::data方法的具体用法?PHP Request::data怎么用?PHP Request::data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Network\Request
的用法示例。
在下文中一共展示了Request::data方法的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: val
/**
* {@inheritDoc}
*/
public function val($field, $options = [])
{
$options += ['default' => null, 'schemaDefault' => true];
$val = $this->_request->data($field);
if ($val !== null) {
return $val;
}
return $options['default'];
}
示例3: authenticate
/**
* Authenticate a user based on the request information.
*
* @param Request $request Request to get authentication information from.
* @param Response $response A response object that can have headers added.
* @return array|bool User array on success, false on failure.
*/
public function authenticate(Request $request, Response $response)
{
$fields = $this->_config['fields'];
if (!$request->data($fields['provider'])) {
return $this->getUser($request);
}
$provider = $this->_checkFields($request, $fields);
if (!$provider) {
return false;
}
if ($this->_config['hauth_return_to']) {
$returnTo = Router::url($this->_config['hauth_return_to'], true);
} else {
$returnTo = Router::url(['plugin' => 'ADmad/HybridAuth', 'controller' => 'HybridAuth', 'action' => 'authenticated'], true);
}
$params = ['hauth_return_to' => $returnTo];
if ($provider === 'OpenID') {
$params['openid_identifier'] = $request->data[$fields['openid_identifier']];
}
$this->_init($request);
$adapter = $this->hybridAuth->authenticate($provider, $params);
if ($adapter) {
return $this->_getUser($provider, $adapter);
}
return false;
}
示例4: val
/**
* Get the value for a given path.
*
* Traverses the entity data and finds the value for $path.
*
* @param string $field The dot separated path to the value.
* @param array $options Options:
* - `default`: Default value to return if no value found in request
* data or entity.
* - `schemaDefault`: Boolen indicating whether default value from table
* schema should be used if it's not explicitly provided.
* @return mixed The value of the field or null on a miss.
*/
public function val($field, $options = [])
{
$options += ['default' => null, 'schemaDefault' => true];
$val = $this->_request->data($field);
if ($val !== null) {
return $val;
}
if (empty($this->_context['entity'])) {
return $options['default'];
}
$parts = explode('.', $field);
$entity = $this->entity($parts);
if (end($parts) === '_ids' && !empty($entity)) {
return $this->_extractMultiple($entity, $parts);
}
if ($entity instanceof EntityInterface) {
$part = array_pop($parts);
$val = $entity->get($part);
if ($val !== null) {
return $val;
}
if ($options['default'] !== null || !$options['schemaDefault'] || !$entity->isNew()) {
return $options['default'];
}
return $this->_schemaDefault($part, $entity);
}
if (is_array($entity)) {
$key = array_pop($parts);
return isset($entity[$key]) ? $entity[$key] : null;
}
return null;
}
示例5: _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;
}
示例6: val
/**
* Get the current value for a given field.
*
* This method will coalesce the current request data and the 'defaults'
* array.
*
* @param string $field A dot separated path to the field a value
* is needed for.
* @return mixed
*/
public function val($field)
{
$val = $this->_request->data($field);
if ($val !== null) {
return $val;
}
if (empty($this->_context['defaults']) || !is_array($this->_context['defaults'])) {
return null;
}
return Hash::get($this->_context['defaults'], $field);
}
示例7: _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;
}
示例8: val
/**
* {@inheritDoc}
*/
public function val($field)
{
$val = $this->_request->data($field);
if ($val !== null) {
return $val;
}
if (empty($this->_context['entity'])) {
return null;
}
$parts = explode('.', $field);
$entity = $this->entity($parts);
if ($entity instanceof Document) {
return $entity->get(array_pop($parts));
}
}
示例9: val
/**
* Get the current value for a given field.
*
* This method will coalesce the current request data and the 'defaults'
* array.
*
* @param string $field A dot separated path to the field a value
* is needed for.
* @param array $options Options:
* - `default`: Default value to return if no value found in request
* data or context record.
* - `schemaDefault`: Boolean indicating whether default value from
* context's schema should be used if it's not explicitly provided.
* @return mixed
*/
public function val($field, $options = [])
{
$options += ['default' => null, 'schemaDefault' => true];
$val = $this->_request->data($field);
if ($val !== null) {
return $val;
}
if ($options['default'] !== null || !$options['schemaDefault']) {
return $options['default'];
}
if (empty($this->_context['defaults']) || !is_array($this->_context['defaults'])) {
return null;
}
return Hash::get($this->_context['defaults'], $field);
}
示例10: 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;
}
示例11: authenticate
/**
* Authenticate callback
*
* @param Request $request Cake request object.
* @param Response $response Cake response object.
* @return bool|mixed
*/
public function authenticate(Request $request, Response $response)
{
$data = $request->session()->read(Configure::read('Users.Key.Session.social'));
if (empty($data)) {
return false;
}
$socialMail = Hash::get((array) $data->info, Configure::read('Users.Key.Data.email'));
if (!empty($socialMail)) {
$data->email = $socialMail;
$data->validated = true;
} else {
$data->email = $request->data(Configure::read('Users.Key.Data.email'));
$data->validated = false;
}
$user = $this->_findOrCreateUser($data);
return $user;
}
示例12: val
/**
* Get the value for a given path.
*
* Traverses the entity data and finds the value for $path.
*
* @param string $field The dot separated path to the value.
* @return mixed The value of the field or null on a miss.
*/
public function val($field)
{
$val = $this->_request->data($field);
if ($val !== null) {
return $val;
}
if (empty($this->_context['entity'])) {
return null;
}
$parts = explode('.', $field);
$entity = $this->_getEntity($parts);
if (end($parts) === '_ids' && !empty($entity)) {
return $this->_extractMultiple($entity, $parts);
}
if ($entity instanceof Entity) {
return $entity->get(array_pop($parts));
}
return null;
}
示例13: val
/**
* Get the value for a given path.
*
* Traverses the entity data and finds the value for $path.
*
* @param string $field The dot separated path to the value.
* @return mixed The value of the field or null on a miss.
*/
public function val($field)
{
$val = $this->_request->data($field);
if ($val !== null) {
return $val;
}
if (empty($this->_context['entity'])) {
return null;
}
$parts = explode('.', $field);
$entity = $this->entity($parts);
if (end($parts) === '_ids' && !empty($entity)) {
return $this->_extractMultiple($entity, $parts);
}
if ($entity instanceof EntityInterface) {
return $entity->get(array_pop($parts));
} elseif (is_array($entity)) {
$key = array_pop($parts);
return isset($entity[$key]) ? $entity[$key] : null;
}
return null;
}
示例14: _validateToken
/**
* Validate the request data against the cookie token.
*
* @param \Cake\Network\Request $request The request to validate against.
* @throws \Cake\Network\Exception\InvalidCsrfTokenException when the CSRF token is invalid or missing.
* @return void
*/
protected function _validateToken(Request $request)
{
$cookie = $request->cookie($this->_config['cookieName']);
$post = $request->data($this->_config['field']);
$header = $request->header('X-CSRF-Token');
if (empty($cookie)) {
throw new InvalidCsrfTokenException(__d('cake', 'Missing CSRF token cookie'));
}
if ($post !== $cookie && $header !== $cookie) {
throw new InvalidCsrfTokenException(__d('cake', 'CSRF token mismatch.'));
}
}
示例15: testDataWritingFalsey
/**
* Test writing falsey values.
*
* @return void
*/
public function testDataWritingFalsey()
{
$request = new Request();
$request->data('Post.null', null);
$this->assertNull($request->data['Post']['null']);
$request->data('Post.false', false);
$this->assertFalse($request->data['Post']['false']);
$request->data('Post.zero', 0);
$this->assertSame(0, $request->data['Post']['zero']);
$request->data('Post.empty', '');
$this->assertSame('', $request->data['Post']['empty']);
}