本文整理汇总了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);
}
}