本文整理汇总了PHP中Cake\Utility\Hash::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::get方法的具体用法?PHP Hash::get怎么用?PHP Hash::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Hash
的用法示例。
在下文中一共展示了Hash::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _afterIdentifyUser
/**
* Update remember me and determine redirect url after user identified
* @param array $user user data after identified
* @param bool $socialLogin is social login
* @return array
*/
protected function _afterIdentifyUser($user, $socialLogin = false)
{
$socialKey = Configure::read('Users.Key.Session.social');
if (!empty($user)) {
$this->request->session()->delete($socialKey);
$this->Auth->setUser($user);
$event = $this->dispatchEvent(UsersAuthComponent::EVENT_AFTER_LOGIN);
if (is_array($event->result)) {
return $this->redirect($event->result);
}
$url = $this->Auth->redirectUrl();
return $this->redirect($url);
} else {
$message = __d('Users', 'Username or password is incorrect');
if ($socialLogin) {
$socialData = $this->request->session()->read($socialKey);
$socialDataEmail = null;
if (!empty($socialData->info)) {
$socialDataEmail = Hash::get((array) $socialData->info, Configure::read('data_email_key'));
}
$postedEmail = $this->request->data(Configure::read('Users.Key.Data.email'));
if (Configure::read('Users.Email.required') && empty($socialDataEmail) && empty($postedEmail)) {
return $this->redirect(['controller' => 'Users', 'action' => 'socialEmail']);
}
$message = __d('Users', 'There was an error associating your social network account');
}
$this->Flash->error($message, 'default', [], 'auth');
}
}
示例2: parseIndexes
/**
* Parses a list of arguments into an array of indexes
*
* @param array $arguments A list of arguments being parsed
* @return array
**/
public function parseIndexes($arguments)
{
$indexes = [];
$arguments = $this->validArguments($arguments);
foreach ($arguments as $field) {
preg_match('/^(\\w*)(?::(\\w*))?(?::(\\w*))?(?::(\\w*))?/', $field, $matches);
$field = $matches[1];
$type = Hash::get($matches, 2);
$indexType = Hash::get($matches, 3);
$indexName = Hash::get($matches, 4);
if (in_array($type, ['primary', 'primary_key'])) {
$indexType = 'primary';
}
if ($indexType === null) {
continue;
}
$indexUnique = false;
if ($indexType == 'primary') {
$indexUnique = true;
} elseif ($indexType == 'unique') {
$indexUnique = true;
}
$indexName = $this->getIndexName($field, $indexType, $indexName, $indexUnique);
if (empty($indexes[$indexName])) {
$indexes[$indexName] = ['columns' => [], 'options' => ['unique' => $indexUnique, 'name' => $indexName]];
}
$indexes[$indexName]['columns'][] = $field;
}
return $indexes;
}
示例3: resetToken
/**
* Resets user token
*
* @param string $reference User username or email
* @param array $options checkActive, sendEmail, expiration
*
* @return string
* @throws InvalidArgumentException
* @throws UserNotFoundException
* @throws UserAlreadyActiveException
*/
public function resetToken($reference, array $options = [])
{
if (empty($reference)) {
throw new InvalidArgumentException(__d('CakeDC/Users', "Reference cannot be null"));
}
$expiration = Hash::get($options, 'expiration');
if (empty($expiration)) {
throw new InvalidArgumentException(__d('CakeDC/Users', "Token expiration cannot be empty"));
}
$user = $this->_getUser($reference);
if (empty($user)) {
throw new UserNotFoundException(__d('CakeDC/Users', "User not found"));
}
if (Hash::get($options, 'checkActive')) {
if ($user->active) {
throw new UserAlreadyActiveException(__d('CakeDC/Users', "User account already validated"));
}
$user->active = false;
$user->activation_date = null;
}
if (Hash::get($options, 'ensureActive')) {
if (!$user['active']) {
throw new UserNotActiveException(__d('CakeDC/Users', "User not active"));
}
}
$user->updateToken($expiration);
$saveResult = $this->_table->save($user);
$template = !empty($options['emailTemplate']) ? $options['emailTemplate'] : 'CakeDC/Users.reset_password';
if (Hash::get($options, 'sendEmail')) {
$this->Email->sendResetPasswordEmail($saveResult, null, $template);
}
return $saveResult;
}
示例4: testGet
/**
* Test get()
*
* @return void
*/
public function testGet()
{
$data = array('abc', 'def');
$result = Hash::get($data, '0');
$this->assertEquals('abc', $result);
$result = Hash::get($data, 0);
$this->assertEquals('abc', $result);
$result = Hash::get($data, '1');
$this->assertEquals('def', $result);
$data = self::articleData();
$result = Hash::get(array(), '1.Article.title');
$this->assertNull($result);
$result = Hash::get($data, '');
$this->assertNull($result);
$result = Hash::get($data, '0.Article.title');
$this->assertEquals('First Article', $result);
$result = Hash::get($data, '1.Article.title');
$this->assertEquals('Second Article', $result);
$result = Hash::get($data, '5.Article.title');
$this->assertNull($result);
$default = array('empty');
$this->assertEquals($default, Hash::get($data, '5.Article.title', $default));
$this->assertEquals($default, Hash::get(array(), '5.Article.title', $default));
$result = Hash::get($data, '1.Article.title.not_there');
$this->assertNull($result);
$result = Hash::get($data, '1.Article');
$this->assertEquals($data[1]['Article'], $result);
$result = Hash::get($data, array('1', 'Article'));
$this->assertEquals($data[1]['Article'], $result);
}
示例5: basepath
/**
* Returns the basepath for the current field/data combination.
* If a `path` is specified in settings, then that will be used as
* the replacement pattern
*
* @return string
* @throws LogicException if a replacement is not valid for the current dataset
*/
public function basepath()
{
$defaultPath = 'webroot{DS}files{DS}{model}{DS}{field}{DS}';
$path = Hash::get($this->settings, 'path', $defaultPath);
if (strpos($path, '{primaryKey}') !== false) {
if ($this->entity->isNew()) {
throw new LogicException('{primaryKey} substitution not allowed for new entities');
}
if (is_array($this->table->primaryKey())) {
throw new LogicException('{primaryKey} substitution not valid for composite primary keys');
}
}
$replacements = ['{primaryKey}' => $this->entity->get($this->table->primaryKey()), '{model}' => $this->table->alias(), '{table}' => $this->table->table(), '{field}' => $this->field, '{year}' => date("Y"), '{month}' => date("m"), '{day}' => date("d"), '{time}' => time(), '{microtime}' => microtime(), '{DS}' => DIRECTORY_SEPARATOR];
if (preg_match_all("/{field-value:(\\w+)}/", $path, $matches)) {
foreach ($matches[1] as $field) {
$value = $this->entity->get($field);
if ($value === null) {
throw new LogicException(sprintf('Field value for substitution is missing: %s', $field));
} elseif (!is_scalar($value)) {
throw new LogicException(sprintf('Field value for substitution must be a integer, float, string or boolean: %s', $field));
} elseif (strlen($value) < 1) {
throw new LogicException(sprintf('Field value for substitution must be non-zero in length: %s', $field));
}
$replacements[sprintf('{field-value:%s}', $field)] = $value;
}
}
return str_replace(array_keys($replacements), array_values($replacements), $path);
}
示例6: getUser
public function getUser(Request $request)
{
if (!isset($_SESSION)) {
return false;
}
$provider = Hash::get($_SESSION, 'opauth.auth.provider');
if (!$provider) {
return false;
}
$uid = Hash::get($_SESSION, 'opauth.auth.uid');
if (!$uid) {
return false;
}
$userModel = $this->_config['userModel'];
list(, $model) = pluginSplit($userModel);
$fields = $this->_config['fields'];
$conditions = [$model . '.' . $fields['auth_provider'] => $provider, $model . '.' . $fields['auth_uid'] => $uid];
$scope = $this->_config['scope'];
if ($scope) {
$conditions = array_merge($conditions, $scope);
}
$table = TableRegistry::get($userModel)->find('all');
$contain = $this->_config['contain'];
if ($contain) {
$table = $table->contain($contain);
}
$result = $table->where($conditions)->hydrate(false)->first();
if (empty($result)) {
return false;
}
return $result;
}
示例7: filename
/**
* Returns the filename for the current field/data combination.
* If a `nameCallback` is specified in settings, then that callable
* will be invoked with the current upload data.
*
* @return string
*/
public function filename()
{
$processor = Hash::get($this->settings, 'nameCallback', null);
if (is_callable($processor)) {
return $processor($this->data, $this->settings);
}
return $this->data['name'];
}
示例8: __construct
public function __construct($moduleDefintion)
{
parent::__construct($moduleDefintion);
$moduleClass = Hash::get($moduleDefintion, 'meta.moduleId');
if ($moduleClass) {
$this->instance = new $moduleClass(Hash::get($moduleDefintion, 'data'));
}
}
示例9: _getVictor
protected function _getVictor()
{
$gameMembershipsCollection = new Collection($this->game_memberships);
$victor_member = $gameMembershipsCollection->indexBy('id')->max('points');
$victor['full_name'] = Hash::get($victor_member, 'member.full_name');
$victor['id'] = Hash::get($victor_member, 'member.id');
return $victor;
}
示例10: user
/**
* Get the user data of the current session.
*
* @param string|null $key Key in dot syntax.
* @return mixed Data
*/
public function user($key = null)
{
$user = $this->_getUser();
if ($key === null) {
return $user;
}
return Hash::get($user, $key);
}
示例11: __construct
public function __construct($cellDefinition)
{
parent::__construct($cellDefinition);
$this->grid = new Grid(Hash::get($cellDefinition, 'meta.grid.colWidth', 0), Hash::get($cellDefinition, 'meta.grid.baseWidth', 0));
foreach ($cellDefinition['data'] as $moduleDefintion) {
$this->data[] = new Module($moduleDefintion);
}
}
示例12: authorize
/**
* Check if the user is superuser
*
* @param type $user User information object.
* @param Request $request Cake request object.
* @return bool
*/
public function authorize($user, Request $request)
{
$user = (array) $user;
$superuserField = $this->config('superuser_field');
if (Hash::check($user, $superuserField)) {
return (bool) Hash::get($user, $superuserField);
}
return false;
}
示例13: link
/**
* Generate a link if the target url is authorized for the logged in user
*
* @param type $title link's title.
* @param type $url url that the user is making request.
* @param array $options Array with option data.
* @return string
*/
public function link($title, $url = null, array $options = [])
{
if ($this->isAuthorized($url)) {
$linkOptions = $options;
unset($linkOptions['before'], $linkOptions['after']);
return Hash::get($options, 'before') . $this->Html->link($title, $url, $linkOptions) . Hash::get($options, 'after');
}
return false;
}
示例14: findSearch
/**
* Callback fired from the controller.
*
* @param Query $query Query.
* @param array $options The options for the find.
* - `search`: Array of search arguments.
* - `collection`: Filter collection name.
* @return \Cake\ORM\Query The Query object used in pagination.
* @throws \Exception When missing search arguments.
*/
public function findSearch(Query $query, array $options)
{
if (!isset($options['search'])) {
throw new Exception('Custom finder "search" expects search arguments ' . 'to be nested under key "search" in find() options.');
}
$filters = $this->_getAllFilters(Hash::get($options, 'collection', 'default'));
$params = $this->_flattenParams((array) $options['search']);
$params = $this->_extractParams($params, $filters);
return $this->_processFilters($filters, $params, $query);
}
示例15: getEngine
/**
* Retrieves a queue engine
*
* @param \Psr\Log\LoggerInterface $logger logger
* @return \josegonzalez\Queuesadilla\Engine\Base
*/
public function getEngine($logger)
{
$config = Hash::get($this->params, 'config');
$engine = Queue::engine($config);
$engine->setLogger($logger);
if (!empty($this->params['queue'])) {
$engine->config('queue', $this->params['queue']);
}
return $engine;
}