* @var array applications (each element is an instance of
* ApplicationConfiguration)
*/
public $applications = [];
/**
* @var array authentication methods for this workspace (each element is an
* instance of AuthenticationMethod)
*/
public $authenticationMethods = [];
/**
* @var array disclaimers (each element a string)
*/
public $disclaimers = [];
/**
* @var array collections (each key a string to the collection name, each
* value a string to the collection document type)
*/
public $collections = [];
/**
* Determines if internal Obsidian Workspaces authentication can be used to
* login on this workspace URL
*
* @return boolean True if a user not logged in Obsidian Workspaces going
* to a workspace URL should be offered to login through
* Obsidian ; otherwise, false.
*/
public $allowInternalAuthentication = true;
/**
* @var string The overall custom header to prepend to the header site
*/
public $header = '';
/**
* @var string The overall custom footer to append to the footer site
*/
public $footer = '';
/**
* Get applications controllers binds for this workspace
*/
public function getControllersBinds () {
$controllers = [];
foreach ($this->applications as $application) {
$controllers[$application->bind] = $application;
}
return $controllers;
}
/**
* Determines if the URL fragment matches a controller bound to it.
*
* @param ApplicationConfiguration $applicationConfiguration The
* application
* configuration
*
* @return boolean true if the URL fragment matches an application
* controller's bind
*/
public function hasControllerBind ($url, &$applicationConfiguration) {
foreach ($this->applications as $application) {
if ($application->bind == $url) {
$applicationConfiguration = $application;
return true;
}
}
return false;
}
/**
- * Loads a WorkspaceConfiguration instance from an object
+ * Loads a WorkspaceConfiguration instance from an array
*
- * @param object $data The object to deserialize
- * @param Context $context The site context
+ * @param array $data The array to deserialize
+ * @param mixed $context The application context
*
* @return WorkspaceConfiguration The deserialized instance
+ * @throws WorkspaceException
*/
- public static function loadFromObject ($data, $context) {
+ public static function loadFromArray (
+ array $data,
+ mixed $context
+ ) : self {
$instance = new WorkspaceConfiguration();
- //Applications array
- if (property_exists($data, 'applications')) {
- foreach ($data->applications as $applicationData) {
- if (!property_exists($applicationData, 'name')) {
- throw new Exception("Missing required property: application name");
- }
+ // Parse applications to load in the workspace
+ $applications = $data["applications"] ?? [];
+ foreach ($applications as $applicationData) {
+ if (!array_key_exists("name", $applicationData)) {
+ throw new WorkspaceException("Missing required property: application name");
+ }
- $controllerClass = $applicationData->name;
- if (!class_exists($controllerClass)) {
- trigger_error("Application controller doesn't exist: $controllerClass. If you've just added application code, update includes/autoload.php file to register your new classes.",
+ // Parse custom authentication methods for this workspace
+ if (array_key_exists("login", $data)) {
$instance->allowInternalAuthentication = false;
- foreach ($data->login as $authData) {
- if (!property_exists($authData, 'type')) {
- throw new Exception("Missing required property: login type");
- }
-
- if ($authData->type == 'internal') {
+ foreach ($data["login"] as $authData) {
+ if ($authData["type"] == "internal") {
$instance->allowInternalAuthentication = true;
continue;
}
- $class = $authData->type;
- if (!class_exists($class)) {
- throw new Exception("Authentication method doesn't exist: $class. If you've just added authentication code, update includes/autoload.php file to register your new classes.");
- if (property_exists($collection, 'documentType')) {
- $type = $collection->documentType;
- if (!class_exists($type)) {
- throw new Exception("CollectionDocument children class doesn't exist: $type. If you've just added authentication code, update includes/autoload.php file to register your new classes.");
- }
- } else {
- $type = null;
+ // Parse collections the workspace applications can access
+ $collections = $data->collections ?? [];
+ foreach ($collections as $collection) {
+ if (!property_exists($collection, 'name')) {
+ throw new WorkspaceException("A collection has been declared without name in the workspace configuration.");
+ if (property_exists($collection, 'documentType')) {
+ $type = $collection->documentType;
+ if (!class_exists($type)) {
+ throw new WorkspaceException("CollectionDocument children class doesn't exist: $type. If you've just added authentication code, update includes/autoload.php file to register your new classes.");
$this->loginError = '<p>An unknown error has been received:</p><pre>' . print_r($reply, true) . '</pre><p>Please notify technical support about this new error message, so we can handle it in the future.</p>';