View source
<?php
declare (strict_types=1);
namespace Drupal\og;
abstract class Permission implements PermissionInterface {
protected $name;
protected $title;
protected $description = '';
protected $defaultRoles = [];
protected $restrictAccess = FALSE;
public function __construct(array $values = []) {
foreach ($values as $property => $value) {
$this
->set($property, $value);
}
}
public function get($property) {
$property = $this
->lowerCamelize($property);
if (!property_exists($this, $property)) {
throw new \InvalidArgumentException("Invalid property {$property}.");
}
return $this->{$property};
}
public function set($property, $value) {
$property = $this
->lowerCamelize($property);
$this
->validate($property, $value);
$this->{$property} = $value;
}
public function getName() {
return $this
->get('name');
}
public function setName($name) {
$this
->set('name', $name);
return $this;
}
public function getTitle() {
return $this
->get('title');
}
public function setTitle($title) {
$this
->set('title', $title);
return $this;
}
public function getDescription() {
return $this
->get('description');
}
public function setDescription($description) {
$this
->set('description', $description);
return $this;
}
public function getDefaultRoles() {
return $this
->get('default roles');
}
public function setDefaultRoles(array $default_roles) {
$this
->set('default roles', $default_roles);
return $this;
}
public function getRestrictAccess() {
return $this
->get('restrict access');
}
public function setRestrictAccess($access) {
$this
->set('restrict access', $access);
return $this;
}
protected function validate($property, $value) {
if (!property_exists($this, $property)) {
throw new \InvalidArgumentException("Invalid property {$property}.");
}
if ($property === 'restrictAccess' && !is_bool($value)) {
throw new \InvalidArgumentException('The value for the "restrict access" property should be a boolean.');
}
}
protected static function lowerCamelize($string) {
return lcfirst(str_replace(' ', '', ucwords($string)));
}
}