* @var array applications (each element is an instance of
@@ -109,102 +114,111 @@
}
/**
- * 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.");