本文整理汇总了PHP中Cake\Utility\Hash类的典型用法代码示例。如果您正苦于以下问题:PHP Hash类的具体用法?PHP Hash怎么用?PHP Hash使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Hash类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dump
/**
* {@inheritdoc}
*
* @param string $key The identifier to write to.
* @param array $data The data to dump.
* @return bool True on success or false on failure.
*/
public function dump($key, array $data)
{
$data = Hash::flatten($data);
array_walk($data, [$this, '_persist'], $key);
array_filter($data);
return (bool) $data;
}
示例2: api
/**
* Wrap Moxiemanager's api.php in a controller action.
*
* @return void
*/
public function api()
{
try {
$pluginPath = Plugin::path('CkTools');
define('MOXMAN_CLASSES', $pluginPath . 'src/Lib/moxiemanager/classes');
define('MOXMAN_PLUGINS', $pluginPath . 'src/Lib/moxiemanager/plugins');
define('MOXMAN_ROOT', $pluginPath . 'src/Lib/moxiemanager');
define('MOXMAN_API_FILE', __FILE__);
$appConfig = Configure::read('CkTools.moxiemanager');
Configure::load('CkTools.moxiemanager');
$moxieManagerConfig = Configure::read('moxiemanager');
if (is_array($appConfig)) {
$moxieManagerConfig = Hash::merge($moxieManagerConfig, $appConfig);
}
$GLOBALS['moxieManagerConfig'] = $moxieManagerConfig;
require_once MOXMAN_CLASSES . '/MOXMAN.php';
$context = \MOXMAN_Http_Context::getCurrent();
$pluginManager = \MOXMAN::getPluginManager();
foreach ($pluginManager->getAll() as $plugin) {
if ($plugin instanceof \MOXMAN_Http_IHandler) {
$plugin->processRequest($context);
}
}
} catch (Exception $e) {
\MOXMAN_Exception::printException($e);
}
return $this->render(false, false);
}
示例3: mergeConfig
/**
* Merge Configuration
*
* @param string $key Configure key
* @param array $config New configuration to merge
* @param return array Array of merged configurations
*/
public static function mergeConfig($key, $config)
{
$values = Configure::read($key);
$values = Hash::merge((array) $values, $config);
Configure::write($key, $values);
return $values;
}
示例4: index
/**
* Index method
*
* @return void
*/
public function index()
{
if ($this->request->is(['post', 'put'])) {
$settings = $this->Settings->find('all')->all();
$settings = $this->Settings->patchEntities($settings, $this->request->data()['Setting']);
$result = $this->Settings->connection()->transactional(function () use($settings) {
foreach ($settings as $setting) {
$result = $this->Settings->save($setting, ['atomic' => false]);
if (!$result) {
return false;
}
}
return true;
});
if ($result) {
$settings = $this->Settings->find()->combine('path', 'value')->toArray();
ksort($settings);
$settings = Hash::expand($settings);
Settings::dump('config', 'default', $settings);
$this->Flash->success('The settings has been saved.');
$this->redirect(['action' => 'index']);
} else {
$this->Flash->error('The settings could not be saved. Please, try again.');
}
}
$settings = $this->Settings->find('extended')->find('editable')->toArray();
$this->set('settings', $settings['editable']);
}
示例5: __construct
/**
* Creates a Transport instance
*
* @param array $config transport-specific configuration options
*/
public function __construct(array $config)
{
$config = Hash::merge(Configure::read('Notifications.transports.sms'), $config);
parent::__construct($config);
$keys = Configure::read('Notifications.transports.sms');
$this->_smsClient = new \WebSmsCom_Client($keys['username'], $keys['password'], $keys['gateway']);
}
示例6: initialize
/**
* Initialization hook method.
*
* @return void
*/
public function initialize()
{
parent::initialize();
if (Configure::read('Swagger')) {
$this->config = Hash::merge(static::$defaultConfig, Configure::read('Swagger'));
}
}
示例7: format
/**
* Get format permission data.
*
* @param $acos
* @param array $aros
* @param array $options
* @return array
* @SuppressWarnings("unused")
*/
public function format($acos, array $aros, array $options = [])
{
$options = Hash::merge(['perms' => true, 'model' => 'Roles'], $options);
$permissions = [];
/** @var \Acl\Model\Entity\Aco $aco */
foreach ($acos as $aco) {
$acoId = $aco->get('id');
$acoAlias = $aco->get('alias');
$path = $this->Acos->find('path', ['for' => $acoId]);
$path = join('/', collection($path)->extract('alias')->toArray());
$data = ['path' => $path, 'alias' => $acoAlias, 'depth' => substr_count($path, '/')];
foreach ($aros as $key => $aroId) {
$role = ['foreign_key' => $key, 'model' => $options['model']];
if ($options['perms']) {
$isCheck = $this->check($role, $path);
if ($key == Role::ADMIN_ID || $isCheck) {
$data['roles'][$key] = 1;
} else {
$data['roles'][$key] = (int) $isCheck;
}
}
$permissions[$acoId] = new Data($data);
}
}
return $permissions;
}
示例8: beforeDispatch
/**
* Callback for Routing.beforeDispatch event.
*
* @param \Cake\Event\Event $event The event instance.
*
* @return \Cake\Network\Response Response instance.
*/
public function beforeDispatch(Event $event)
{
$request = $event->data['request'];
$response = $event->data['response'];
$path = urldecode($request->url);
if (Configure::read('Glide.secureUrls')) {
SignatureFactory::create(Security::salt())->validateRequest('/' . $path, $request->query);
}
$server = ServerFactory::create(Configure::read('Glide.serverConfig'));
$cache = Configure::read('Glide.cache');
if ($cache) {
$timestamp = $server->getSource()->getTimestamp($server->getSourcePath($path));
$response->modified($timestamp);
if (!$response->checkNotModified($request)) {
$response = $server->getImageResponse($path, $request->query);
}
$response->cache($timestamp, $cache);
} else {
$response = $server->getImageResponse($path, $request->query);
}
$headers = Hash::filter((array) Configure::read('Glide.headers'));
foreach ($headers as $key => $value) {
$response->header($key, $value);
}
return $response;
}
示例9: 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;
}
示例10: setJraOption
/**
* Sets a JSON REST API option.
*
* @param mixed $path
* @param mixed $value
*/
public function setJraOption($path, $value)
{
if (!isset($this->jraOptions)) {
$this->jraOptions = [];
}
$this->jraOptions = Hash::insert($this->jraOptions, $path, $value);
}
示例11: loadDataCsv
public function loadDataCsv($fileName, $column_list, $delimiter = ",", $array_encoding = 'utf8', $import_encoding = 'sjis-win')
{
//保存をするのでモデルを読み込み
try {
$data = array();
$csvData = array();
$file = fopen($fileName, "r");
while ($data = $this->fgetcsv_reg($file, 65536, $delimiter)) {
//CSVファイルを","区切りで配列に
mb_convert_variables($array_encoding, $import_encoding, $data);
$csvData[] = $data;
}
$i = 0;
foreach ($csvData as $line) {
$this_data = array();
foreach ($column_list as $k => $v) {
if (isset($line[$k])) {
//先頭と末尾の"を削除
$b = $line[$k];
//カラムの数だけセット
$this_data = Hash::merge($this_data, array($v => $b));
} else {
$this_data = Hash::merge($this_data, array($v => ''));
}
}
$data[$i] = $this_data;
$i++;
}
} catch (\Exception $e) {
return false;
}
return $data;
}
示例12: 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);
}
示例13: 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;
}
示例14: index
/**
* Index method
*
* @return \Cake\Network\Response|null
*/
public function index()
{
// Get all tag IDs associated with members
$tags = $this->Tags->find('all')->find('forMembers')->select(['id', 'parent_id'])->toArray();
$memberTagIds = Hash::extract($tags, '{n}.id');
// Get all of those tags' parent IDs
$tagParentIds = Hash::extract($tags, '{n}.parent_id');
// Collect all parent tags that lead from member tags to the tag tree root
$tagIds = $memberTagIds;
while (!empty($tagParentIds)) {
// Search for unrecognized parents
$parentsToFind = [];
foreach ($tagParentIds as $tagId) {
if (!in_array($tagId, $tagIds)) {
$parentsToFind[] = $tagId;
}
}
if (empty($parentsToFind)) {
break;
}
// Add these parent tag IDs to the full list
$additionalTags = $this->Tags->find('all')->where([function ($exp, $q) use($parentsToFind) {
return $exp->in('id', $parentsToFind);
}])->select(['id', 'parent_id'])->order(['Tags.name' => 'ASC'])->toArray();
$tagIds = array_merge(Hash::extract($additionalTags, '{n}.id'), $tagIds);
// Set up next round of searching for parents
$tagParentIds = Hash::extract($additionalTags, '{n}.parent_id');
}
$tags = $this->Tags->find('all')->find('threaded')->where([function ($exp, $q) use($tagIds) {
return $exp->in('id', $tagIds);
}])->select(['id', 'name', 'slug', 'parent_id'])->order(['Tags.name' => 'ASC'])->all();
$this->set(['pageTitle' => 'Art Tags', 'tags' => $tags, 'memberTagIds' => $memberTagIds]);
}
示例15: _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');
}
}