AbstractRole.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 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 
18 
19 /**
20  * Default implementation of a role.
21  *
22  * @author ingo herwig <ingo@wemove.com>
23  */
24 abstract class AbstractRole extends Node implements Role {
25 
26  /**
27  * @see Role::setName()
28  */
29  public function setName($name) {
30  $this->setValue('name', $name);
31  }
32 
33  /**
34  * @see Role::getName()
35  */
36  public function getName() {
37  return $this->getValue('name');
38  }
39 
40  /**
41  * @see PersistentObject::validateValue()
42  */
43  public function validateValue($name, $value, Message $message) {
44  parent::validateValue($name, $value, $message);
45 
46  // validate the name property
47  // the name is expected to be stored in the 'name' value
48  if ($name == 'name') {
49  if (strlen(trim($value)) == 0) {
50  throw new ValidationException($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($message->getText("The role '%0%' already exists", array($value)));
56  }
57  }
58  }
59 }
60 ?>
Default implementation of a role.
getValue($name)
Definition: Node.php:91
validateValue($name, $value, Message $message)
setValue($name, $value, $forceSet=false, $trackChange=true)
Definition: Node.php:119
Role is the interface for user roles.
Definition: Role.php:18
static getInstance($name, $dynamicConfiguration=array())
Message is used to get localized messages to be used in the user interface.
Definition: Message.php:23
ValidationException signals an exception in validation.
getText($message, $parameters=null, $lang='')
Get a localized string.
Node adds the concept of relations to PersistentObject.
Definition: Node.php:34