本文整理匯總了PHP中Q::normalize方法的典型用法代碼示例。如果您正苦於以下問題:PHP Q::normalize方法的具體用法?PHP Q::normalize怎麽用?PHP Q::normalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Q
的用法示例。
在下文中一共展示了Q::normalize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
/**
* 構造函數
*
* @param array $config
*
* @return Log
*/
function __construct(array $config = null)
{
$names = array('EMERG' => self::EMERG, 'ALERT' => self::ALERT, 'CRIT' => self::CRIT, 'ERR' => self::ERR, 'WARN' => self::WARN, 'NOTICE' => self::NOTICE, 'INFO' => self::INFO, 'DEBUG' => self::DEBUG);
$arr = isset($config['log_priorities']) ? Q::normalize($config['log_priorities']) : Q::normalize(Q::getIni('log_priorities'));
$this->_priorities = array('index' => array(), 'names' => array());
foreach ($arr as $item) {
if (isset($names[$item])) {
$this->_priorities['index'][$names[$item]] = $item;
$this->_priorities['names'][$item] = $names[$item];
}
}
$dir_tmp = isset($config['log_writer_dir']) ? $config['log_writer_dir'] : Q::getIni('log_writer_dir');
$dir = realpath($dir_tmp);
if (empty($dir)) {
$dir = realpath(Q::getIni('runtime_cache_dir'));
if (empty($dir)) {
// LC_MSG: 指定的日誌文件保存目錄不存在 "%s".
throw new QLog_Exception(__('指定的日誌文件保存目錄不存在 "%s".', $dir_tmp));
}
}
$filename = isset($config['log_writer_filename']) ? $config['log_writer_filename'] : Q::getIni('log_writer_filename');
$this->_filename = rtrim($dir, '/\\') . DS . $filename;
$chunk_size = isset($config['log_cache_chunk_size']) ? intval($config['log_cache_chunk_size']) : intval(Q::getIni('log_cache_chunk_size'));
$this->_cache_chunk_size = $chunk_size * 1024;
$this->append(__METHOD__, self::DEBUG);
}
示例2: UserAclRoles
function UserAclRoles($user_id = '')
{
$show_box['title'] = '獲取用戶全部角色';
$return_value = '';
$roles_idname = array();
$roles_id = array();
$sp_roles = Q::ini('appini/sp_role');
// 第一步:直接從中間表獲得用戶的全部角色ID
$user_roles = UsersHaveRoles::find('user_id = ?', intval($user_id))->asArray()->getAll();
//dump($user_roles);
// 取出有用的ID,去除deny的ID
foreach ($user_roles as $value) {
if ($value['is_include']) {
$roles_id[] = $value['role_id'];
}
}
//dump ( $roles_id);
$roles_arr = Roles::find('role_id in (?)', Q::normalize($roles_id, ","))->asArray()->getAll();
foreach ($roles_arr as $value) {
$roles_idname[$value['role_id']] = $value['rolename'];
}
//dump($roles_idname);
if (in_array($sp_roles['REPEAL'], $roles_idname)) {
$return_value = array($value['role_id'] => $sp_roles['REPEAL']);
return $return_value;
} elseif (in_array($sp_roles['FREEZE'], $roles_idname)) {
$return_value = array($value['role_id'] => $sp_roles['FREEZE']);
return $return_value;
} elseif (in_array($sp_roles['UNCHECKED'], $roles_idname)) {
$return_value = array($value['role_id'] => $sp_roles['UNCHECKED']);
return $return_value;
} else {
return $roles_idname;
}
}
示例3: testNormalize
/**
* @dataProvider normalizeProvider
*/
function testNormalize($items, $test)
{
$data = array('key1', 'key2', 'key3');
if ($test) {
$this->assertEquals($data, Q::normalize($items, $test));
} else {
$this->assertEquals($data, Q::normalize($items));
}
}
示例4: uploadAllowedTypes
/**
* 允許上傳的文件類型
*
* @param stirng $types
* @return array
*/
function uploadAllowedTypes($types = null)
{
if ($types) {
$this->_upload_allowed_types = Q::normalize($types);
return $this;
} else {
return $this->_upload_allowed_types;
}
}
示例5: setTags
function setTags($tags)
{
if (is_array($tags) || $tags instanceof Iterator) {
$arr = array();
foreach ($tags as $tag) {
$arr[] = $tag->label;
}
$tags = $arr;
}
return implode(' ', Q::normalize($tags, ' '));
}
示例6: createForm
static function createForm($id, $action)
{
$form = new Form_Admin_Links($id, $action);
$form->add(QForm::ELEMENT, 'name', array('_ui' => 'textbox', '_label' => '友情鏈接名稱', '_req' => true, '_tips' => '友情鏈接的網站名'))->add(QForm::ELEMENT, 'url', array('_ui' => 'textbox', '_label' => '網站地址', '_req' => true, '_tips' => '友情鏈接網站的網址'))->add(QForm::ELEMENT, 'link_id', array('_ui' => 'hidden'))->add(QForm::ELEMENT, 'img', array('_ui' => 'admin_picpreview', '_label' => '已上傳圖片', 'attr' => array('dir' => 'links')))->add(QForm::ELEMENT, 'ico', array('_ui' => 'upload', '_label' => '上傳圖標', '_tips' => ''))->add(QForm::ELEMENT, 'order_num', array('_ui' => 'textbox', '_label' => '排序', 'value' => 0));
$form->addValidations(Links::meta());
//上傳圖片的限製
$types = Q::normalize(Q::ini('appini/teapics/upload_allowed_types'));
$size = intval(Q::ini('appini/teapics/upload_allowed_size') * 1024);
$dim = Q::ini('appini/teapics/img_pic_width') . 'x' . Q::ini('appini/teapics/img_pic_height');
$form['ico']->_tips = sprintf($form['ico']->_tips, implode('/', $types), $size / 1024, $dim);
$form->selectUploadElement('ico')->uploadAllowedSize($size)->uploadAllowedTypes($types)->enableSkipUpload();
//表單驗證規則
return $form;
}
示例7: _createFormConfig
/**
* 從配置文件中創建表單
* @param string $action 表單的url
* @param string $configName 配置文件的名字
* @return Form_Tea $form
*/
protected static function _createFormConfig($action, $configName)
{
$form = new Form_Admin_Tea('tea_form', $action);
$filename = rtrim(dirname(__FILE__), '/\\') . DS . $configName;
$form->loadFromConfig(Helper_YAML::load($filename));
$form->addValidations(Tea::meta());
//圖片的路徑
$form['thumb_filename']->dir = Q::ini('appini/teapics/img_dir');
//上傳圖片的限製
$types = Q::normalize(Q::ini('appini/teapics/upload_allowed_types'));
$size = intval(Q::ini('appini/teapics/upload_allowed_size') * 1024);
$dim = Q::ini('appini/teapics/img_pic_width') . 'x' . Q::ini('appini/teapics/img_pic_height');
$form['postfile']->_tips = sprintf($form['postfile']->_tips, implode('/', $types), $size / 1024, $dim);
// 茶葉類別
// $teatype = new TeaType();
// $form['type_id']->items=$teatype->list;
$form->selectUploadElement('postfile')->uploadAllowedSize($size)->uploadAllowedTypes($types)->enableSkipUpload();
return $form;
}
示例8: bind
/**
* 綁定行為插件
*/
function bind()
{
$props = Q::normalize($this->_settings['assoc_props']);
foreach ($props as $prop_name) {
if (empty($this->_meta->props[$prop_name]) || !$this->_meta->props[$prop_name]['assoc']) {
// LC_MSG: 類 "%s" 的 "%s" 屬性不是一個關聯.
throw new QDB_ActiveRecord_Behavior_Exception(__('類 "%s" 的 "%s" 屬性不是一個關聯.', $this->_meta->class_name, $prop_name));
}
$assoc_type = $this->_meta->props[$prop_name]['assoc'];
$suffix = $this->_meta->props[$prop_name]['assoc_class'];
$arg = array($prop_name);
if ($assoc_type == QDB::HAS_MANY) {
$this->_addDynamicMethod("add{$suffix}", array($this, 'addRelated'), $arg);
} elseif ($assoc_type == QDB::MANY_TO_MANY) {
$this->_addDynamicMethod("bind{$suffix}", array($this, 'bindRelated'), $arg);
$this->_addDynamicMethod("unbind{$suffix}", array($this, 'unbindRelated'), $arg);
$this->_addDynamicMethod("unbindAll{$suffix}", array($this, 'unbindAllRelated'), $arg);
}
}
}
示例9: _checkUniqueness
protected function _checkUniqueness(QDB_ActiveRecord_Abstract $obj, QDB_Cond $more_cond = null, $ignore_id = false)
{
$check_props = Q::normalize($this->_settings['check_props']);
if (empty($check_props)) {
return;
}
$checks = array();
$error = array();
foreach ($check_props as $check) {
if ($ignore_id && $check == $obj->idname()) {
continue;
}
if (strpos($check, '+') !== false) {
$props = Q::normalize($check, '+');
$cond = array();
foreach ($props as $prop_name) {
$cond[$prop_name] = $obj->{$prop_name};
}
} else {
$cond = array($check => $obj->{$check});
$props = $check;
}
if (!is_null($more_cond)) {
$cond[] = $more_cond;
}
$test = $this->_meta->find($cond)->count()->query();
if ($test['row_count'] < 1) {
continue;
}
if (isset($this->_settings['error_messages'][$check])) {
$error[$check] = array($check => $this->_settings['error_messages'][$check]);
} else {
$error[$check] = array($check => "{$check} duplicated");
}
}
if (!empty($error)) {
throw new QDB_ActiveRecord_ValidateFailedException($error, $obj);
}
}
示例10: _processMeta
protected function _processMeta($meta, $allows_tags = null)
{
if ($allows_tags) {
$allows_tags = Q::normalize($allows_tags);
}
$tags = preg_split('/^\\s*@/m', $meta, -1, PREG_SPLIT_NO_EMPTY);
$arr = array();
foreach ($tags as $tag) {
$segs = preg_split('/\\s+/', trim($tag), 2);
$tag_name = $segs[0];
$param = isset($segs[1]) ? trim($segs[1]) : '';
if ($allows_tags && !in_array($tag_name, $allows_tags)) {
continue;
}
$tag_method = '_processTag' . ucfirst($tag_name);
if (method_exists($this, $tag_method)) {
$this->{$tag_method}($param);
} elseif (property_exists($this, $tag_name)) {
$this->{$tag_name} = $param;
} else {
throw new API_Doc_NotSupportedTagException($this, $tag_name);
}
}
}
示例11: aclDataDyn
/**
* 獲得用戶的 ACL 數據
*
* ACL 數據一般包含用戶 ID 和用戶名,通常用於配合 QACL 實現基於角色的訪問控製。
*
* 用法:
* @code php
* $data = $member->aclData();
* dump($data);
* @endcode
*
* 要返回的數據由 acl_data_props 設置來指定。不過不管指定了哪些屬性,aclData()
* 的返回結果中總是為包含名為 id 的鍵。該鍵的值是用戶對象的 ID。
*
* 也可以在獲得 ACL 數據時通過 $props 參數指定要返回的屬性值:
* @code php
* $data = $member->aclData('email, addr');
* @endcode
*
* @param QDB_ActiveRecord_Abstract $member 用戶對象
* @param string $props 要返回的屬性值
*
* @return array 包含指定屬性值的數組
*/
function aclDataDyn(QDB_ActiveRecord_Abstract $member, $props = null)
{
if (!$props) {
$props = $this->_settings['acl_data_props'];
}
$props = Q::normalize($props);
$data = array();
foreach ($props as $pn) {
$data[$pn] = $member[$pn];
}
$data['id'] = $member->id();
return $data;
}
示例12: normalize
/**
* 對 ACL 整理,返回整理結果
*
* @param array $acl 要整理的 ACL
*
* @return array
*/
function normalize(array $acl)
{
$acl = array_change_key_case($acl, CASE_LOWER);
$ret = array();
$keys = array('allow', 'deny');
foreach ($keys as $key) {
do {
if (!isset($acl[$key])) {
$values = self::ACL_NULL;
break;
}
$acl[$key] = strtolower($acl[$key]);
if ($acl[$key] == self::ACL_EVERYONE || $acl[$key] == self::ACL_HAS_ROLE || $acl[$key] == self::ACL_NO_ROLE || $acl[$key] == self::ACL_NULL) {
$values = $acl[$key];
break;
}
$values = Q::normalize($acl[$key]);
if (empty($values)) {
$values = self::ACL_NULL;
}
} while (false);
$ret[$key] = $values;
}
return $ret;
}
示例13: flush
/**
* 將緩存的日誌信息寫入實際存儲,並清空緩存
*/
function flush()
{
if (empty($this->_log)) {
return;
}
// 更新日誌記錄優先級
$keys = Q::normalize(Q::ini('log_priorities'));
$arr = array();
foreach ($keys as $key) {
if (!isset($this->_priorities[$key])) {
continue;
}
$arr[$key] = true;
}
$this->_priorities = $arr;
// 確定日誌寫入目錄
$dir = realpath(Q::ini('log_writer_dir'));
if ($dir === false || empty($dir)) {
$dir = realpath(Q::ini('runtime_cache_dir'));
if ($dir === false || empty($dir)) {
// LC_MSG: 指定的日誌文件保存目錄不存在 "%s".
if ($this->_destruct) {
return;
} else {
throw new QLog_Exception(__('指定的日誌文件保存目錄不存在 "%s".', Q::ini('log_writer_dir')));
}
}
}
$filename = Q::ini('log_writer_filename');
$this->_filename = rtrim($dir, '/\\') . DS . $filename;
//if(is_file($this->_filename))
//unlink($this->_filename);
$chunk_size = intval(Q::ini('log_cache_chunk_size'));
if ($chunk_size < 1) {
$chunk_size = 64;
}
$this->_cache_chunk_size = $chunk_size * 1024;
$this->_writeable = true;
// 寫入日誌
$string = '';
foreach ($this->_log as $offset => $item) {
list($time, $msg, $type) = $item;
unset($this->_log[$offset]);
// 過濾掉不需要的日誌條目
if (!isset($this->_priorities[$type])) {
continue;
}
$string .= date('c', $time) . " {$type}: {$msg}\n";
}
if ($string) {
$fp = fopen($this->_filename, 'a');
if ($fp && flock($fp, LOCK_EX)) {
fwrite($fp, $string);
flock($fp, LOCK_UN);
fclose($fp);
}
}
//unset($this->_log);
$this->_log = array();
$this->_cached_size = 0;
}
示例14: unsetProps
/**
* 刪除多個屬性
*
* @param string|array $props
*
* @return QForm_Element
*/
function unsetProps($props)
{
$props = Q::normalize($props);
foreach ($props as $prop) {
unset($this->_props[$prop]);
}
if (in_array('value', $props)) {
$this->setValue(null);
}
return $this;
}
示例15: _init1
/**
* 第一步初始化
*
* @param string $class
*/
protected function _init1($class)
{
// 從指定類獲得初步的定義信息
Q::loadClass($class);
$this->class_name = $class;
$ref = (array) call_user_func(array($class, '__define'));
/**
* 檢查是否是繼承
*/
if (!empty($ref['inherit'])) {
$this->inherit_base_class = $ref['inherit'];
/**
* 繼承類的 __define() 方法隻需要指定與父類不同的內容
*/
$base_ref = (array) call_user_func(array($this->inherit_base_class, '__define'));
$ref = array_merge_recursive($base_ref, $ref);
}
// 被繼承的類
$this->inherit_type_field = !empty($ref['inherit_type_field']) ? $ref['inherit_type_field'] : null;
// 設置表數據入口對象
$table_config = !empty($ref['table_config']) ? (array) $ref['table_config'] : array();
if (!empty($ref['table_class'])) {
$this->table = $this->_tableByClass($ref['table_class'], $table_config);
} else {
$this->table = $this->_tableByName($ref['table_name'], $table_config);
}
$this->table_meta = $this->table->columns();
// 根據字段定義確定字段屬性
if (empty($ref['props']) || !is_array($ref['props'])) {
$ref['props'] = array();
}
foreach ($ref['props'] as $prop_name => $config) {
$this->addProp($prop_name, $config);
}
// 將沒有指定的字段也設置為對象屬性
foreach ($this->table_meta as $prop_name => $field) {
if (isset($this->props2fields[$prop_name])) {
continue;
}
$this->addProp($prop_name, $field);
}
// 設置其他選項
if (!empty($ref['create_reject'])) {
$this->create_reject = array_flip(Q::normalize($ref['create_reject']));
}
if (!empty($ref['update_reject'])) {
$this->update_reject = array_flip(Q::normalize($ref['update_reject']));
}
if (!empty($ref['create_autofill']) && is_array($ref['create_autofill'])) {
$this->create_autofill = $ref['create_autofill'];
}
if (!empty($ref['update_autofill']) && is_array($ref['update_autofill'])) {
$this->update_autofill = $ref['update_autofill'];
}
if (!empty($ref['attr_accessible'])) {
$this->attr_accessible = array_flip(Q::normalize($ref['attr_accessible']));
}
if (!empty($ref['attr_protected'])) {
$this->attr_protected = array_flip(Q::normalize($ref['attr_protected']));
}
// 準備驗證規則
if (empty($ref['validations']) || !is_array($ref['validations'])) {
$ref['validations'] = array();
}
$this->validations = $this->_prepareValidationRules($ref['validations']);
// 設置對象 ID 屬性名
$pk = $this->table->getPK();
$this->idname = array();
foreach ($this->table->getPK() as $pk) {
$pn = $this->fields2props[$pk];
$this->idname[$pn] = $pn;
}
$this->idname_count = count($this->idname);
// 綁定行為插件
if (isset($ref['behaviors'])) {
$config = isset($ref['behaviors_settings']) ? $ref['behaviors_settings'] : array();
$this->bindBehaviors($ref['behaviors'], $config);
}
}