Page MenuHomeDevCentral

No OneTemporary

diff --git a/composer.json b/composer.json
index 8af8c23..3f2b33e 100644
--- a/composer.json
+++ b/composer.json
@@ -1,47 +1,48 @@
{
"name": "waystone/waystone",
"type": "library",
"description": "Modular libraries to build applications with Obsidian Workspaces",
"keywords": [
"framework",
"keruald",
"waystone",
"obsidian"
],
"license": "BSD-2-Clause",
"homepage": "https://waystone.nasqueron.org",
"authors": [
{
"name": "Sébastien Santoro",
"email": "dereckson@espace-win.org"
}
],
"require": {
"keruald/database": "0.5.2",
- "keruald/omnitools": "0.15.1",
+ "keruald/omnitools": "0.16.0",
+ "keruald/yaml": "0.1.1",
"netresearch/jsonmapper": "^v5.0.0",
"smarty/smarty": "^5.6.0",
"vlucas/phpdotenv": "^v5.6.2",
"ext-mysqli": "*"
},
"require-dev": {
"nasqueron/codestyle": "^0.1.2",
"phpunit/phpunit": "^12.4",
"squizlabs/php_codesniffer": "^4.0"
},
"replace": {
"waystone/workspaces": "1.0.0"
},
"autoload": {
"psr-4": {
"Waystone\\Workspaces\\": "workspaces/src/",
"Waystone\\Workspaces\\Tests\\": "workspaces/tests/"
}
},
"scripts": {
"lint-src": "find */src -type f -name '*.php' | xargs -I {} php -l {} 1> /dev/null",
"lint-tests": "find */tests -type f -name '*.php' | xargs -n1 php -l",
"test": "vendor/bin/phpunit"
},
"minimum-stability": "dev"
}
diff --git a/workspaces/composer.json b/workspaces/composer.json
index 87daed3..bdb648c 100644
--- a/workspaces/composer.json
+++ b/workspaces/composer.json
@@ -1,31 +1,32 @@
{
"name": "waystone/workspaces",
"description": "Core interfaces for Obsidian Workspaces",
"type": "project",
"require": {
"keruald/database": "0.5.2",
- "keruald/omnitools": "0.15.1",
+ "keruald/omnitools": "0.16.0",
+ "keruald/yaml": "0.1.1",
"smarty/smarty": "^5.6.0"
},
"require-dev": {
"phpunit/phpunit": "^12.4",
"nasqueron/codestyle": "^0.1.2",
"netresearch/jsonmapper": "^v5.0.0",
"squizlabs/php_codesniffer": "^4.0",
"vlucas/phpdotenv": "^v5.6.2",
"ext-mysqli": "*"
},
"license": "BSD-2-Clause",
"autoload": {
"psr-4": {
"Waystone\\Workspaces\\": "src/",
"Waystone\\Workspaces\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "Sébastien Santoro",
"email": "dereckson@espace-win.org"
}
]
}
diff --git a/workspaces/src/Engines/Apps/Application.php b/workspaces/src/Engines/Apps/Application.php
index 70e30f8..d87208a 100644
--- a/workspaces/src/Engines/Apps/Application.php
+++ b/workspaces/src/Engines/Apps/Application.php
@@ -1,83 +1,84 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Application class
*
* @package ObsidianWorkspaces
* @subpackage Apps
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*/
namespace Waystone\Workspaces\Engines\Apps;
use Waystone\Workspaces\Engines\Controller\Controller;
+use Waystone\Workspaces\Engines\Errors\ErrorHandling;
use Waystone\Workspaces\Engines\Workspaces\WorkspaceConfiguration;
use Collection;
use Exception;
/**
* Application class
*
* This class describes an application
*/
abstract class Application extends Controller {
/**
* @var string The application name
*/
public static $name;
/**
* @var ApplicationContext The current application context
*/
public $context;
/**
* @var Collection[] The collections, keys as collections roles and values as
* collections names.
*/
public $collections = [];
/**
* Initializes the controller resources
*/
public function initialize () {
$this->collections = $this->loadCollections();
}
/**
* Loads the collection
*/
private function loadCollections () : array {
$loadedCollections = [];
$workspaceCollections =
$this->context->workspace->configuration->collections;
foreach (
$this->context->configuration->useCollections as $role => $name
) {
if (!array_key_exists($name, $workspaceCollections)) {
$name =
WorkspaceConfiguration::getCollectionNameWithPrefix($this->context->workspace,
$name);
if (!array_key_exists($name, $workspaceCollections)) {
throw new Exception("Collection not found: $name");
}
}
$loadedCollections[$role] =
Collection::load($name, $workspaceCollections[$name]);
}
return $loadedCollections;
}
}
diff --git a/workspaces/src/Engines/Apps/ApplicationConfiguration.php b/workspaces/src/Engines/Apps/ApplicationConfiguration.php
index 7164324..b1263cb 100644
--- a/workspaces/src/Engines/Apps/ApplicationConfiguration.php
+++ b/workspaces/src/Engines/Apps/ApplicationConfiguration.php
@@ -1,85 +1,73 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Application configuration class
*
* @package ObsidianWorkspaces
* @subpackage Apps
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*/
namespace Waystone\Workspaces\Engines\Apps;
-use Waystone\Workspaces\Engines\Workspaces\WorkspaceConfiguration;
+use Waystone\Workspaces\Engines\Serialization\ArrayDeserializable;
use Message;
-use ObjectDeserializable;
/**
* Application configuration class
*
* This class describes an application configuration.
*
* It can be serialized into a workspace.conf application entry
*/
-class ApplicationConfiguration implements ObjectDeserializable {
+class ApplicationConfiguration implements ArrayDeserializable {
/**
* @var string The URL the application is binded to, without initial slash.
*/
public $bind;
/**
* @var Message The navigation entry
*/
public $nav;
/**
* @var string The application icon name
*/
public $icon;
/**
* @var string[] The collections to use. Keys ares collections roles, values
* collections names.
*/
public $useCollections = [];
/**
- * Loads a WorkspaceConfiguration instance from an object
+ * Loads an ApplicationConfiguration instance from an associative array
*
- * @param object $data The object to deserialize
+ * @param array $data The associative array to deserialize
*
- * @return WorkspaceConfiguration The deserialized instance
+ * @return ApplicationConfiguration The deserialized instance
*/
- public static function loadFromObject ($data) {
- $instance = new ApplicationConfiguration();
+ public static function loadFromArray (array $data) : self {
+ $instance = new static;
- //Applications array
foreach ($data as $key => $value) {
- switch ($key) {
- case 'nav':
- $instance->nav = new Message($value);
- break;
-
- case 'useCollections':
- foreach ($data->useCollections as $role => $name) {
- $instance->useCollections[$role] = $name;
- }
- break;
-
- default:
- $instance->$key = $value;
- }
+ $instance->$key = match ($key) {
+ "nav" => new Message($value),
+ default => $value,
+ };
}
return $instance;
}
}
diff --git a/workspaces/src/Engines/Exceptions/WorkspaceException.php b/workspaces/src/Engines/Exceptions/WorkspaceException.php
new file mode 100644
index 0000000..b406971
--- /dev/null
+++ b/workspaces/src/Engines/Exceptions/WorkspaceException.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Waystone\Workspaces\Engines\Exceptions;
+
+use RuntimeException;
+
+class WorkspaceException extends RuntimeException {
+
+}
diff --git a/workspaces/src/Engines/Serialization/ArrayDeserializable.php b/workspaces/src/Engines/Serialization/ArrayDeserializable.php
new file mode 100644
index 0000000..ddae0d0
--- /dev/null
+++ b/workspaces/src/Engines/Serialization/ArrayDeserializable.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Waystone\Workspaces\Engines\Serialization;
+
+interface ArrayDeserializable {
+
+ /**
+ * Loads a specified class instance from an associative array.
+ *
+ * @param array $data The object to deserialize
+ * @return self The deserialized instance
+ */
+ public static function loadFromArray (array $data) : self;
+
+}
diff --git a/workspaces/src/Engines/Serialization/ArrayDeserializableWithContext.php b/workspaces/src/Engines/Serialization/ArrayDeserializableWithContext.php
new file mode 100644
index 0000000..5ae0078
--- /dev/null
+++ b/workspaces/src/Engines/Serialization/ArrayDeserializableWithContext.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Waystone\Workspaces\Engines\Serialization;
+
+interface ArrayDeserializableWithContext {
+
+ /**
+ * Loads a specified class instance from an associative array.
+ *
+ * @param array $data The object to deserialize
+ * @param mixed $context The site or application context
+ * @return self The deserialized instance
+ */
+ public static function loadFromArray (array $data, mixed $context) : self;
+
+}
diff --git a/workspaces/src/Engines/Workspaces/Workspace.php b/workspaces/src/Engines/Workspaces/Workspace.php
index 57b3cbf..b59a201 100644
--- a/workspaces/src/Engines/Workspaces/Workspace.php
+++ b/workspaces/src/Engines/Workspaces/Workspace.php
@@ -1,269 +1,280 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Workspace class
*
* @package ObsidianWorkspaces
* @subpackage Workspaces
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*/
namespace Waystone\Workspaces\Engines\Workspaces;
use Waystone\Workspaces\Engines\Errors\ErrorHandling;
use Waystone\Workspaces\Engines\Framework\Context;
use Cache;
use Language;
use User;
use Exception;
use LogicException;
/**
* Workspace class
*
* This class maps the workspaces table.
*/
class Workspace {
public $id;
public $code;
public $name;
public $created;
public $description;
/**
* @var WorkspaceConfiguration The workspace configuration
*/
public $configuration;
/**
* Initializes a new instance
*
* @param int $id the primary key
*/
function __construct ($id = null) {
if ($id) {
$this->id = $id;
$this->load_from_database();
}
}
/**
* Loads the object Workspace (ie fill the properties) from the $_POST array
*/
function load_from_form () {
if (array_key_exists('code', $_POST)) {
$this->code = $_POST['code'];
}
if (array_key_exists('name', $_POST)) {
$this->name = $_POST['name'];
}
if (array_key_exists('created', $_POST)) {
$this->created = $_POST['created'];
}
if (array_key_exists('description', $_POST)) {
$this->description = $_POST['description'];
}
}
/**
* Loads the object zone (ie fill the properties) from the $row array
*/
function load_from_row ($row) {
$this->id = $row['workspace_id'];
$this->code = $row['workspace_code'];
$this->name = $row['workspace_name'];
$this->created = $row['workspace_created'];
$this->description = $row['workspace_description'];
}
/**
* Loads the specified workspace from code
*
* @param string $code The workspace code
*
* @return Workspace The specified workspace instance
*/
public static function fromCode ($code) {
global $db;
$code = $db->escape($code);
$sql = "SELECT * FROM " . TABLE_WORKSPACES . " WHERE workspace_code = '"
. $code . "'";
if (!$result = $db->query($sql)) {
ErrorHandling::messageAndDie(SQL_ERROR,
"Unable to query workspaces", '', __LINE__, __FILE__, $sql);
}
if (!$row = $db->fetchRow($result)) {
throw new Exception("Workspace unknown: " . $code);
}
$workspace = new Workspace();
$workspace->load_from_row($row);
return $workspace;
}
/**
* Loads the object Workspace (ie fill the properties) from the database
*/
function load_from_database () {
global $db;
$id = $db->escape($this->id);
$sql = "SELECT * FROM " . TABLE_WORKSPACES . " WHERE workspace_id = '"
. $id . "'";
if (!$result = $db->query($sql)) {
ErrorHandling::messageAndDie(SQL_ERROR,
"Unable to query workspaces", '', __LINE__, __FILE__, $sql);
}
if (!$row = $db->fetchRow($result)) {
$this->lastError = "Workspace unknown: " . $this->id;
return false;
}
$this->load_from_row($row);
return true;
}
/**
* Saves to database
*/
function save_to_database () {
global $db;
$id = $this->id ? "'" . $db->escape($this->id) . "'" : 'NULL';
$code = $db->escape($this->code);
$name = $db->escape($this->name);
$created = $db->escape($this->created);
$description = $db->escape($this->description);
//Updates or inserts
$sql = "REPLACE INTO " . TABLE_WORKSPACES
. " (`workspace_id`, `workspace_code`, `workspace_name`, `workspace_created`, `workspace_description`) VALUES ('$id', '$code', '$name', '$created', '$description')";
if (!$db->query($sql)) {
ErrorHandling::messageAndDie(SQL_ERROR, "Unable to save", '',
__LINE__, __FILE__, $sql);
}
if (!$this->id) {
//Gets new record id value
$this->id = $db->nextId();
}
}
/**
* Determines if the specified user has access to the current workspace
*
* @param User $user The user to check
*
* @return boolean true if the user has access to the current workspace ;
* otherwise, false.
*/
public function userCanAccess (User $user) {
if ($this->id === false || $this->id === null || $this->id === '') {
throw new LogicException("The workspace must has a valid id before to call userCanAccess.");
}
foreach ($user->get_workspaces() as $workspace) {
if ($workspace->id == $this->id) {
return true;
}
}
return false;
}
/**
* Loads configuration
*
* @param Context $context The site context
*/
public function loadConfiguration (Context $context) {
global $Config;
- $file = $Config['Content']['Workspaces'] . '/' . $this->code
- . '/workspace.conf';
- if (!file_exists($file)) {
- $exceptionMessage =
- sprintf(Language::get('NotConfiguredWorkspace'), $file);
- throw new Exception($exceptionMessage);
+ $dir = $Config['Content']['Workspaces'] . '/' . $this->code;
+
+ // Load JSON configuration file
+ $file = $dir . '/workspace.conf';
+ if (file_exists($file)) {
+ $this->configuration =
+ WorkspaceConfiguration::loadFromFile($file, $context);
+ return;
}
- $this->configuration =
- WorkspaceConfiguration::loadFromFile($file, $context);
+ // Load YAML configuration file
+ $file = $dir . '/workspace.yml';
+ if (file_exists($file)) {
+ $this->configuration =
+ WorkspaceConfiguration::loadFromYamlFile($file, $context);
+ return;
+ }
+
+ $exceptionMessage =
+ sprintf(Language::get('NotConfiguredWorkspace'), $file);
+ throw new Exception($exceptionMessage);
}
/**
* Gets workspaces specified user has access to.
*
* @param int $user_id The user to get his workspaces
*
* @return Workspace[] A list of workspaces
*/
public static function get_user_workspaces ($user_id) {
global $db;
//Gets the workspaces list from cache, as this complex request could take 100ms
//and is called on every page.
$cache = Cache::load();
if (!$workspaces = unserialize($cache->get("workspaces-$user_id"))) {
$clause = User::get_permissions_clause_from_user_id($user_id);
$sql = "SELECT DISTINCT w.*
FROM " . TABLE_PERMISSIONS . " p, " . TABLE_WORKSPACES . " w
WHERE p.target_resource_type = 'W' AND
p.target_resource_id = w.workspace_id AND
p.permission_name = 'accessLevel' AND
p.permission_flag > 0 AND
($clause)";
if (!$result = $db->query($sql)) {
ErrorHandling::messageAndDie(SQL_ERROR,
"Can't get user workspaces", '', __LINE__, __FILE__, $sql);
}
$workspaces = [];
while ($row = $db->fetchRow($result)) {
$workspace = new Workspace();
$workspace->id = $row['workspace_id'];
$workspace->load_from_row($row);
$workspaces[] = $workspace;
}
$cache->set("workspaces-$user_id", serialize($workspaces));
}
return $workspaces;
}
/**
* Determines if a string matches an existing workspace code.
*
* @param string $code The workspace code to check
*
* @return boolean If the specified code matches an existing workspace,
* true; otherwise, false.
*/
public static function is_workspace ($code) {
global $db;
$code = $db->escape($code);
$sql = "SELECT count(*) FROM " . TABLE_WORKSPACES
. " WHERE workspace_code = '$code'";
if (!$result = $db->query($sql)) {
ErrorHandling::messageAndDie(SQL_ERROR,
"Can't check workspace code", '', __LINE__, __FILE__, $sql);
}
$row = $db->fetchRow($result);
return ($row[0] == 1);
}
}
diff --git a/workspaces/src/Engines/Workspaces/WorkspaceConfiguration.php b/workspaces/src/Engines/Workspaces/WorkspaceConfiguration.php
index 9415f3e..3f660e7 100644
--- a/workspaces/src/Engines/Workspaces/WorkspaceConfiguration.php
+++ b/workspaces/src/Engines/Workspaces/WorkspaceConfiguration.php
@@ -1,237 +1,272 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Workspace configuration class
*
* @package ObsidianWorkspaces
* @subpackage Workspaces
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*/
namespace Waystone\Workspaces\Engines\Workspaces;
use Waystone\Workspaces\Engines\Apps\ApplicationConfiguration;
+use Waystone\Workspaces\Engines\Exceptions\WorkspaceException;
use Waystone\Workspaces\Engines\Framework\Context;
+use Waystone\Workspaces\Engines\Serialization\ArrayDeserializableWithContext;
-use ObjectDeserializableWithContext;
+use Keruald\Yaml\Parser as YamlParser;
+use Keruald\Yaml\Tags\EnvTag;
+
+use AuthenticationMethod;
use Exception;
/**
* Workspace configuration class
*
* This class maps the workspaces table.
*/
-class WorkspaceConfiguration implements ObjectDeserializableWithContext {
+class WorkspaceConfiguration implements ArrayDeserializableWithContext {
/**
* @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.",
- E_USER_WARNING);
- continue;
- }
- $configurationClass = $controllerClass . 'Configuration';
- if (!class_exists($configurationClass)) {
- $configurationClass = "ApplicationConfiguration";
- }
- $instance->applications[] =
- $configurationClass::loadFromObject($applicationData);
+ $controllerClass = $applicationData["name"];
+ if (!class_exists($controllerClass)) {
+ trigger_error("Application controller doesn't exist: $controllerClass.",
+ E_USER_WARNING);
+ continue;
+ }
+
+ $configurationClass = $controllerClass . "Configuration";
+ if (!class_exists($configurationClass)) {
+ $configurationClass = ApplicationConfiguration::class;
}
+
+ $instance->applications[] = [$configurationClass, "loadFromArray"]($applicationData);
}
- //Login array
- if (property_exists($data, 'login')) {
+ // 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.");
- }
- $authenticationMethod = $class::loadFromObject($authData);
- $authenticationMethod->context = $context;
- $instance->authenticationMethods[] = $authenticationMethod;
+ $auth = self::loadAuthenticationMethod($authData, $context);
+ $instance->authenticationMethods[] = $auth;
}
}
- //Disclaimers array
- if (property_exists($data, 'disclaimers')) {
- $instance->disclaimers = $data->disclaimers;
- }
-
- //Collections array
- if (property_exists($data, 'collections')) {
- foreach ($data->collections as $collection) {
- if (!property_exists($collection, 'name')) {
- throw new Exception("A collection has been declared without name in the workspace configuration.");
- }
- $name = $collection->name;
- if (!property_exists($collection, 'global')
- || !$collection->global) {
- $name =
- WorkspaceConfiguration::getCollectionNameWithPrefix($context->workspace,
- $name);
- }
- 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.");
+ }
+ $name = $collection->name;
+ if (!property_exists($collection, 'global')
+ || !$collection->global) {
+ $name =
+ WorkspaceConfiguration::getCollectionNameWithPrefix($context->workspace,
+ $name);
+ }
+ 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.");
}
- $instance->collections[$name] = $type;
+ } else {
+ $type = null;
}
+ $instance->collections[$name] = $type;
}
- //Header string
- if (property_exists($data, 'header')) {
- $instance->header = $data->header;
+ // Customization
+ $instance->disclaimers = $data->disclaimers ?? [];
+ $instance->header = $data["header"] ?? "";
+ $instance->footer = $data["footer"] ?? "";
+
+ return $instance;
+ }
+
+ private static function loadAuthenticationMethod (
+ array $authData,
+ Context $context,
+ ) : AuthenticationMethod {
+ if (!array_key_exists("type", $authData)) {
+ throw new WorkspaceException("Missing required property: login type");
}
- //Footer string
- if (property_exists($data, 'footer')) {
- $instance->footer = $data->footer;
+ $class = $authData["type"];
+ if (!class_exists($class)) {
+ throw new WorkspaceException("Authentication method doesn't exist: $class.");
}
- return $instance;
+ try {
+ $authenticationMethod = $class::loadFromArray($authData);
+ $authenticationMethod->context = $context;
+ } catch (Exception $ex) {
+ throw new WorkspaceException(
+ "Can't load authentication method: " . $ex->getMessage(), 0, $ex
+ );
+ }
+
+ return $authenticationMethod;
}
/**
* Gets the full name of a collection, with the workspace prefix
*
* @param Workspace $workspace The current workspace
* @param string $name The collection name
*
* @return string The full name of the collection
*/
public static function getCollectionNameWithPrefix (
Workspace $workspace,
string $name
) {
return $workspace->code . '-' . $name;
}
/**
* Loads a WorkspaceConfiguration instance deserializing a JSON file
*/
public static function loadFromFile ($file, $context) {
- $object = json_decode(file_get_contents($file));
+ $object = json_decode(file_get_contents($file), true);
if ($object === null) {
throw new Exception("Can't parse configuration file: "
. json_last_error_msg());
}
- return self::loadFromObject($object, $context);
+ return self::loadFromArray($object, $context);
+ }
+
+ /**
+ * @throws WorkspaceException
+ */
+ public static function loadFromYamlFile (
+ string $file,
+ Context $context
+ ) : self {
+ $parser = new YamlParser();
+ $parser->withTagClass(EnvTag::class);
+
+ try {
+ $value = $parser->parseFile($file);
+ }
+ catch (Exception $ex) {
+ throw new WorkspaceException("Can't parse configuration file: "
+ . $ex->getMessage(), 0, $ex);
+ }
+
+ return self::loadFromArray($value, $context);
}
}
diff --git a/workspaces/src/includes/ObjectDeserializable.php b/workspaces/src/includes/ObjectDeserializable.php
index 78ad275..39e55c1 100644
--- a/workspaces/src/includes/ObjectDeserializable.php
+++ b/workspaces/src/includes/ObjectDeserializable.php
@@ -1,45 +1,30 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* ObjectDeserializable and ObjectDeserializableWithContext interfaces
*
* @package ObsidianWorkspaces
* @subpackage Keruald
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
/**
* ObjectDeserializable interface
*/
interface ObjectDeserializable {
/**
* Loads a specified class instance from a generic object. Typically used to deserialize a JSON document.
*
* @param object $data The object to deserialize
* @return object The deserialized instance
*/
public static function loadFromObject ($data);
}
-
-
-/**
- * ObjectDeserializableWithContext interface
- */
-interface ObjectDeserializableWithContext {
- /**
- * Loads a specified class instance from a generic object. Typically used to deserialize a JSON document.
- *
- * @param object $data The object to deserialize
- * @param object $context The site or application context
- * @return object The deserialized instance
- */
- public static function loadFromObject ($data, $context);
-}
\ No newline at end of file
diff --git a/workspaces/src/includes/auth/AddToGroupUserAction.php b/workspaces/src/includes/auth/AddToGroupUserAction.php
index d025872..b91cf9e 100644
--- a/workspaces/src/includes/auth/AddToGroupUserAction.php
+++ b/workspaces/src/includes/auth/AddToGroupUserAction.php
@@ -1,60 +1,67 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Add to group user action class
*
* @package ObsidianWorkspaces
* @subpackage Auth
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
+use Waystone\Workspaces\Engines\Serialization\ArrayDeserializable;
+
/**
* User action to add a user into a group
*/
-class AddToGroupUserAction extends UserAction implements ObjectDeserializable {
+class AddToGroupUserAction extends UserAction implements ArrayDeserializable {
/**
* @var UserGroup The group to add the user to
*/
public $group;
/**
* @var boolean Determines if the target user has to be added to the group in the quality of admin
*/
public $isAdmin;
+
/**
* Executes the user action
*/
public function run () {
if ($this->targetUser->isMemberOfGroup($this->group)) {
if ($this->isAdmin) {
//Promotes to admin if needed
$this->targetUser->addToGroup($this->group, true);
}
} else {
//Adds user to the group
$this->targetUser->addToGroup($this->group, $this->isAdmin);
}
}
/**
- * Loads a AddToGroupUserAction instance from an object.
+ * Loads an AddToGroupUserAction instance from an object.
+ *
+ * @param array $data The associative array to deserialize
*
- * @param object $data The object to deserialize
* @return AddToGroupUserAction The deserialized instance
+ * @throws Exception when the group code is not found
*/
- public static function loadFromObject ($data) {
+ public static function loadFromArray (array $data) : self {
$instance = new AddToGroupUserAction();
- $instance->group = UserGroup::fromCode($data->code);
- $instance->isAdmin = ($data->isAdmin == true);
+
+ $instance->group = UserGroup::fromCode($data["code"]);
+ $instance->isAdmin = ($data["isAdmin"] == true);
+
return $instance;
}
}
diff --git a/workspaces/src/includes/auth/AuthenticationMethod.php b/workspaces/src/includes/auth/AuthenticationMethod.php
index 8bfb6fc..a83cc7a 100644
--- a/workspaces/src/includes/auth/AuthenticationMethod.php
+++ b/workspaces/src/includes/auth/AuthenticationMethod.php
@@ -1,243 +1,245 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Authentication method class
*
* @package ObsidianWorkspaces
* @subpackage Auth
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*/
use Waystone\Workspaces\Engines\Framework\Context;
+use Waystone\Workspaces\Engines\Serialization\ArrayDeserializable;
/**
* Authentication method class
*
* This class has to be extended to implement custom authentication methods.
*/
-abstract class AuthenticationMethod implements ObjectDeserializable {
+abstract class AuthenticationMethod implements ArrayDeserializable {
/**
* @var User The local user matching the authentication
*/
public $localUser;
/**
* @var string The username
*/
public $name;
/**
* @var string The e-mail address
*/
public $email;
/**
* @var string The authentication method identifiant
*/
public $id;
/**
* @var string The remote identity provider user identifiant
*/
public $remoteUserId;
/**
* @var Message The localized authentication login message
*/
public $loginMessage;
/**
* @var boolean Determines if the authentication method could be used to register new users
*/
public $canCreateUser = false;
/**
* @var Array Actions to execute if a user is created, each instance a member of UserAction
*/
public $createUserActions = [];
/**
* @var Context The site context
*/
public $context;
/**
* @var Message The localized authentication error message
*/
public $loginError;
/**
* Gets authentication link for this method
*/
public abstract function getAuthenticationLink();
/**
* Handles request
*/
public abstract function handleRequest();
/**
* Runs actions planned on user create
*/
protected function runCreateUserActions () {
foreach ($this->createUserActions as $action) {
$action->targetUser = $this->localUser;
$action->run();
}
}
/**
* Finds user from available data
*
* @return User the user if a user has been found; otherwise, false.
*/
private function findUser () {
if ($this->remoteUserId != '') {
$user = User::getUserFromRemoteIdentity(
$this->id, $this->remoteUserId
);
if ($user !== null) return $user;
}
if ($this->email != '') {
$user = User::get_user_from_email($this->email);
if ($user !== null) return $user;
}
return null;
}
/**
* Signs in or creates a new user
*
* @return boolean true if user has been successfully logged in; otherwise, false.
*/
public function signInOrCreateUser () {
// At this stage, if we don't already have a user instance,
// we're fetching it by remote user id or mail.
//
// If no result is returned, we're creating a new user if needed.
//
// Finally, we proceed to log in.
if ($this->localUser === null) {
$this->localUser = $this->findUser();
}
if ($this->localUser === null) {
if (!$this->canCreateUser) {
$this->loginError = Language::get("ExternalLoginCantCreateAccount");
return false;
} else {
$this->createUser();
if ($this->localUser === null) {
throw new Exception("Can't sign in: after correct remote authentication, an error occurred creating locally a new user.");
}
}
}
$this->signIn($this->localUser);
return true;
}
/**
* Signs in the specified user
*
* @param User The user to log in
*/
public function signIn(User $user) {
$this->context->session->user_login($user->id);
}
/**
* Creates a new user based on the authentication provisioning information
*
* @return User The user created
*/
public function createUser () {
if (!$this->canCreateUser) {
throw new Exception("Can't create user: the canCreateUser property is set at false.");
}
$user = User::create();
$user->name = $this->name;
$user->email = $this->email;
$user->save_to_database();
$user->setRemoteIdentity(
$this->id, $this->remoteUserId
);
$this->localUser = $user;
$this->runCreateUserActions();
}
/**
* Gets authentication method from ID
*
* @param string $id The authentication method id
* @param Context $context The site context
* @return AuthenticationMethod The authentication method matching the id
*/
public static function getFromId ($id, $context) {
if ($context->workspace != null) {
foreach ($context->workspace->configuration->authenticationMethods as $authenticationMethod) {
if ($authenticationMethod->id == $id) {
return $authenticationMethod;
}
}
}
return null;
}
/**
- * Loads a AuthenticationMethod instance from a generic object. Typically used to deserialize a JSON document.
+ * Loads an AuthenticationMethod instance from a generic array.
+ * Typically used to deserialize a configuration.
+ *
+ * @param array $data The associative array to deserialize
*
- * @param object $data The object to deserialize
* @return AuthenticationMethod The deserialized instance
+ * @throws InvalidArgumentException|Exception
*/
- public static function loadFromObject ($data) {
+ public static function loadFromArray(array $data) : self {
$instance = new static;
- if (!property_exists($data, 'id')) {
+ if (!array_key_exists("id", $data)) {
throw new InvalidArgumentException("Authentication method id is required.");
}
- $instance->id = $data->id;
+ $instance->id = $data["id"];
- if (property_exists($data, 'loginMessage')) {
- $instance->loginMessage = new Message($data->loginMessage);
- } else {
- $instance->loginMessage = new Message(Language::get("SignIn"));
- }
+ $message = $data["loginMessage"] ?? Language::get("SignIn");
+ $instance->loginMessage = new Message($message);
+
+ if (array_key_exists("createUser", $data)) {
+ $createUser = $data["createUser"];
- if (property_exists($data, 'createUser')) {
- if (property_exists($data->createUser, 'enabled')) {
- $instance->canCreateUser = ($data->createUser->enabled == true);
+ if (array_key_exists("enabled", $createUser)) {
+ $instance->canCreateUser = ($createUser["enabled"] === true);
}
- if (property_exists($data->createUser, 'addToGroups')) {
- foreach ($data->createUser->addToGroups as $actionData) {
- $instance->createUserActions[] = AddToGroupUserAction::loadFromObject($actionData);
- }
+ $addToGroups = $createUser["addToGroups"] ?? [];
+ foreach ($addToGroups as $actionData) {
+ $instance->createUserActions[] = AddToGroupUserAction::loadFromArray($actionData);
}
- if (property_exists($data->createUser, 'givePermissions')) {
- foreach ($data->createUser->givePermissions as $actionData) {
- $instance->createUserActions[] = GivePermissionUserAction::loadFromObject($actionData);
- }
+ $givePermissions = $createUser["givePermissions"] ?? [];
+ foreach ($createUser["givePermissions"] as $actionData) {
+ $instance->createUserActions[] = GivePermissionUserAction::loadFromArray($actionData);
}
}
return $instance;
}
+
}
diff --git a/workspaces/src/includes/auth/AzharProvider.php b/workspaces/src/includes/auth/AzharProvider.php
index 73d99a7..aa1cf74 100644
--- a/workspaces/src/includes/auth/AzharProvider.php
+++ b/workspaces/src/includes/auth/AzharProvider.php
@@ -1,205 +1,206 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Azhàr provider authentication method class
*
* @package ObsidianWorkspaces
* @subpackage Auth
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*/
/**
* Azhàr provider authentication method class
*
* Azhàr sends a document providing authentication and registration of new users.
* It's signed by a shared secret key.
*/
class AzharProvider extends AuthenticationMethod {
/**
* @var string Shared secret key
*/
public $secretKey;
/**
* @var string Client key, to identify the consumer application.
*/
public $clientKey;
/**
* @var string The Azhàr identity provider login URL
*/
public $url;
/**
* Handles user login request
*/
public function handleRequest () {
$action = array_key_exists('action', $_GET) ? $_GET['action'] : '';
$sessionKey = array_key_exists('sessionKey', $_GET) ? $_GET['sessionKey'] : '';
if ($action == "user.login.azhar.initialize") {
//Redirects user to Azhàr SSO service
$callbackUrl = get_server_url() . get_url($this->context->workspace->code)
. '?action=user.login.azhar.success&authenticationMethodId=' . $this->id;
$url = $this->url . '?mode=provider&key=' . $this->clientKey
. '&sessionKey=' . $this->getSessionKey()
. '&url=' . urlencode($callbackUrl);
header('Location: ' . $url);
exit;
} elseif ($action == "user.login.azhar.success") {
//User claims to have logged in, we can get authentication information
$reply = $this->fetchInformation();
if (!$this->isDocumentLegit($reply)) {
$this ->loginError = Language::get('ExternalLoginNotLegitReply');
return;
}
if ($reply->status == "SUCCESS") {
//Creates user or login
$this->name = $reply->username;
$this->email = $reply->email;
$this->remoteUserId = $reply->localUserId;
$this->signInOrCreateUser();
return;
} elseif ($reply->status == "ERROR_USER_SIDE") {
switch ($reply->code) {
case 'NO_USER_VISIT':
case 'NOT_LOGGED_IN':
$this ->loginError = Language::get('ExternalLoginNotRemotelyLoggedIn');
return;
}
} elseif ($reply->status == "ERROR_BETWEEN_US") {
switch ($reply->code) {
case 'SESSION_BADSECRET':
$this->loginError = sprintf(Language::get('ExternalLoginTechnicalDifficulty'), $reply->code);
return;
}
}
$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>';
} else {
$this ->loginError = '<p>Unknown action: $action</p>';
}
}
/**
* Gets Azhàr provider session key
*
* This key allows us as consumer to fetch information, and Azhàr as provider to store it.
*
* @return string the session key
*/
public function getSessionKey () {
$hash = md5($this->id);
if (!isset($_SESSION['Auth-$hash']['SessionKey'])) {
$url = $this->url . '?mode=provider.announce&key=' . $this->clientKey
. '&url=n/a';
$reply = self::query($url);
$this->setSessionSecret($reply->sessionSecret);
$_SESSION['Auth-$hash']['SessionKey'] = $reply->sessionKey;
}
return $_SESSION['Auth-$hash']['SessionKey'];
}
/**
* Gets Azhàr provider session secret
*
* @return string the session secret
*/
private function getSessionSecret () {
$hash = md5($this->id);
return $_SESSION['Auth-$hash']['SessionSecret'];
}
/**
* Sets Azhàr provider session secret
*
* @param string $secret the session secret
*/
private function setSessionSecret ($secret) {
$hash = md5($this->id);
$_SESSION['Auth-$hash']['SessionSecret'] = $secret;
}
/**
* Gets Azhàr external authentication link
*
* @retrun string the login link
*/
public function getAuthenticationLink() {
$url = get_server_url() . get_url($this->context->workspace->code)
. '?action=user.login.azhar.initialize&authenticationMethodId=' . $this->id;
return $url;
}
/**
* Determines if the document received has been signed by the correct shared secret key.
*
* @return boolean true if the document is legit; otherwise, false.
*/
function isDocumentLegit ($document) {
$hash = '';
$claimedHash = NULL;
foreach ($document as $key => $value) {
if ($key == 'hash') {
$claimedHash = $value;
continue;
}
$hash .= md5($key . $value);
}
$salt = '$2y$10$' . substr($this->secretKey, 0, 22);
$computedHash = crypt($hash, $salt);
return $claimedHash === $computedHash;
}
/**
* Fetches information document
*
* @return stdClass The Azhàr identity provider information about the current login operation
*/
function fetchInformation () {
$url = $this->url . '?mode=provider.fetch&key=' . $this->clientKey
. '&sessionSecret=' . $this->getSessionSecret()
. '&sessionKey=' . $this->getSessionKey()
. '&url=n/a';
return self::query($url);
}
/**
* Gets the contents of the specified URL and decode the JSON reply
*
* @param string $url The URL to the JSON document to query.
* @return stdClass The reply
*/
public static function query ($url) {
$data = file_get_contents($url);
return json_decode($data);
}
/**
- * Loads a AzharProvider instance from a generic object. Typically used to deserialize a JSON document.
+ * Loads an AzharProvider instance from a generic array.
+ * Typically used to deserialize a configuration.
*
- * @param object $data The object to deserialize
+ * @param array $data The associative array to deserialize
* @return AzharProvider The deserialized instance
*/
- public static function loadFromObject ($data) {
- $instance = parent::loadFromObject($data);
+ public static function loadFromArray (array $data) : self {
+ $instance = parent::loadFromArray($data);
- $instance->url = $data->url;
- $instance->secretKey = $data->secretKey;
- $instance->clientKey = $data->clientKey;
+ $instance->url = $data["url"];
+ $instance->secretKey = $data["secretKey"];
+ $instance->clientKey = $data["clientKey"];
return $instance;
}
}
diff --git a/workspaces/src/includes/auth/GivePermissionUserAction.php b/workspaces/src/includes/auth/GivePermissionUserAction.php
index 5e86245..33af0f4 100644
--- a/workspaces/src/includes/auth/GivePermissionUserAction.php
+++ b/workspaces/src/includes/auth/GivePermissionUserAction.php
@@ -1,106 +1,114 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Give permission user action class
*
* @package ObsidianWorkspaces
* @subpackage Auth
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
+use Waystone\Workspaces\Engines\Serialization\ArrayDeserializable;
+
/**
* User action to grant user a permission
*/
-class GivePermissionUserAction extends UserAction implements ObjectDeserializable, JsonSerializable {
+class GivePermissionUserAction extends UserAction implements ArrayDeserializable, JsonSerializable {
/**
* @var string The permission name
*/
public $permissionName;
/**
* @var int The permission flag
*/
public $permissionFlag = 1;
/**
* @var string The target resource type
*/
public $resourceType;
/**
* @var string The target resource identifier
*/
public $resourceIdentifier;
/**
* Executes the user action
*/
public function run () {
if (!$id = resolve_resource_id($this->resourceType, $this->resourceIdentifier)) {
throw new Exception("Can't get identifier from resource " . $this->resourceType . " " . $this->resourceIdentifier);
}
$this->targetUser->setPermission(
$this->resourceType, $id,
$this->permissionName, $this->permissionFlag
);
}
/**
- * Loads a GivePermissionUserAction instance from an object.
+ * Loads a GivePermissionUserAction instance from an associative array.
*
- * @param object $data The object to deserialize
+ * @param object $data The associative array to deserialize
* @return GivePermissionUserAction The deserialized instance
*/
- public static function loadFromObject ($data) {
- //Checks the object contains every mandatory data
- if (!property_exists($data, 'resource')) {
+ public static function loadFromArray (mixed $data) : self {
+ // Validate mandatory data
+ if (!array_key_exists("resource", $data)) {
throw new InvalidArgumentException("A resource property, with two mandatory type and id property is required.");
}
- if (!property_exists($data, 'permission')) {
+ if (!array_key_exists("permission", $data)) {
throw new InvalidArgumentException("A permission property, with a mandatory name property and a facultative flag property is required.");
}
- if (!property_exists($data->permission, 'name')) {
+
+ $resource = $data["resource"];
+ $permission = $data["permission"];
+
+ if (!array_key_exists("name", $permission)) {
throw new InvalidArgumentException("Permission name is required.");
}
- if (!property_exists($data->resource, 'type')) {
+ if (!array_key_exists("type", $resource)) {
throw new InvalidArgumentException("Resource type is required.");
}
- if (!property_exists($data->resource, 'id')) {
+ if (!array_key_exists("id", $resource)) {
throw new InvalidArgumentException("Resource id is required.");
}
- //Builds instance
+ // Build instance
$instance = new GivePermissionUserAction();
- $instance->resourceType = Permission::getResourceTypeLetterFromCode($data->resource->type);
- $instance->resourceIdentifier = $data->resource->id;
- $instance->permissionName = $data->permission->name;
- if (property_exists($data->permission, 'flag')) {
- $instance->permissionFlag = $data->permission->flag;
+ $instance->resourceType = Permission::getResourceTypeLetterFromCode($resource["type"]);
+ $instance->resourceIdentifier = $resource["id"];
+ $instance->permissionName = $permission["name"];
+
+ if (array_key_exists("flag", $permission)) {
+ $instance->permissionFlag = $permission["flag"];
}
return $instance;
}
+
/**
* Serializes the object to a value that can be serialized natively by json_encode().
*
* @return object The serializable value
*/
public function jsonSerialize() {
//TODO: if you wish strict code here, we need such a class.
$data->resource->type = Permission::getResourceTypeCodeFromLetter($this->resourceType);
$data->resource->id = $this->resourceIdentifier;
$data->permission->name = $this->permissionName;
$data->permission->flag = $this->permissionFlag;
return $data;
}
}
diff --git a/workspaces/src/includes/autoload.php b/workspaces/src/includes/autoload.php
index 5e0cb2c..6e00cba 100644
--- a/workspaces/src/includes/autoload.php
+++ b/workspaces/src/includes/autoload.php
@@ -1,107 +1,106 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Classes and interfaces auto loader
*
* @package ObsidianWorkspaces
* @filesource
*/
/**
* This SPL autoloader method is called when a class or an interface can't be loaded.
*/
function obsidian_autoload ($name) {
$dir = dirname(__DIR__);
///
/// Applications
///
if ($name == 'Document') { require $dir . '/apps/documents/Document.php'; return true; }
if ($name == 'DocumentsApplication') { require $dir . '/apps/documents/DocumentsApplication.php'; return true; }
if ($name == 'DocumentsApplicationConfiguration') { require $dir . '/apps/documents/DocumentsApplicationConfiguration.php'; return true; }
if ($name == 'DocumentType') { require $dir . '/apps/documents/DocumentType.php'; return true; }
if ($name == 'HelloWorldApplication') { require $dir . '/apps/helloworld/HelloWorldApplication.php'; return true; }
if ($name == 'MediaWikiMirrorApplication') { require $dir . '/apps/mediawikimirror/MediaWikiMirrorApplication.php'; return true; }
if ($name == 'MediaWikiMirrorApplicationConfiguration') { require $dir . '/apps/mediawikimirror/MediaWikiMirrorApplicationConfiguration.php'; return true; }
if ($name == 'StaticContentApplication') { require $dir . '/apps/staticcontent/StaticContentApplication.php'; return true; }
if ($name == 'StaticContentApplicationConfiguration') { require $dir . '/apps/staticcontent/StaticContentApplicationConfiguration.php'; return true; }
///
/// Core controllers
///
if ($name == 'ErrorPageController') { require $dir . '/controllers/errorpage.php'; return true; }
if ($name == 'FooterController') { require $dir . '/controllers/footer.php'; return true; }
if ($name == 'HeaderController') { require $dir . '/controllers/header.php'; return true; }
if ($name == 'HomepageController') { require $dir . '/controllers/home.php'; return true; }
///
/// Keruald and Obsidian Workspaces libraries
///
if ($name == 'Events') { require $dir . '/includes/Events.php'; return true; }
if ($name == 'LoadableWithContext') { require $dir . '/includes/LoadableWithContext.php'; return true; }
if ($name == 'ObjectDeserializable') { require $dir . '/includes/ObjectDeserializable.php'; return true; }
- if ($name == 'ObjectDeserializableWithContext') { require $dir . '/includes/ObjectDeserializable.php'; return true; }
if ($name == 'Application') { require $dir . '/includes/apps/Application.php'; return true; }
if ($name == 'ApplicationConfiguration') { require $dir . '/includes/apps/ApplicationConfiguration.php'; return true; }
if ($name == 'ApplicationContext') { require $dir . '/includes/apps/ApplicationContext.php'; return true; }
if ($name == 'AddToGroupUserAction') { require $dir . '/includes/auth/AddToGroupUserAction.php'; return true; }
if ($name == 'AuthenticationMethod') { require $dir . '/includes/auth/AuthenticationMethod.php'; return true; }
if ($name == 'AzharProvider') { require $dir . '/includes/auth/AzharProvider.php'; return true; }
if ($name == 'GivePermissionUserAction') { require $dir . '/includes/auth/GivePermissionUserAction.php'; return true; }
if ($name == 'UserAction') { require $dir . '/includes/auth/UserAction.php'; return true; }
if ($name == 'Cache') { require $dir . '/includes/cache/cache.php'; return true; }
if ($name == 'CacheMemcached') { require $dir . '/includes/cache/memcached.php'; return true; }
if ($name == 'CacheVoid') { require $dir . '/includes/cache/void.php'; return true; }
if ($name == 'Collection') { require $dir . '/includes/collection/Collection.php'; return true; }
if ($name == 'CollectionDocument') { require $dir . '/includes/collection/CollectionDocument.php'; return true; }
if ($name == 'FilesCollection') { require $dir . '/includes/collection/FilesCollection.php'; return true; }
if ($name == 'MongoDBCollection') { require $dir . '/includes/collection/MongoDBCollection.php'; return true; }
if ($name == 'MongoDBCollectionIterator') { require $dir . '/includes/collection/MongoDBCollectionIterator.php'; return true; }
if ($name == 'MySQLCollection') { require $dir . '/includes/collection/MySQLCollection.php'; return true; }
if ($name == 'SQLiteCollection') { require $dir . '/includes/collection/SQLiteCollection.php'; return true; }
if ($name == 'SQLCollection') { require $dir . '/includes/collection/SQLCollection.php'; return true; }
if ($name == 'Context') { require $dir . '/includes/controller/Context.php'; return true; }
if ($name == 'Controller') { require $dir . '/includes/controller/Controller.php'; return true; }
if ($name == 'RunnableWithContext') { require $dir . '/includes/controller/RunnableWithContext.php'; return true; }
if ($name == 'Database') { require $dir . '/includes/database/Database.php'; return true; }
if ($name == 'DatabaseException') { require $dir . '/includes/database/DatabaseException.php'; return true; }
if ($name == 'DatabaseResult') { require $dir . '/includes/database/DatabaseResult.php'; return true; }
if ($name == 'EmptyDatabaseResult') { require $dir . '/includes/database/EmptyDatabaseResult.php'; return true; }
if ($name == 'MySQLDatabase') { require $dir . '/includes/database/MySQLDatabase.php'; return true; }
if ($name == 'MySQLDatabaseResult') { require $dir . '/includes/database/MySQLDatabaseResult.php'; return true; }
if ($name == 'MySQLiDatabase') { require $dir . '/includes/database/MySQLiDatabase.php'; return true; }
if ($name == 'MySQLiDatabaseResult') { require $dir . '/includes/database/MySQLiDatabaseResult.php'; return true; }
if ($name == 'Language') { require $dir . '/includes/i18n/Language.php'; return true; }
if ($name == 'Message') { require $dir . '/includes/i18n/Message.php'; return true; }
if ($name == 'TextFileMessage') { require $dir . '/includes/i18n/TextFileMessage.php'; return true; }
if ($name == 'Disclaimer') { require $dir . '/includes/objects/Disclaimer.php'; return true; }
if ($name == 'Permission') { require $dir . '/includes/objects/Permission.php'; return true; }
if ($name == 'User') { require $dir . '/includes/objects/user.php'; return true; }
if ($name == 'UserGroup') { require $dir . '/includes/objects/usergroup.php'; return true; }
if ($name == 'Workspace') { require $dir . '/includes/workspaces/Workspace.php'; return true; }
if ($name == 'WorkspaceConfiguration') { require $dir . '/includes/workspaces/WorkspaceConfiguration.php'; return true; }
return false;
}
spl_autoload_register('obsidian_autoload');

File Metadata

Mime Type
text/x-diff
Expires
Wed, Mar 18, 12:57 (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3539882
Default Alt Text
(64 KB)

Event Timeline