AbstractRole.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
17 
18 /**
19  * Default implementation of a role.
20  *
21  * @author ingo herwig <ingo@wemove.com>
22  */
23 abstract class AbstractRole extends Node implements Role {
24 
25  /**
26  * @see Role::setName()
27  */
28  public function setName($name) {
29  $this->setValue('name', $name);
30  }
31 
32  /**
33  * @see Role::getName()
34  */
35  public function getName() {
36  return $this->getValue('name');
37  }
38 
39  /**
40  * @see PersistentObject::validateValue()
41  */
42  public function validateValue($name, $value) {
43  parent::validateValue($name, $value);
44 
45  // validate the name property
46  // the name is expected to be stored in the 'name' value
47  if ($name == 'name') {
48  $message = ObjectFactory::getInstance('message');
49  if (strlen(trim($value)) == 0) {
50  throw new ValidationException($name, $value, $message->getText("The role requires a name"));
51  }
52  $principalFactory = ObjectFactory::getInstance('principalFactory');
53  $role = $principalFactory->getRole($value);
54  if ($role != null && $role->getOID() != $this->getOID()) {
55  throw new ValidationException($name, $value, $message->getText("The role '%0%' already exists", [$value]));
56  }
57  }
58  }
59 }
60 ?>
ValidationException signals an exception in validation.
getValue($name)
Definition: Node.php:97
Role is the interface for user roles.
Definition: Role.php:18
Node adds the concept of relations to PersistentObject.
Definition: Node.php:34
static getInstance($name, $dynamicConfiguration=[])
setValue($name, $value, $forceSet=false, $trackChange=true)
Definition: Node.php:125
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...
Default implementation of a role.