Upgrade to 3.2.0

This commit is contained in:
Bastian Allgeier
2019-06-25 09:56:08 +02:00
parent 9e18cf635d
commit 9c89153d35
296 changed files with 14408 additions and 2504 deletions

View File

@@ -4,13 +4,18 @@ namespace Kirby\Cms;
use Exception;
use Kirby\Data\Data;
use Kirby\Exception\NotFoundException;
use Kirby\Toolkit\F;
use Kirby\Toolkit\I18n;
/**
* Represents a User role with attached
* permissions. Roles are defined by user blueprints.
*
* @package Kirby Cms
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://getkirby.com/license
*/
class Role extends Model
{
@@ -25,7 +30,7 @@ class Role extends Model
}
/**
* Improved var_dump() output
* Improved `var_dump` output
*
* @return array
*/
@@ -48,19 +53,19 @@ class Role extends Model
}
}
protected static function defaults()
protected static function defaults(): array
{
return [
'admin' => [
'description' => 'The admin has all rights',
'name' => 'admin',
'title' => 'Admin',
'description' => I18n::translate('role.admin.description'),
'title' => I18n::translate('role.admin.title'),
'permissions' => true,
],
'nobody' => [
'description' => 'This is a fallback role without any permissions',
'name' => 'nobody',
'title' => 'Nobody',
'description' => I18n::translate('role.nobody.description'),
'title' => I18n::translate('role.nobody.title'),
'permissions' => false,
]
];
@@ -71,7 +76,12 @@ class Role extends Model
return $this->description;
}
public static function factory(array $props, array $inject = []): self
/**
* @param array $props
* @param array $inject
* @return self
*/
public static function factory(array $props, array $inject = [])
{
return new static($props + $inject);
}
@@ -91,7 +101,12 @@ class Role extends Model
return $this->name() === 'nobody';
}
public static function load(string $file, array $inject = []): self
/**
* @param string $file
* @param array $inject
* @return self
*/
public static function load(string $file, array $inject = [])
{
$data = Data::read($file);
$data['name'] = F::name($file);
@@ -104,6 +119,10 @@ class Role extends Model
return $this->name;
}
/**
* @param array $inject
* @return self
*/
public static function nobody(array $inject = [])
{
try {
@@ -113,30 +132,49 @@ class Role extends Model
}
}
public function permissions(): Permissions
/**
* @return Kirby\Cms\Permissions
*/
public function permissions()
{
return $this->permissions;
}
protected function setDescription($description = null): self
/**
* @param [type] $description
* @return self
*/
protected function setDescription($description = null)
{
$this->description = I18n::translate($description, $description);
return $this;
}
protected function setName(string $name): self
/**
* @param string $name
* @return self
*/
protected function setName(string $name)
{
$this->name = $name;
return $this;
}
protected function setPermissions($permissions = null): self
/**
* @param [type] $permissions
* @return self
*/
protected function setPermissions($permissions = null)
{
$this->permissions = new Permissions($permissions);
return $this;
}
protected function setTitle($title = null): self
/**
* @param [type] $title
* @return self
*/
protected function setTitle($title = null)
{
$this->title = I18n::translate($title, $title);
return $this;