本文整理汇总了PHP中Grav\Common\Utils::getDotNotation方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::getDotNotation方法的具体用法?PHP Utils::getDotNotation怎么用?PHP Utils::getDotNotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grav\Common\Utils
的用法示例。
在下文中一共展示了Utils::getDotNotation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Save a group
*/
public function save()
{
$grav = Grav::instance();
$config = $grav['config'];
$blueprints = new Blueprints();
$blueprint = $blueprints->get('user/group');
$fields = $blueprint->fields();
$config->set("groups.{$this->groupname}", []);
foreach ($fields as $field) {
if ($field['type'] == 'text') {
$value = $field['name'];
if (isset($this->items['data'][$value])) {
$config->set("groups.{$this->groupname}.{$value}", $this->items['data'][$value]);
}
}
if ($field['type'] == 'array') {
$value = $field['name'];
$arrayValues = Utils::getDotNotation($this->items['data'], $field['name']);
if ($arrayValues) {
foreach ($arrayValues as $arrayIndex => $arrayValue) {
$config->set("groups.{$this->groupname}.{$value}.{$arrayIndex}", $arrayValue);
}
}
}
}
$type = 'groups';
$blueprints = $this->blueprints("config/{$type}");
$obj = new Data($config->get($type), $blueprints);
$file = CompiledYamlFile::instance($grav['locator']->findResource("config://{$type}.yaml"));
$obj->file($file);
$obj->save();
}
示例2: normalizeFiles
/**
* Internal method to normalize the $_FILES array
*
* @param array $data $_FILES starting point data
* @param string $key
* @return object a new Object with a normalized list of files
*/
protected function normalizeFiles($data, $key = '')
{
$files = new \stdClass();
$files->field = $key;
$files->file = new \stdClass();
foreach ($data as $fieldName => $fieldValue) {
// Since Files Upload are always happening via Ajax
// we are not interested in handling `multiple="true"`
// because they are always handled one at a time.
// For this reason we normalize the value to string,
// in case it is arriving as an array.
$value = (array) Utils::getDotNotation($fieldValue, $key);
$files->file->{$fieldName} = array_shift($value);
}
return $files;
}
示例3: testGetDotNotation
public function testGetDotNotation()
{
$array = ['test' => ['test2' => 'test2Value', 'test3' => ['test4' => 'test4Value']]];
$this->assertEquals('test2Value', Utils::getDotNotation($array, 'test.test2'));
$this->assertEquals('test4Value', Utils::getDotNotation($array, 'test.test3.test4'));
$this->assertEquals('defaultValue', Utils::getDotNotation($array, 'test.non_existent', 'defaultValue'));
}
示例4: taskRemoveFileFromBlueprint
/**
* Handle deleting a file from a blueprint
*
* @return bool True if the action was performed.
*/
protected function taskRemoveFileFromBlueprint()
{
$uri = $this->grav['uri'];
$blueprint = base64_decode($uri->param('blueprint'));
$path = base64_decode($uri->param('path'));
$proute = base64_decode($uri->param('proute'));
$type = $uri->param('type');
$field = $uri->param('field');
$event = $this->grav->fireEvent('onAdminCanSave', new Event(['controller' => &$this]));
if (!$event['can_save']) {
return false;
}
$this->taskRemoveMedia();
if ($type == 'pages') {
$page = $this->admin->page(true, $proute);
$keys = explode('.', preg_replace('/^header./', '', $field));
$header = (array) $page->header();
$data_path = implode('.', $keys);
$data = Utils::getDotNotation($header, $data_path);
if (isset($data[$path])) {
unset($data[$path]);
Utils::setDotNotation($header, $data_path, $data);
$page->header($header);
}
$page->save();
} else {
$blueprint_prefix = $type == 'config' ? '' : $type . '.';
$blueprint_name = str_replace('/blueprints', '', str_replace('config/', '', $blueprint));
$blueprint_field = $blueprint_prefix . $blueprint_name . '.' . $field;
$files = $this->grav['config']->get($blueprint_field);
if ($files) {
foreach ($files as $key => $value) {
if ($key == $path) {
unset($files[$key]);
}
}
}
$this->grav['config']->set($blueprint_field, $files);
switch ($type) {
case 'config':
$data = $this->grav['config']->get($blueprint_name);
$config = $this->admin->data($blueprint, $data);
$config->save();
break;
case 'themes':
Theme::saveConfig($blueprint_name);
break;
case 'plugins':
Plugin::saveConfig($blueprint_name);
break;
}
}
$this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL')];
return true;
}
示例5: authorize
/**
* Checks user authorization to the action.
*
* @param string $action
*
* @return bool
*/
public function authorize($action)
{
if (empty($this->items)) {
return false;
}
if (isset($this->state) && $this->state !== 'enabled') {
return false;
}
$return = false;
//Check group access level
$groups = $this->get('groups');
if ($groups) {
foreach ((array) $groups as $group) {
$permission = Grav::instance()['config']->get("groups.{$group}.access.{$action}");
$return = Utils::isPositive($permission);
if ($return === true) {
break;
}
}
}
//Check user access level
if ($this->get('access')) {
if (Utils::getDotNotation($this->get('access'), $action) !== null) {
$permission = $this->get("access.{$action}");
$return = Utils::isPositive($permission);
}
}
return $return;
}