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: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265:
<?php
namespace Nethgui\Module;
abstract class AbstractModule implements \Nethgui\Module\ModuleInterface, \Nethgui\View\ViewableInterface, \Nethgui\Log\LogConsumerInterface, \Nethgui\Utility\PhpConsumerInterface, \Nethgui\Authorization\AuthorizationAttributesProviderInterface, \Nethgui\System\PlatformConsumerInterface, \Nethgui\Authorization\PolicyEnforcementPointInterface
{
private $identifier;
private $parent;
private $initialized = FALSE;
private $log;
private $php;
private $descriptor;
private $viewTemplate;
private $platform;
public function __construct($identifier = NULL)
{
$this->php = new \Nethgui\Utility\PhpWrapper(get_class($this));
$this->viewTemplate = NULL;
if (isset($identifier)) {
$this->identifier = $identifier;
} else {
$this->identifier = \Nethgui\array_end(explode('\\', get_class($this)));
}
}
public function setPlatform(\Nethgui\System\PlatformInterface $platform)
{
$this->platform = $platform;
if ($platform instanceof \Nethgui\Log\LogConsumerInterface) {
$this->setLog($platform->getLog());
}
return $this;
}
public function getPlatform()
{
return $this->platform;
}
public function hasPlatform()
{
return $this->getPlatform() instanceof \Nethgui\System\PlatformInterface;
}
public function initialize()
{
if ($this->initialized === FALSE) {
$this->initialized = TRUE;
} else {
throw new \LogicException(sprintf("%s: module re-initialization is forbidden in class `%s`.", __CLASS__, get_class($this)), 1322148737);
}
}
public function isInitialized()
{
return $this->initialized;
}
public function getIdentifier()
{
return $this->identifier;
}
public function setParent(\Nethgui\Module\ModuleInterface $parentModule)
{
$this->parent = $parentModule;
return $this;
}
public function getParent()
{
return $this->parent;
}
public function prepareView(\Nethgui\View\ViewInterface $view)
{
$template = $this->getViewTemplate();
if ( ! is_null($template)) {
$view->setTemplate($template);
}
}
protected function setViewTemplate($template)
{
$this->viewTemplate = $template;
return $this;
}
protected function getViewTemplate()
{
return $this->viewTemplate;
}
public function setLog(\Nethgui\Log\LogInterface $log)
{
$this->log = $log;
$this->php->setLog($log);
return $this;
}
public function getLog()
{
if ( ! isset($this->log)) {
return new \Nethgui\Log\Nullog;
}
return $this->log;
}
protected function initializeAttributes(\Nethgui\Module\ModuleAttributesInterface $attributes)
{
return $attributes;
}
public function getAttributesProvider()
{
if ( ! isset($this->descriptor)) {
$attributes = new \Nethgui\Module\SimpleModuleAttributesProvider();
$this->descriptor = $this->initializeAttributes($attributes->initializeFromModule($this));
}
return $this->descriptor;
}
public function setPhpWrapper(\Nethgui\Utility\PhpWrapper $object)
{
$this->php = $object;
return $this;
}
protected function getPhpWrapper()
{
return $this->php;
}
public function asAuthorizationString()
{
return get_class($this) . ':' . $this->getIdentifier();
}
public function getAuthorizationAttribute($attributeName)
{
if ($attributeName === 'identifier') {
return $this->getIdentifier();
} elseif ($attributeName === 'title') {
return $this->getAttributesProvider()->getTitle();
} elseif ($attributeName === 'category') {
return $this->getAttributesProvider()->getCategory();
}
return NULL;
}
private $pdp;
protected function getPolicyDecisionPoint()
{
if ( ! isset($this->pdp)) {
$this->pdp = new \Nethgui\Test\Tool\StaticPolicyDecisionPoint(TRUE);
}
return $this->pdp;
}
public function setPolicyDecisionPoint(\Nethgui\Authorization\PolicyDecisionPointInterface $pdp)
{
$this->pdp = $pdp;
return $this;
}
}