本文整理汇总了PHP中Hash::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::get方法的具体用法?PHP Hash::get怎么用?PHP Hash::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rule
/**
* Add a rule to a column
*
* @return void
* @author Justin Palmer
**/
public function rule($column, Rule $rule)
{
//Make sure the property exists.
$this->model->hasProperty($column);
if ($rule instanceof RequiredRule) {
$this->required[] = $column;
}
//Get the rules for this property.
$rules = $this->rules->get($column);
if ($rules === null) {
$rules = array();
}
$rules[] = $rule;
$this->rules->set($column, $rules);
}
示例2: get_opening_hours
public function get_opening_hours($data = [])
{
if (!$this->exists()) {
throw new NotFoundException(__('Invalid Shop'));
}
if (empty($data)) {
$opening_time = $this->field('opening_time');
$closing_time = $this->field('closing_time');
$opening_val = (int) str_replace(':', '', $opening_time);
$closing_val = (int) str_replace(':', '', $closing_time);
$now = time();
$today = date('Y-m-d', $now);
if ($opening_val < 240000 && 0 < $closing_val % 12) {
$closing_date = date('Y-m-d', strtotime('+1 day', $now));
} else {
$closing_date = $today;
}
$closing_datetime = $closing_date . ' ' . $closing_time;
$opening_datetime = $today . ' ' . $opening_time;
} else {
$keys = ['opening', 'closing'];
foreach ($keys as $key) {
$field = "{$key}_datetime";
$path = "Shop.{$field}";
$datetime = Hash::get($data, $path);
${$field} = $this->deconstruct($field, $datetime);
}
}
return compact('opening_datetime', 'closing_datetime');
}
示例3: add
/**
* Adds new task
*
* @param string $command
* @param string $path
* @param array $arguments
* @param array $options
* - `unique` - if true and found active duplicates wont add new task
* - `dependsOn` - an array of task ids that must be done before this task starts
* @return bool
*/
public function add($command, $path, array $arguments = array(), array $options = array())
{
$dependsOn = (array) Hash::get($options, 'dependsOn');
$unique = (bool) Hash::get($options, 'unique');
unset($options['dependsOn'], $options['unique']);
$task = compact('command', 'path', 'arguments') + $options;
$task += array('timeout' => 60 * 60, 'status' => TaskType::UNSTARTED, 'code' => 0, 'stdout' => '', 'stderr' => '', 'details' => array(), 'server_id' => 0, 'scheduled' => null, 'hash' => $this->_hash($command, $path, $arguments));
$dependsOnIds = $this->find('list', array('fields' => array('id', 'id'), 'conditions' => array('hash' => $task['hash'], 'status' => array(TaskType::UNSTARTED, TaskType::DEFFERED, TaskType::RUNNING))));
if ($unique && $dependsOnIds) {
return false;
} elseif ($dependsOnIds) {
$dependsOn = array_merge($dependsOn, $dependsOnIds);
}
$this->create();
if ($dependsOn) {
$data = array($this->alias => $task, $this->DependsOnTask->alias => $dependsOn);
$success = $this->saveAssociated($data);
} else {
$success = $this->save($task);
}
if (!$success) {
return false;
} else {
return $this->read()[$this->alias];
}
}
示例4: defaultUserAttributeRole
/**
* UserAttributesRoleのデフォルト値
*
* * パスワード=自分/他人とも読み取り不可
* * ラベル項目=自分/他人とも書き込み不可
* * 会員管理が使用可=上記以外、自分・他人とも自分/他人の読み・書き可
* * 会員管理が使用不可
* ** 管理者以外、読み取り不可項目とする=自分/他人の読み・書き不可。※読めないのに書けるはあり得ないため。
* ** 管理者以外、書き込み不可項目とする=自分/他人の書き込み不可。
* ** 上記以外
* *** ハンドル・アバター=自分は、読み・書き可。他人は、読み取り可/書き込み不可。
* *** それ以外=自分は、読み・書き可。他人は、読み・書き不可。
*
* @param Model $model Model using this behavior
* @param array|string $userAttrSetting 配列:ユーザ属性設定データ、文字列:ユーザ属性キー
* @param bool $enableUserManager 有効かどうか
* @return array ユーザ属性ロールデータ
*/
public function defaultUserAttributeRole(Model $model, $userAttrSetting, $enableUserManager)
{
$model->loadModels(['UserAttributeSetting' => 'UserAttributes.UserAttributeSetting']);
$userAttrSetting = $model->UserAttributeSetting->create($userAttrSetting);
$userAttributeRole = array();
$userAttributeRole['UserAttributesRole']['self_readable'] = true;
$userAttributeRole['UserAttributesRole']['self_editable'] = true;
$userAttributeKey = $userAttrSetting['UserAttributeSetting']['user_attribute_key'];
if ($userAttributeKey === UserAttribute::PASSWORD_FIELD) {
$userAttributeRole['UserAttributesRole']['self_readable'] = false;
$userAttributeRole['UserAttributesRole']['other_readable'] = false;
} elseif ($enableUserManager) {
$userAttributeRole['UserAttributesRole']['other_readable'] = true;
} elseif (Hash::get($userAttrSetting, 'UserAttributeSetting.only_administrator_readable')) {
$userAttributeRole['UserAttributesRole']['self_readable'] = false;
$userAttributeRole['UserAttributesRole']['other_readable'] = false;
$userAttrSetting['UserAttributeSetting']['only_administrator_editable'] = true;
} else {
$userAttributeRole['UserAttributesRole']['self_readable'] = true;
$userAttributeRole['UserAttributesRole']['other_readable'] = in_array($userAttributeKey, $this->readableDefault, true);
}
$userAttributeRole['UserAttributesRole']['other_editable'] = false;
if ($userAttrSetting['UserAttributeSetting']['data_type_key'] === DataType::DATA_TYPE_LABEL) {
$userAttributeRole['UserAttributesRole']['self_editable'] = false;
} elseif ($enableUserManager) {
$userAttributeRole['UserAttributesRole']['other_editable'] = true;
} elseif (Hash::get($userAttrSetting, 'UserAttributeSetting.only_administrator_editable')) {
$userAttributeRole['UserAttributesRole']['self_editable'] = false;
}
return $userAttributeRole;
}
示例5: move
/**
* Resize a file uploaded
* @param string $path Path of the data, for instance to upload the file in data['Movie']['picture'] path would be Movie.picture
* @param string $dest Where to save the uploaded file
* @param integer $width
* @param integer $height
* @return boolean True if the image is uploaded.
*/
public function move($path, $dest, $width = 0, $height = 0)
{
$file = Hash::get($this->controller->request->data, $path);
if (empty($file['tmp_name'])) {
return false;
}
$tmp = TMP . $file['name'];
move_uploaded_file($file['tmp_name'], $tmp);
$info = pathinfo($file['name']);
$destinfo = pathinfo($dest);
$directory = dirname(IMAGES . $dest);
if (!file_exists($directory)) {
mkdir($directory, 0777, true);
}
if ($info['extension'] == $destinfo['extension'] && $width == 0) {
rename($tmp, IMAGES . $dest);
return true;
}
if (!file_exists($dest_file)) {
require_once APP . 'Plugin' . DS . 'Media' . DS . 'Vendor' . DS . 'imagine.phar';
$imagine = new Imagine\Gd\Imagine();
$imagine->open($tmp)->thumbnail(new Imagine\Image\Box($width, $height), Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND)->save(IMAGES . $dest, array('quality' => 90));
}
return true;
}
示例6: user
/**
* @param mix $key
* @return mixed
*/
public function user($key = null)
{
if (!is_null($key)) {
return Hash::get((array) $this->_userData, $key);
}
return $this->_userData;
}
示例7: 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);
$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);
}
示例8: price
public function price($price)
{
if (is_array($price)) {
$price = intval(Hash::get($price, 'Product.price'));
}
return Configure::read('Settings.price_prefix') . number_format($price, 0, '.', Configure::read('Settings.int_div')) . Configure::read('Settings.price_postfix');
}
示例9: deleteByUserId
public function deleteByUserId($id)
{
$favUser = $this->FavouriteUser->findByUserIdAndFavUserId($this->currUserID, $id);
$favUser = Hash::get($favUser, 'FavouriteUser.id');
$this->FavouriteUser->delete($favUser);
$this->redirect($this->referer());
}
示例10: getTmpName
/**
* Get the temporary name of the file.
*
* @param $data The data from the request.
* @return mixed String containing the temp path name if data is valid, otherwise false.
*/
public function getTmpName($data)
{
if (is_array($data)) {
return Hash::get($data, 'FileUpload.filename.tmp_name');
}
return false;
}
示例11: edit
/**
* edit
*
* @return void
*/
public function edit()
{
//会員権限リストを取得する
$userRoles = $this->UserRole->find('list', array('recursive' => -1, 'fields' => array('key', 'name'), 'conditions' => array('language_id' => Current::read('Language.id')), 'order' => array('id' => 'asc')));
$this->set('userRoles', $userRoles);
//リクエストセット
if ($this->request->is('post')) {
$data = $this->request->data['SiteSetting'];
$value = $data['Security.deny_ip_move']['0']['value'];
if (is_array($value)) {
$data['Security.deny_ip_move']['0']['value'] = implode('|', $value);
}
//登録処理
$this->request->data['SiteSetting'] = $data;
$this->SiteSetting->userRoles = $userRoles;
$this->SiteManager->saveData();
} else {
$this->request->data['SiteSetting'] = $this->SiteSetting->getSiteSettingForEdit(array('SiteSetting.key' => array('Upload.allow_extension', 'Security.deny_ip_move', 'Security.enable_bad_ips', 'Security.bad_ips', 'Security.enable_allow_system_plugin_ips', 'Security.allow_system_plugin_ips')));
$ips = $this->request->data['SiteSetting']['Security.allow_system_plugin_ips']['0']['value'];
if (!$this->SiteSetting->hasCurrentIp($ips)) {
$ips = Hash::get($_SERVER, 'REMOTE_ADDR');
$this->request->data['SiteSetting']['Security.allow_system_plugin_ips']['0']['value'] = $ips;
}
}
}
示例12: requireOtherFields
/**
* Checks if flag is on, required other fields
*
* @param object &$model use model
* @param array $check check data array
* @param mix $requireValue when check data value equal this value, then require other field
* @param array $others require data field names
* @param string $ope require condition AND or OR or XOR
* @return bool
*/
public function requireOtherFields(&$model, $check, $requireValue, $others, $ope)
{
$checkPatterns = array('AND' => array('midstream' => array('chk' => true, 'ret' => false), 'end' => array('ret' => true)), 'OR' => array('midstream' => array('chk' => false, 'ret' => true), 'end' => array('ret' => false)), 'XOR' => array('midstream' => array('chk' => false, 'ret' => false), 'end' => array('ret' => true)));
$ope = strtoupper($ope);
$checkPattern = $checkPatterns[$ope];
$value = array_values($check);
$value = $value[0];
if ($value != $requireValue) {
return true;
}
foreach ($others as $other) {
$checkData = Hash::get($model->data, $other);
$otherFieldsName = explode('.', $other);
// is_系のフィールドの場合、チェックボックスで実装され、OFFでも0という数値が入ってくる
// そうすると「Blank」判定してほしいのに「ある」と判定されてしまう
// なのでis_で始まるフィールドのデータの設定を確認するときだけは == falseで判定する
if (strncmp('is_', $otherFieldsName[count($otherFieldsName) - 1], 3) === 0) {
$ret = $checkData == false;
} else {
$ret = Validation::blank($checkData);
}
if ($ret == $checkPattern['midstream']['chk']) {
return $checkPattern['midstream']['ret'];
}
}
return $checkPattern['end']['ret'];
}
示例13: beforePaginate
/**
* beforePaginate callback
*
* @param CakeEvent $e
* @return void
*/
public function beforePaginate(CakeEvent $e)
{
$this->_checkRequiredPlugin();
$model = $this->_model();
$controller = $this->_controller();
$request = $this->_request();
$this->_ensureComponent($controller);
$this->_ensureBehavior($model);
$this->_commonProcess($controller, $model->name);
$query = $request->query;
if (!empty($request->query['_scope'])) {
$config = $this->config('scope.' . $request->query['_scope']);
if (empty($config)) {
$config = $this->_action()->config('scope.' . $request->query['_scope']);
}
$query = Hash::get((array) $config, 'query');
if (!empty($config['filter'])) {
$this->_setFilterArgs($model, $config['filter']);
}
} else {
$filterArgs = $this->_action()->config('scope');
if (!empty($filterArgs)) {
$this->_setFilterArgs($model, (array) $filterArgs);
}
}
// Avoid notice if there is no filterArgs
if (empty($model->filterArgs)) {
$this->_setFilterArgs($model, array());
}
$this->_setPaginationOptions($controller, $model, $query);
}
示例14: after
/**
* After migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function after($direction)
{
if ($direction === 'down') {
return true;
}
//UserAttributeSettingのdata_type_key変更
$update = array('data_type_key' => '\'select\'');
$conditions = array('data_type_key' => 'language');
$UserAttributeSetting = $this->generateModel('UserAttributeSetting');
if (!$UserAttributeSetting->updateAll($update, $conditions)) {
return false;
}
$UserAttribute = $this->generateModel('UserAttribute');
$userAttributes = $UserAttribute->find('list', array('recursive' => -1, 'fields' => array('language_id', 'id'), 'conditions' => array('key' => 'language')));
foreach ($this->records['UserAttributeChoice'] as $i => $record) {
$record['user_attribute_id'] = Hash::get($userAttributes, $record['language_id']);
$this->records['UserAttributeChoice'][$i] = $record;
}
foreach ($this->records as $model => $records) {
if (!$this->updateRecords($model, $records)) {
return false;
}
}
return true;
}
示例15: getSettings
/**
* Get all or a specific settings key
*
* @param string $path Hash::get() compatible path, NULL for everything
* @return mixed
*/
public function getSettings($path = null)
{
if (empty($path)) {
return $this->_settings;
}
return Hash::get($this->_settings, $path);
}