-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathPrimitiveEnumeration.class.php
More file actions
86 lines (70 loc) · 2.2 KB
/
PrimitiveEnumeration.class.php
File metadata and controls
86 lines (70 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*****************************************************************************
* Copyright (C) 2006-2008 by Ivan Y. Khvostishkov, Konstantin V. Arkhipov *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 3 of the *
* License, or (at your option) any later version. *
* *
*****************************************************************************/
/**
* @ingroup Primitives
**/
class PrimitiveEnumeration extends IdentifiablePrimitive
{
public function getList()
{
if ($this->value)
return $this->value->getObjectList();
elseif ($this->default)
return $this->default->getObjectList();
else {
$object = new $this->className(
call_user_func(array($this->className, 'getAnyId'))
);
return $object->getObjectList();
}
Assert::isUnreachable();
}
/**
* @throws WrongArgumentException
* @return PrimitiveEnumeration
**/
public function of($class)
{
$className = $this->guessClassName($class);
Assert::classExists($className);
Assert::isInstance($className, 'Enumeration');
$this->className = $className;
return $this;
}
public function importValue(/* Identifiable */ $value)
{
if ($value)
Assert::isEqual(get_class($value), $this->className);
else
return parent::importValue(null);
return $this->import(array($this->getName() => $value->getId()));
}
public function import($scope)
{
if (!$this->className)
throw new WrongStateException(
"no class defined for PrimitiveEnumeration '{$this->name}'"
);
$result = parent::import($scope);
if ($result === true) {
try {
$this->value = new $this->className($this->value);
} catch (MissingElementException $e) {
$this->value = null;
$this->imported = false;
return false;
}
return true;
}
return $result;
}
}
?>