本文整理汇总了PHP中Set::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::normalize方法的具体用法?PHP Set::normalize怎么用?PHP Set::normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set::normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadAsset
/**
* loadAsset
* Load CSS & JS
* @param type $widget
* @param type $option
*/
public function loadAsset($widget = 'jqueryui', $option = array('inline' => false))
{
$asset_path = $this->settings['asset_path'];
$assets = Set::normalize($this->settings['runtimes'], false);
// gears,html5,flash,browserplus,silverlight,html4
echo $this->Html->script($asset_path . 'plupload', array('inline' => $option['inline']));
if (count($assets) > 2) {
echo $this->Html->script($asset_path . "plupload.full.js", array('inline' => $option['inline']));
} else {
foreach ($assets as $asset) {
echo $this->Html->script($asset_path . "plupload.{$asset}", array('inline' => $option['inline']));
}
}
if (!empty($this->settings['locale'])) {
echo $this->Html->script($asset_path . 'i18n/' . $this->settings['locale'], array('inline' => $option['inline']));
}
switch ($widget) {
case 'jquery':
echo $this->Html->script($asset_path . 'jquery.plupload.queue/jquery.plupload.queue', array('inline' => false));
echo $this->Html->css($asset_path . 'jquery.plupload.queue/css/jquery.plupload.queue', null, array('inline' => false));
break;
case 'jqueryui':
default:
echo $this->Html->script($asset_path . 'jquery.ui.plupload/jquery.ui.plupload', array('inline' => false));
echo $this->Html->css($asset_path . 'jquery.ui.plupload/css/jquery.ui.plupload', null, array('inline' => false));
break;
}
}
示例2: cakeArrayToArray
public function cakeArrayToArray($data, $options = array())
{
$options += array('fields' => array(), 'models' => array());
$options['fields'] = Set::normalize($options['fields'], false);
$options['models'] = Set::normalize($options['models'], false);
$options += array('defaultModel' => count($options['models']) == 1 ? $options['models'][0] : null);
$firstRow = true;
$array = array();
foreach ($data as $item) {
foreach ($item as $model => $fields) {
if ($options['models'] && !in_array($model, $options['models'])) {
continue;
}
foreach ($fields as $field => $value) {
if ($options['fields'] && !in_array($field, $options['fields']) && !in_array("{$model}.{$field}", $options['fields'])) {
continue;
}
if ($firstRow) {
if ($model == $options['defaultModel']) {
$array[0][] = $field;
} else {
$array[0][] = "{$model}.{$field}";
}
}
$row[] = $value;
}
$array[] = $row;
}
$firstRow = false;
}
return $array;
}
示例3: _setSlugOptions
protected function _setSlugOptions()
{
foreach (Set::normalize($this->options['slugs']) as $slug => $options) {
$defaultBySlug = array('display' => $slug);
$this->_slugOptions[$slug] = Set::merge(array_intersect_key($this->options, array_flip(array('model', 'urlencode'))), $defaultBySlug, self::$defaultSlugOptions, $options);
}
}
示例4: loadComponent
/**
* Loads a Component
*
* @param string $component Name of component to load
* @return Object loaded component
**/
public function loadComponent($settings = array())
{
if (!isset($this->Controller)) {
$this->loadController();
}
$component = new $this->componentClass(null);
if (method_exists($component, 'initialize')) {
$component->initialize($this->Controller, $settings);
}
if (isset($component->components) && is_array($component->components)) {
$components = (array) Set::normalize($component->components);
foreach (array_keys($components) as $c) {
$this->Controller->Component->_loadComponents($component, $c);
}
foreach ($components as $c => $config) {
list($plugin, $c) = pluginSplit($c, true, null);
if (method_exists($component->{$c}, 'initialize')) {
$component->{$c}->initialize($this->Controller, $config);
}
if (method_exists($component->{$c}, 'startup')) {
$component->{$c}->startup($this->Controller);
}
}
}
$this->{$this->componentName} = $this->Controller->{$this->componentName} = $component;
return $this->{$this->componentName};
}
示例5: parse
function parse($html = null, $blockName = 'document', $blockParams = null)
{
if (empty($html)) {
return;
}
$images = Set::normalize($html, false);
foreach ($images as &$image) {
if (!strpos($image, '://') && $image[0] != '/') {
$image = "img/{$image}";
}
$image = $this->_getHelper('SlHtml')->webroot($image);
SlConfigure::append("Asset.js.ready", "\$.preloadImages({$images})");
}
SlConfigure::write('Asset.js.footer.imagePreloader.after', <<<end
jQuery.preLoadImagesCache = [];
// Arguments are image paths relative to the current page.
jQuery.preLoadImages = function() {
var args_len = arguments.length;
for (var i = args_len; i--;) {
var cacheImage = document.createElement('img');
cacheImage.src = arguments[i];
jQuery.preLoadImagesCache.push(cacheImage);
}
}
end
);
}
示例6: _findJoin
function _findJoin(&$Model, $dummy, $state, $query, $results = array())
{
if ($state == 'after') {
return $results;
}
if (!isset($query[$this->optionName])) {
return $query;
}
$tojoin = Set::normalize($query[$this->optionName]);
$joins = isset($query['joins']) ? $query['joins'] : array();
foreach ($tojoin as $alias => $options) {
// Model::__associations is private property
foreach ($this->associations as $association) {
if (isset($Model->{$association}[$alias])) {
$join = $this->generateJoins($Model, $alias, $Model->{$association}[$alias], $association, $options);
if (!empty($join)) {
$joins = Set::merge($joins, $join);
$Model->unbindModel(array($association => array($alias)));
}
}
}
}
$query['joins'] = $joins;
return $query;
}
示例7: beforeFind
function beforeFind(&$Model, $query = array())
{
extract($this->settings);
if (!isset($query['virtualFields'])) {
return true;
}
$virtualFields = Set::normalize($query['virtualFields']);
unset($query['virtualFields']);
$blackList = array();
foreach ($virtualFields as $key => $sql) {
if ($sql !== false && empty($sql) || $sql === true) {
if (isset($Model->{$collectionName}[$key])) {
$virtualFields[$key] = $Model->{$collectionName}[$key];
} else {
unset($virtualFields[$key]);
}
} else {
$blackList[] = $key;
unset($virtualFields[$key]);
}
}
if (!empty($virtualFields) || !empty($blackList)) {
$this->__virtualFieldsBackup[$Model->alias] = $Model->virtualFields;
$Model->virtualFields = array_merge($Model->virtualFields, $virtualFields);
if (!empty($blackList)) {
foreach ($blackList as $key) {
if (isset($Model->virtualFields[$key])) {
unset($Model->virtualFields[$key]);
}
}
}
}
return $query;
}
示例8: mergeVars
function mergeVars($admin, $configuration)
{
if (empty($configuration)) {
$configuration = array($this->defaults);
}
$schema = $admin->modelObj->schema();
foreach ($configuration as $i => $config) {
foreach ($this->defaults as $key => $value) {
if (!isset($config[$key])) {
$configuration[$i][$key] = $value;
}
}
$fields = array();
if (empty($configuration[$i]['fields']) || in_array('*', (array) $configuration[$i]['fields'])) {
// $fields is all fields
foreach (array_keys($schema) as $field) {
$fields[$field] = array('label' => Inflector::humanize($field));
}
}
if (!empty($configuration[$i]['fields'])) {
$configuration[$i]['fields'] = Set::normalize($configuration[$i]['fields']);
foreach ((array) $configuration[$i]['fields'] as $field => $config) {
if ($field === '*') {
continue;
}
if (empty($configuration[$i])) {
$config = array();
} else {
if (is_string($config)) {
$config = array('label' => $config);
}
}
if (empty($config['label'])) {
$config['label'] = Inflector::humanize($field);
}
$fields[$field] = $config;
}
}
if (!empty($configuration[$i]['exclude'])) {
foreach ($configuration[$i]['exclude'] as $field) {
if (in_array($field, array_keys($fields))) {
$fields = array_diff_key($fields, array($field => $field));
}
}
}
if (!empty($configuration[$i]['hidden'])) {
foreach ((array) $configuration[$i]['hidden'] as $field) {
if (in_array($field, array_keys($fields))) {
$fields[$field]['type'] = 'hidden';
}
}
}
$configuration[$i]['fields'] = $fields;
$configuration[$i]['classes'] = (string) $configuration[$i]['classes'];
$configuration[$i]['description'] = (string) $configuration[$i]['description'];
}
return $configuration;
}
示例9: append
public function append($name, $settings = array())
{
if (is_array($name)) {
foreach (Set::normalize($name) as $n => $settings) {
$this->__set($n, $settings);
}
return true;
}
return $this->__set($name, $settings);
}
示例10: admin_index
public function admin_index($activeSection = null)
{
$this->set('sections', $sections = SlConfigure::read2("Config.sections"));
foreach ($sections as $section => $settings) {
if (!SlAuth::isAuthorized('config' . Inflector::camelize($section))) {
unset($sections[$i]);
}
}
if (isset($this->data['_section'])) {
$activeSection = $this->data['_section'];
}
if (empty($activeSection) || !isset($sections[$activeSection])) {
$activeSection = reset(array_keys($sections));
}
$settings = $this->_getSettings($activeSection);
$this->set('title', __t(SlConfigure::read2("Config.sections.{$activeSection}")));
if ($this->data) {
$locales = SlConfigure::read('I18n.locales');
foreach ($settings as $name => &$setting) {
if (is_int($name)) {
$name = "setting_{$name}";
}
if ($setting['collection'] == 'user') {
$setting['collection'] = 'User' . SlAuth::user('id');
}
if (empty($setting['translate'])) {
if (isset($this->data[$name])) {
$value = $this->data[$name];
if (isset($setting['type']) && $setting['type'] == 'json') {
$value = json_decode($value, true);
} elseif (isset($setting['type']) && $setting['type'] == 'array') {
$value = Set::normalize($value, false);
}
SlConfigure::write($setting['name'], $value, true, $setting['collection']);
}
} else {
foreach ($locales as $locale) {
if (isset($this->data["{$name}_{$locale}"])) {
$value = $this->data["{$name}_{$locale}"];
if (isset($setting['type']) && $setting['type'] == 'json') {
$value = json_decode($value, true);
} elseif (isset($setting['type']) && $setting['type'] == 'array') {
$value = Set::normalize($value, false);
}
SlConfigure::write($setting['name'], $value, true, "{$setting['collection']}.{$locale}");
}
}
}
}
$settings = $this->_getSettings($activeSection);
$this->Session->setFlash(__t('Configuration saved'), array('class' => 'success'));
}
$this->data['_section'] = $activeSection;
$this->set('settings', $settings);
}
示例11: mergeVars
function mergeVars($admin, $configuration)
{
if (empty($configuration)) {
return array($this->defaults);
}
$modelObj = ClassRegistry::init(array('class' => $admin->modelName, 'table' => $admin->useTable, 'ds' => $admin->useDbConfig));
$schema = $modelObj->schema();
foreach ($configuration as $i => $config) {
foreach ($this->defaults as $key => $value) {
if (!isset($config[$key])) {
$configuration[$i][$key] = $value;
}
}
$fields = array();
if (empty($configuration[$i]['fields']) || in_array('*', (array) $configuration[$i]['fields'])) {
// $fields is all fields
foreach (array_keys($schema) as $field) {
$fields[$field] = array();
}
} else {
$configuration[$i]['fields'] = Set::normalize($configuration[$i]['fields']);
foreach ((array) $configuration[$i]['fields'] as $field => $config) {
if (empty($configuration[$i])) {
$config = array();
} else {
if (is_string($config)) {
$config = array('label' => $config);
}
}
if ($field !== '*') {
$fields[$field] = $config;
}
}
}
if (!empty($configuration[$i]['exclude'])) {
foreach ($configuration[$i]['exclude'] as $field) {
if (in_array($field, array_keys($fields))) {
$fields = array_diff_key($fields, array($field => $field));
}
}
}
if (!empty($configuration[$i]['hidden'])) {
foreach ((array) $configuration[$i]['hidden'] as $field) {
if (in_array($field, array_keys($fields))) {
$fields[$field]['type'] = 'hidden';
}
}
}
$configuration[$i]['fields'] = $fields;
$configuration[$i]['classes'] = (string) $configuration[$i]['classes'];
$configuration[$i]['description'] = (string) $configuration[$i]['description'];
}
return $configuration;
}
示例12: afterSave
/**
* Save tag and tagged models
*
* @param object $model
*/
function afterSave(&$model)
{
if (!isset($model->data[$model->alias]['tags'])) {
return;
}
$tagged_conditions = array('model' => $model->alias, 'model_id' => $model->id);
$this->Tagged->deleteAll($tagged_conditions, false, true);
$tags = Set::normalize($model->data[$model->alias]['tags'], false);
$tags = array_unique($tags);
foreach ($tags as $tag) {
$this->Tag->saveTag($tag, $tagged_conditions);
}
}
示例13: _parseTrueToDefault
function _parseTrueToDefault($config)
{
$_this =& CaptchaConfig::getInstance();
$trueToDefault = Set::normalize($_this->trueToDefault);
foreach ($trueToDefault as $path => $options) {
if (Set::extract($path, $config) === true) {
if (empty($options)) {
$options = Set::extract($path, $_this->defaultConfig);
}
$config = Set::insert($config, $path, $options);
}
}
return $config;
}
示例14: setup
function setup(&$Model, $settings = array())
{
if (empty($settings['fieldsOpt'])) {
$settings['fieldsOpt'] = array();
}
if (!empty($settings['fields'])) {
$settings['fieldsOpt'] = set::merge($settings['fieldsOpt'], array_filter(Set::normalize($settings['fields'])));
$settings['fields'] = array_keys(Set::normalize($settings['fields']));
}
if (empty($this->settings[$Model->alias])) {
$this->settings[$Model->alias] = $this->defSettings;
}
$this->settings[$Model->alias] = set::merge($this->settings[$Model->alias], $settings);
}
示例15: loadComponent
function loadComponent($componentName, $config = null, $parent = null)
{
$component = null;
$pathing = $this->componentPathing($componentName);
$created = false;
if (!isset($this->controller->Component->_loaded[$pathing['name']])) {
if (!class_exists($pathing['className'])) {
if (is_null($pathing['plugin']) || !App::import('Component', $pathing['fullName'])) {
if (!App::import('Component', $pathing['name'])) {
$this->cakeError('missingComponentFile', array(array('className' => $this->controller->name, 'component' => $pathing['name'], 'file' => Inflector::underscore($pathing['name']) . '.php', 'base' => '', 'code' => 500)));
return false;
}
}
if (!class_exists($pathing['className'])) {
$this->cakeError('missingComponentClass', array(array('className' => $this->controller->name, 'component' => $pathing['name'], 'file' => Inflector::underscore($pathing['name']) . '.php', 'base' => '', 'code' => 500)));
return false;
}
}
$component =& new $pathing['className']();
$created = true;
$component->enabled = true;
$this->controller->Component->_loaded[$pathing['name']] = $component;
} else {
$component =& $this->controller->Component->_loaded[$pathing['name']];
}
if (!empty($config)) {
if (isset($this->controller->Component->__settings[$pathing['name']])) {
$this->controller->Component->__settings[$pathing['name']] = array_merge($this->controller->Component->__settings[$pathing['name']], $config);
} else {
$this->controller->Component->__settings[$pathing['name']] = $config;
}
}
if (!empty($parent)) {
$parent->{$pathing['name']} = $component;
}
if (!empty($component->components)) {
$normal = Set::normalize($component->components);
foreach ((array) $normal as $subcomponent => $config) {
$this->loadComponent($subcomponent, $config, $component);
}
}
if ($created && method_exists($component, 'initialize') && $component->enabled === true) {
$settings = array();
if (isset($this->controller->Component->__settings[$pathing['name']])) {
$settings = $this->controller->Component->__settings[$pathing['name']];
}
$component->initialize($this->controller, $settings);
}
return $component;
}