Page MenuHomeDevCentral

No OneTemporary

diff --git a/composer.json b/composer.json
index 4034319..22635a6 100644
--- a/composer.json
+++ b/composer.json
@@ -1,51 +1,53 @@
{
"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/cache": "^0.1.1",
"keruald/database": "0.6.1",
"keruald/omnitools": "dev-develop/1.x@dev",
"keruald/yaml": "0.1.1",
"netresearch/jsonmapper": "^v5.0.0",
+ "psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
"smarty/smarty": "^5.6.0",
"vlucas/phpdotenv": "^v5.6.2",
"ext-mysqli": "*"
},
"require-dev": {
"nasqueron/codestyle": "^0.1.2",
"phpunit/phpunit": "^12.5",
"squizlabs/php_codesniffer": "^4.0"
},
"replace": {
"waystone/orbeon-forms": "0.1.0",
"waystone/workspaces": "1.0.0"
},
"autoload": {
"psr-4": {
"Waystone\\Apps\\OrbeonForms\\": "apps/orbeon-forms/src/",
"Waystone\\Apps\\OrbeonForms\\Tests\\": "apps/orbeon-forms/tests/",
"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 bdb648c..23529a2 100644
--- a/workspaces/composer.json
+++ b/workspaces/composer.json
@@ -1,32 +1,34 @@
{
"name": "waystone/workspaces",
"description": "Core interfaces for Obsidian Workspaces",
"type": "project",
"require": {
+ "keruald/cache": "^0.1.1",
"keruald/database": "0.5.2",
"keruald/omnitools": "0.16.0",
"keruald/yaml": "0.1.1",
+ "psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
"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/Framework/Application.php b/workspaces/src/Engines/Framework/Application.php
index 94a8c3d..4045546 100644
--- a/workspaces/src/Engines/Framework/Application.php
+++ b/workspaces/src/Engines/Framework/Application.php
@@ -1,34 +1,38 @@
<?php
namespace Waystone\Workspaces\Engines\Framework;
-use Keruald\Database\Database;
use Waystone\Workspaces\Engines\Errors\ErrorHandling;
use Waystone\Workspaces\Engines\Users\UserRepository;
+use Keruald\Cache\CacheFactory;
+use Keruald\Database\Database;
+
class Application {
public static function init () : void {
Environment::init();
ErrorHandling::init();
}
public static function getContext(array $config) : Context {
$context = new Context();
$context->config = $config;
$context->db = Database::load($config["sql"]);
$context->resources = new Resources(
new UserRepository($context->db),
);
$context->session = Session::load(
$context->db,
$context->resources->users,
);
$context->url = get_current_url_fragments();
$context->initializeTemplateEngine($context->config['Theme']);
+ $context->cache = CacheFactory::load($context->config["cache"]);
+
return $context;
}
}
diff --git a/workspaces/src/Engines/Framework/Context.php b/workspaces/src/Engines/Framework/Context.php
index f6d00b1..a9d30fa 100644
--- a/workspaces/src/Engines/Framework/Context.php
+++ b/workspaces/src/Engines/Framework/Context.php
@@ -1,108 +1,110 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Application context class
*
* @package ObsidianWorkspaces
* @subpackage Controller
* @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\Framework;
use Keruald\Database\DatabaseEngine;
+use Psr\SimpleCache\CacheInterface;
use Smarty\Smarty;
use Waystone\Workspaces\Engines\Users\User;
-use Waystone\Workspaces\Engines\Users\UserRepository;
use Waystone\Workspaces\Engines\Workspaces\WorkSpace;
/**
* Context class
*
* This class describes the site context.
*/
class Context {
/**
* @var ?WorkSpace the workspace currently enabled
*/
public ?WorkSpace $workspace = null;
/**
* @var DatabaseEngine the database
*/
public DatabaseEngine $db;
/**
* @var array the configuration
*/
public array $config;
public Resources $resources;
/**
* @var ?User the user currently logged in
*/
public ?User $user = null;
/**
* @var Session the current session
*/
public Session $session;
/**
* @var string[] the URL fragments
*/
public array $url;
/**
* @var Smarty the template engine
*/
public Smarty $templateEngine;
+ public CacheInterface $cache;
+
///
/// Helper methods
///
/**
* Gets application root directory
*
* @return string|false the application root directory
*/
public function getApplicationRootDirectory () : string|false {
return getcwd();
}
///
/// Templates
///
/**
* Initializes the template engine
*
* @param string $theme the theme for the templates
*/
public function initializeTemplateEngine (string $theme) : void {
$smarty = new Smarty();
$current_dir = static::getApplicationRootDirectory();
$smarty
->setTemplateDir("$current_dir/skins/$theme")
->setCacheDir($this->config["Content"]["Cache"])
->setCompileDir($this->config["Content"]["Cache"] . "/compiled")
->setConfigDir($current_dir);
$smarty->config_vars += [
"StaticContentURL" => $this->config["StaticContentURL"],
];
$this->templateEngine = $smarty;
}
}
diff --git a/workspaces/src/Engines/Workspaces/Workspace.php b/workspaces/src/Engines/Workspaces/Workspace.php
index a9bb21a..3d19e1e 100644
--- a/workspaces/src/Engines/Workspaces/Workspace.php
+++ b/workspaces/src/Engines/Workspaces/Workspace.php
@@ -1,301 +1,299 @@
<?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 Waystone\Workspaces\Engines\I18n\Language;
use Waystone\Workspaces\Engines\Users\User;
use Keruald\OmniTools\Collections\Vector;
-use Cache;
+use Psr\SimpleCache\InvalidArgumentException as InvalidArgumentCacheException;
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;
///
/// Constructors
///
/**
* Initializes a new instance
*
* @param int $id the primary key
*/
function __construct ($id = null) {
if ($id) {
$this->id = $id;
$this->load_from_database();
}
}
public static function fromRow ($row) : self {
$workspace = new self;
$workspace->load_from_row($row);
return $workspace;
}
///
/// Load data
///
/**
* 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;
$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;
}
// 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
+ * @throws InvalidArgumentCacheException
*/
public static function get_user_workspaces ($user_id) {
- //Gets the workspaces list from cache, as this complex request could take 100ms
- //and is called on every page.
- $cache = Cache::load();
- $cachedWorkspaces = $cache->get("workspaces-$user_id");
+ global $context;
+ $cache = $context->cache;
- if ($cachedWorkspaces !== null && $cachedWorkspaces !== false) {
- return unserialize($cachedWorkspaces);
- }
-
- $workspaces = self::loadWorkspacesForUser($user_id);
- $cache->set("workspaces-$user_id", serialize($workspaces));
-
- return $workspaces;
+ return $cache->get("workspaces-$user_id") ?? self::loadForUser($user_id);
}
/**
* @return self[]
*/
- private static function loadWorkspacesForUser (int $user_id) : array {
- global $db;
+ private static function loadForUser (int $user_id) : array {
+ global $context;
+ $db = $context->db;
+ $cache = $context->cache;
$clause = User::get_permissions_clause_from_user_id($user_id, $db);
$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);
}
- return Vector::from($result)
+ $workspaces = Vector::from($result)
->map(fn($row) => self::fromRow($row))
->toArray();
+
+ $cache->set("workspaces-$user_id", $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/includes/autoload.php b/workspaces/src/includes/autoload.php
index 92e632e..7eb2623 100644
--- a/workspaces/src/includes/autoload.php
+++ b/workspaces/src/includes/autoload.php
@@ -1,61 +1,57 @@
<?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 == '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 == 'Disclaimer') { require $dir . '/includes/objects/Disclaimer.php'; return true; }
if ($name == 'UserGroup') { require $dir . '/includes/objects/usergroup.php'; return true; }
return false;
}
spl_autoload_register('obsidian_autoload');
diff --git a/workspaces/src/includes/cache/cache.php b/workspaces/src/includes/cache/cache.php
deleted file mode 100644
index 65add3e..0000000
--- a/workspaces/src/includes/cache/cache.php
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Cache loader class.
- *
- * This file provides a calling class, which read the configuration, ensures
- * the cache class for the cache engine given in config exists and initializes
- * it.
- *
- * You'll find a sample of implementation in the CacheMemcached.
- * @see CacheMemcached
- *
- * If no caching mechanism, a "blackhole" void cache will be used.
- * @see CacheVoid.
- *
- * The class to call is determined from the following preference:
- * <code>
- * $Config['cache']['engine'] = 'memcached'; //will use CacheMemcached class.
- * </code>
- *
- * @package ObsidianWorkspaces
- * @subpackage Cache
- * @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\Errors\ErrorHandling;
-
-/**
- * Cache caller
- */
-class Cache {
- /**
- * Gets the cache instance, initializing it if needed
- *
- * The correct cache instance to initialize will be determined from the
- * $Config['cache']['engine'] preference.
- *
- * The class cache to use will be Cache + (preference engine, capitalized)
- *
- * This method will create an instance of the specified object,
- * calling the load static method from this object class.
- *
- * Example:
- * <code>
- * $Config['cache']['engine'] = 'quux';
- * $cache = Cache::load(); //Cache:load() will call CacheQuux:load();
- * </code>
- *
- * @return Cache the cache instance
- */
- static function load () {
- global $Config;
- if (
- !array_key_exists('cache', $Config) ||
- !array_key_exists('engine', $Config['cache'])
- ) {
- //cache is not configured or engine is not specified
- $engine = 'void';
- } else {
- //engine is specified in the configuration
- $engine = $Config['cache']['engine'];
- }
-
- $engine_file = 'includes/cache/' . $engine . '.php';
- $engine_class = 'Cache' . ucfirst($engine);
-
- if (!file_exists($engine_file)) {
- ErrorHandling::messageAndDie(GENERAL_ERROR, "Can't initialize $engine cache engine.<br />$engine_file not found.", 'Cache');
- }
-
- require_once($engine_file);
- if (!class_exists($engine_class)) {
- ErrorHandling::messageAndDie(GENERAL_ERROR, "Can't initialize $engine cache engine.<br />$engine_class class not found.", 'Cache');
- }
-
- return call_user_func(array($engine_class, 'load'));
- }
-}
diff --git a/workspaces/src/includes/cache/memcached.php b/workspaces/src/includes/cache/memcached.php
deleted file mode 100644
index 8f74c77..0000000
--- a/workspaces/src/includes/cache/memcached.php
+++ /dev/null
@@ -1,106 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * Memcached cache.
- *
- * @package ObsidianWorkspaces
- * @subpackage Cache
- * @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\Errors\ErrorHandling;
-
-/**
- * Memcached cache
- *
- * !!! This class uses the Memcached extension AND NOT the Memcache ext !!!!
- *
- * References:
- * @link http://www.php.net/manual/en/book/memcached.php
- * @link http://memcached.org
- *
- * This class implements a singleton pattern.
- */
-class CacheMemcached {
-
- /**
- * The current cache instance
- *
- * @var CacheMemcached
- */
- static $instance = null;
-
- /**
- * The Memcached object
- *
- * @var Memcached
- */
- private $memcached = null;
-
- /**
- * Gets the cache instance, initializing it if needed
- *
- * @return Cache the cache instance, or null if nothing is cached
- */
- static function load () {
- //Checks extension is okay
- if (!extension_loaded('memcached')) {
- if (extension_loaded('memcache')) {
- ErrorHandling::messageAndDie(GENERAL_ERROR, "Can't initialize $engine cache engine.<br />PHP extension memcached not loaded.<br /><strong>!!! This class uses the Memcached extension AND NOT the Memcache extension (this one is loaded) !!!</strong>", 'Cache');
- } else {
- ErrorHandling::messageAndDie(GENERAL_ERROR, "Can't initialize $engine cache engine.<br />PHP extension memcached not loaded.", 'Cache');
- }
- }
-
- //Creates the Memcached object if needed
- if (self::$instance === null) {
- global $Config;
-
- self::$instance = new CacheMemcached();
- self::$instance->memcached = new Memcached();
- self::$instance->memcached->addServer(
- $Config['cache']['server'],
- $Config['cache']['port']
- );
- }
-
- return self::$instance;
- }
-
- /**
- * Gets the specified key's data
- *
- * @param string $key the key to fetch
- * @return mixed the data at the specified key
- */
- function get ($key) {
- return $this->memcached->get($key);
- }
-
- /**
- * Sets the specified data at the specified key
- *
- * @param string $key the key where to store the specified data
- * @param mixed $value the data to store
- */
- function set ($key, $value) {
- return $this->memcached->set($key, $value);
- }
-
- /**
- * Deletes the specified key's data
- *
- * @param string $key the key to delete
- */
- function delete ($key) {
- return $this->memcached->delete($key);
- }
-}
diff --git a/workspaces/src/includes/cache/void.php b/workspaces/src/includes/cache/void.php
deleted file mode 100644
index bb33e58..0000000
--- a/workspaces/src/includes/cache/void.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-
-/**
- * _, __, _, _ __, _ _, _, _
- * / \ |_) (_ | | \ | /_\ |\ |
- * \ / |_) , ) | |_/ | | | | \|
- * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- *
- * "Blackhole" void cache.
- *
- * @package ObsidianWorkspaces
- * @subpackage Cache
- * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
- * @license http://www.opensource.org/licenses/bsd-license.php BSD
- * @filesource
- *
- */
-
-/**
- * "blackhole" void cache
- *
- * This class doesn't cache information, it's a void wrapper
- * get will always return null
- * set and delete do nothing
- *
- * It will be used by default if no cache is specified.
- *
- * This class implements a singleton pattern.
- */
-class CacheVoid {
- /**
- * @var CacheVoid the current cache instance
- */
- static $instance = null;
-
- /**
- * Gets the cache instance, initializing it if needed
- *
- * @return Cache the cache instance, or null if nothing is cached
- */
- static function load () {
- if (self::$instance === null) {
- self::$instance = new CacheVoid();
- }
-
- return self::$instance;
- }
-
- /**
- * Gets the specified key's data
- *
- * @param string $key the key to fetch
- * @return mixed the data at the specified key
- */
- function get ($key) {
- return null;
- }
-
- /**
- * Sets the specified data at the specified key
- *
- * @param string $key the key where to store the specified data
- * @param mixed $value the data to store
- */
- function set ($key, $value) { }
-
- /**
- * Deletes the specified key's data
- *
- * @param string $key the key to delete
- */
- function delete ($key) { }
-}
diff --git a/workspaces/src/includes/config.php b/workspaces/src/includes/config.php
index 75394fc..1332984 100755
--- a/workspaces/src/includes/config.php
+++ b/workspaces/src/includes/config.php
@@ -1,279 +1,280 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Configuration file
*
* This file will contain your site/application settings. Ideally, you should
* make this file autogenerable by a setup process.
*
* @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
*
*/
+use Keruald\Cache\Engines\CacheVoid;
use Keruald\Database\Engines\MySQLiEngine;
////////////////////////////////////////////////////////////////////////////////
/// ///
/// I. SQL configuration ///
/// ///
////////////////////////////////////////////////////////////////////////////////
//SQL configuration
$Config['sql']['engine'] = MySQLiEngine::class;
$Config['sql']['host'] = $_ENV["DB_HOST"] ?? 'localhost';
$Config['sql']['username'] = $_ENV["DB_USER"] ?? 'obsidian';
$Config['sql']['password'] = $_ENV["DB_PASSWORD"] ?? 'obsidian';
$Config['sql']['database'] = $_ENV["DB_NAME"] ?? 'obsidian';
$Config['sql']['fetch_mode'] = MYSQLI_BOTH;
$Config['sql']['dontThrowExceptions'] = true;
//SQL tables
$prefix = '';
define('TABLE_PERMISSIONS', $prefix . 'permissions');
define('TABLE_USERS', $prefix . 'users');
define('TABLE_USERS_AUTH', $prefix . 'users_auth');
define('TABLE_UGROUPS', $prefix . 'users_groups');
define('TABLE_UGROUPS_MEMBERS', $prefix . 'users_groups_members');
define('TABLE_SESSIONS', $prefix . 'sessions');
define('TABLE_WORKSPACES', $prefix . 'workspaces');
////////////////////////////////////////////////////////////////////////////////
/// ///
/// II. Site configuration ///
/// ///
////////////////////////////////////////////////////////////////////////////////
//Dates
date_default_timezone_set("UTC");
//Secret key, used for some verification hashes in URLs (e.g. xhr calls)
//or forms.
$Config['SecretKey'] = 'Replace this by a secret key, like AdYN}"p/+D.U]M^MC&-Q~KFthXZCT*g<V:dL.@{Mt-Di1mEA\&~_Eh\I\WA';
//When reading files, buffer size
const BUFFER_SIZE = 4096;
//Site theme
$Config['Theme'] = 'bluegray';
////////////////////////////////////////////////////////////////////////////////
/// ///
/// III. Script URLs ///
/// ///
////////////////////////////////////////////////////////////////////////////////
/*
* The following settings give your script/application URL.
*
* Without mod_rewrite:
*
* Subdirectory:
* - $Config['SiteURL'] = 'http://www.yourdomain.tld/application/index.php';
* - $Config['BaseURL'] = '/application/index.php';
*
* Root directory:
* - $Config['SiteURL'] = 'http://www.yourdomain.tld/index.php';
* - $Config['BaseURL'] = '/index.php';
*
* With mod_rewrite:
*
* Subdirectory:
* - $Config['SiteURL'] = 'http://www.yourdomain.tld/application';
* - $Config['BaseURL'] = '/application';
*
* In .htaccess or your vhost definition:
* RewriteEngine On
* RewriteBase /application/
* RewriteCond %{REQUEST_FILENAME} !-f
* RewriteCond %{REQUEST_FILENAME} !-d
* RewriteRule . /application/index.php [L]
*
* Root directory:
* - $Config['SiteURL'] = 'http://www.yourdomain.tld';
* - $Config['BaseURL'] = '';
*
* In .htaccess or your vhost definition:
* RewriteEngine On
* RewriteBase /
* RewriteCond %{REQUEST_FILENAME} !-f
* RewriteCond %{REQUEST_FILENAME} !-d
* RewriteRule . /index.php [L]
*
*
* If you don't want to specify the server domain, you can use get_server_url:
* $Config['SiteURL'] = get_server_url() . '/application';
* $Config['SiteURL'] = get_server_url();
*
* !!! No trailing slash !!!
*
*/
$Config['SiteURL'] = get_server_url();
$Config['BaseURL'] = '';
////////////////////////////////////////////////////////////////////////////////
/// ///
/// IV. Static content ///
/// ///
////////////////////////////////////////////////////////////////////////////////
//Where the static content is located?
//Static content = 4 directories: js, css, img and content
//On default installation, those directories are at site root.
//To improve site performance, you can use a CDN for that.
//
//Recommanded setting: $Config['StaticContentURL'] = $Config['SiteURL'];
//Or if this is the site root: $Config['StaticContentURL'] = '';
//With CoralCDN: $Config['StaticContentURL'] = . '.nyud.net';
//
$Config['StaticContentURL'] = '';
//$Config['StaticContentURL'] = get_server_url() . '.nyud.net';
//Content directories
$Config['Content']['Cache'] = 'content/cache';
$Config['Content']['Help'] = 'content/help';
$Config['Content']['Workspaces'] = 'content/workspaces';
$Config['Content']['Disclaimers'] = 'content/disclaimers';
/*
* The following settings configure your document storage engine.
*
* To use MongoDB:
*
* $Config['DocumentStorage'] = [
* 'Type' => 'MongoDB',
* 'Host' => 'mymongoinstance.domain.tld',
* 'Port' => 27017,
* 'Database' => 'obsidian'
* ];
*
* To use MongoDB, and authenticate with a username and a password:
*
* $Config['DocumentStorage'] = [
* 'Type' => 'MongoDB',
* 'Host' => 'mymongoinstance.domain.tld',
* 'Port' => 27017,
* 'Database' => 'obsidian',
* 'Username' => 'yourusername',
* 'Password' => 'yourpassword'
* ];
*
* To connect to MongoDB with SSL, use the same syntax and add a SSL context as 'SSL' parameter.
* Documentation about SSL context is located at the following PHP documentation URL:
* http://www.php.net/manual/en/context.ssl.php
*
* $Config['DocumentStorage'] = [
* 'Type' => 'MongoDB',
* 'Host' => 'mymongoinstance.domain.tld',
* 'Port' => 27017,
* 'Database' => 'obsidian',
* 'SSL' => [
* 'cafile' => '/path/to/CAcertificate.crt',
* 'local_cert' => '/path/to/yourcertificate.pem',
* 'verify_peer' => true,
* 'allow_self_signed' => false,
* 'CN_match' => 'the server certificate expected CN'
* ]
* ];
*
*
* If you don't want to deploy a MongoDB server, you can use either MySQL
* or SQLite 3 if you need concurrency, either plain text files if you're
* the only user as a fallback.
*
*
* For MySQL, it uses the same connection as the main application.
*
* $Config['DocumentStorage'] = [
* 'Type' => 'MySQL',
* 'Table' => $prefix . 'collections',
* ];
*
* Engine will automatically intialize the database if the file hasn't been found.
*
* You can also store the table in another database with the db.table syntax:
*
* $Config['DocumentStorage'] = [
* 'Type' => 'MySQL',
* 'Table' => 'obsidian_data.collections',
* ];
*
*
* To use SQLite 3:
*
* $Config['DocumentStorage'] = [
* 'Type' => 'SQLite',
* 'File' => 'content/collections.db',
* ];
*
* Engine will automatically intialize the database if the file hasn't been found.
*
*
* To use file storage, create a folder and gives it as path parameter:
*
* $Config['DocumentStorage'] = [
* 'Type' => 'Files',
* 'Path' => 'content/collections',
* ];
*
*/
$Config['DocumentStorage'] = [
'Type' => 'MongoDB',
'Host' => 'localhost',
'Port' => 27017
];
//ImageMagick paths
//Be careful on Windows platform convert could match the NTFS convert command.
$Config['ImageMagick']['convert'] = 'convert';
$Config['ImageMagick']['mogrify'] = 'mogrify';
$Config['ImageMagick']['composite'] = 'composite';
$Config['ImageMagick']['identify'] = 'identify';
////////////////////////////////////////////////////////////////////////////////
/// ///
/// V. Caching ///
/// ///
////////////////////////////////////////////////////////////////////////////////
/*
* Some data (Smarty, OpenID and sessions) are cached in the cache directory.
*
* Security tip: you can move this cache directory outside the webserver tree.
*/
const CACHE_DIR = 'cache';
/*
* Furthermore, you can also enable a cache engine, like memcached, to store
* data from heavy database queries, or frequently accessed stuff.
*
* To use memcached:
- * - $Config['cache']['engine'] = 'memcached';
+ * - $Config['cache']['engine'] = CacheMemcached::class;
* - $Config['cache']['server'] = 'localhost';
* - $Config['cache']['port'] = 11211;
*
* To disable cache:
- * - $Config['cache']['engine'] = 'void';
+ * - $Config['cache']['engine'] = CacheVoid::class;
* (or omit the cache key)
*/
-$Config['cache']['engine'] = 'void';
+$Config['cache']['engine'] = CacheVoid::class;
////////////////////////////////////////////////////////////////////////////////
/// ///
/// VI. Sessions ///
/// ///
////////////////////////////////////////////////////////////////////////////////
//If you want to use a common table of sessions / user handling
//with several websites, specify a different resource id for each site.
$Config['ResourceID'] = 32;

File Metadata

Mime Type
text/x-diff
Expires
Wed, Mar 18, 13:18 (14 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3539974
Default Alt Text
(38 KB)

Event Timeline