Commit 745515b1 authored by Klaus Weidenbach's avatar Klaus Weidenbach

[FEATURE] Add config and use composer autoloader.

We use composer already to install SabreDAV. Include config
composer.(json|lock) to install and manage more dependencies
in future.
Also provide PSR-4 autoloading for our namespaced classes, e.g.
"Zotlabs\". To regenerate autoloader maps use:
$ composer install --optimize-autoloader --no-dev

We could also remove the whole vendor/ folder from our repository, but
that would need changes in deployment and how to install hubs and needs
more discussion first.
parent 17091bd3
......@@ -60,11 +60,13 @@ nbproject/
.idea/
# composer files (at the moment composer is not officially supported and only used to add SabreDAV, we should add these)
composer.*
# When we include composer we should exclude vendor/
## composer
# locally installed composer binary
composer.phar
# vendor/ is managed by composer, no need to include in our repository
# requires new deployment and needs discussion first
#vendor/
# Exclude at least some vendor test files, examples, etc.
vendor/sabre/*/tests/
# Exclude at least some vendor test files, examples, etc. so far
vendor/**/tests/
vendor/**/Test/
vendor/sabre/*/examples/
......@@ -24,8 +24,7 @@ class Master {
static public function Release($argc,$argv) {
cli_startup();
logger('Master: release: ' . print_r($argv,true), LOGGER_ALL,LOG_DEBUG);
require_once('Zotlabs/Daemon/' . $argv[0] . '.php');
$cls = '\\Zotlabs\\Daemon\\' . $argv[0];
$cls::run($argc,$argv);
}
}
\ No newline at end of file
}
......@@ -11,9 +11,6 @@ namespace Zotlabs\Module;
use \Sabre\DAV as SDAV;
use \Zotlabs\Storage;
// composer autoloader for SabreDAV
require_once('vendor/autoload.php');
require_once('include/attach.php');
class Dav extends \Zotlabs\Web\Controller {
......@@ -74,7 +71,6 @@ class Dav extends \Zotlabs\Web\Controller {
$auth->setBrowserPlugin($browser);
// Experimental QuotaPlugin
// require_once('Zotlabs/Storage/QuotaPlugin.php');
// $server->addPlugin(new \Zotlabs\Storage\QuotaPlugin($auth));
// All we need to do now, is to fire up the server
......
......@@ -27,6 +27,9 @@
* documented.
*/
// composer autoloader for all namespaced Classes
require_once('vendor/autoload.php');
require_once('include/config.php');
require_once('include/network.php');
require_once('include/plugin.php');
......@@ -695,44 +698,14 @@ function startup() {
}
class ZotlabsAutoloader {
static public function loader($className) {
$debug = false;
$filename = str_replace('\\', '/', $className) . ".php";
if(file_exists($filename)) {
include($filename);
if (class_exists($className)) {
return TRUE;
}
}
$arr = explode('\\',$className);
if($arr && count($arr) > 1) {
if(! $arr[0])
$arr = array_shift($arr);
$filename = 'addon/' . lcfirst($arr[0]) . '/' . $arr[1] . ((count($arr) === 2) ? '.php' : '/' . $arr[2] . ".php");
if(file_exists($filename)) {
include($filename);
if (class_exists($className)) {
return TRUE;
}
}
}
return FALSE;
}
}
/**
* class miniApp
*
* this is a transient structure which is needed to convert the $a->config settings
* from older (existing) htconfig files which used a global App ($a) into the updated App structure
* which is now static (although currently constructed at startup). We are only converting
* 'system' config settings.
* which is now static (although currently constructed at startup). We are only converting
* 'system' config settings.
*/
class miniApp {
public $config = array('system' => array());
......@@ -982,24 +955,21 @@ class App {
* register template engines
*/
spl_autoload_register('ZotlabsAutoloader::loader');
self::$meta= new Zotlabs\Web\HttpMeta();
// create an instance of the smarty template engine so we can register it.
$smarty = new Zotlabs\Render\SmartyTemplate();
/// @todo validate if this is still the desired behavior
self::register_template_engine(get_class($smarty));
/*
$dc = get_declared_classes();
foreach ($dc as $k) {
if(in_array('Zotlabs\\Render\\TemplateEngine', class_implements($k))) {
self::register_template_engine($k);
}
}
*/
}
public static function get_baseurl($ssl = false) {
......
{
"name" : "zotlabs/hubzilla",
"type" : "application",
"description" : "Hubzilla is a powerful platform for creating interconnected websites featuring a decentralized identity, communications, and permissions framework built using common webserver technology.",
"keywords" : [
"CMS",
"identity",
"decentralisation",
"permission",
"SSO",
"ZOT"
],
"homepage" : "http://github.com/redmatrix/hubzilla",
"license" : "MIT",
"authors" : [{
"name" : "Mike Macgirvin",
"role" : "founder"
}
],
"support" : {
"issues" : "https://github.com/redmatrix/hubzilla/issues",
"source" : "https://github.com/redmatrix/hubzilla"
},
"require" : {
"php" : ">=5.5",
"ext-curl" : "*",
"ext-gd" : "*",
"ext-mbstring" : "*",
"ext-xml" : "*",
"sabre/dav" : "~3.2",
"ext-openssl" : "*"
},
"autoload" : {
"psr-4" : {
"Hubzilla\\" : "include/",
"Zotlabs\\" : "Zotlabs/"
}
},
"minimum-stability" : "stable",
"config" : {
"notify-on-install" : false
}
}
......@@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit02c7a5bb99a87a4c8dbf069d69b1a15c::getLoader();
return ComposerAutoloaderInit7b34d7e50a62201ec5d5e526a5b8b35d::getLoader();
......@@ -53,8 +53,8 @@ class ClassLoader
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
public function getPrefixes()
{
......@@ -322,20 +322,20 @@ class ClassLoader
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative) {
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) {
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if ($file === null) {
if (false === $file) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
$this->missingClasses[$class] = true;
}
return $file;
......@@ -399,6 +399,8 @@ class ClassLoader
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
......
This diff is collapsed.
......@@ -7,10 +7,10 @@ $baseDir = dirname($vendorDir);
return array(
'383eaff206634a77a1be54e64e6459c7' => $vendorDir . '/sabre/uri/lib/functions.php',
'3569eecfeed3bcf0bad3c998a494ecb8' => $vendorDir . '/sabre/xml/lib/Deserializer/functions.php',
'93aa591bc4ca510c520999e34229ee79' => $vendorDir . '/sabre/xml/lib/Serializer/functions.php',
'2b9d0f43f9552984cfa82fee95491826' => $vendorDir . '/sabre/event/lib/coroutine.php',
'd81bab31d3feb45bfe2f283ea3c8fdf7' => $vendorDir . '/sabre/event/lib/Loop/functions.php',
'a1cce3d26cc15c00fcd0b3354bd72c88' => $vendorDir . '/sabre/event/lib/Promise/functions.php',
'3569eecfeed3bcf0bad3c998a494ecb8' => $vendorDir . '/sabre/xml/lib/Deserializer/functions.php',
'93aa591bc4ca510c520999e34229ee79' => $vendorDir . '/sabre/xml/lib/Serializer/functions.php',
'ebdb698ed4152ae445614b69b5e4bb6a' => $vendorDir . '/sabre/http/lib/functions.php',
);
......@@ -6,5 +6,4 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Psr\\Log\\' => array($vendorDir . '/psr/log'),
);
......@@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Zotlabs\\' => array($baseDir . '/Zotlabs'),
'Sabre\\Xml\\' => array($vendorDir . '/sabre/xml/lib'),
'Sabre\\VObject\\' => array($vendorDir . '/sabre/vobject/lib'),
'Sabre\\Uri\\' => array($vendorDir . '/sabre/uri/lib'),
......@@ -15,4 +16,6 @@ return array(
'Sabre\\DAVACL\\' => array($vendorDir . '/sabre/dav/lib/DAVACL'),
'Sabre\\CardDAV\\' => array($vendorDir . '/sabre/dav/lib/CardDAV'),
'Sabre\\CalDAV\\' => array($vendorDir . '/sabre/dav/lib/CalDAV'),
'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
'Hubzilla\\' => array($baseDir . '/include'),
);
......@@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit02c7a5bb99a87a4c8dbf069d69b1a15c
class ComposerAutoloaderInit7b34d7e50a62201ec5d5e526a5b8b35d
{
private static $loader;
......@@ -19,15 +19,15 @@ class ComposerAutoloaderInit02c7a5bb99a87a4c8dbf069d69b1a15c
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit02c7a5bb99a87a4c8dbf069d69b1a15c', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit7b34d7e50a62201ec5d5e526a5b8b35d', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit02c7a5bb99a87a4c8dbf069d69b1a15c', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit7b34d7e50a62201ec5d5e526a5b8b35d', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit02c7a5bb99a87a4c8dbf069d69b1a15c::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit7b34d7e50a62201ec5d5e526a5b8b35d::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
......@@ -48,19 +48,19 @@ class ComposerAutoloaderInit02c7a5bb99a87a4c8dbf069d69b1a15c
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit02c7a5bb99a87a4c8dbf069d69b1a15c::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit7b34d7e50a62201ec5d5e526a5b8b35d::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire02c7a5bb99a87a4c8dbf069d69b1a15c($fileIdentifier, $file);
composerRequire7b34d7e50a62201ec5d5e526a5b8b35d($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire02c7a5bb99a87a4c8dbf069d69b1a15c($fileIdentifier, $file)
function composerRequire7b34d7e50a62201ec5d5e526a5b8b35d($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;
......
This diff is collapsed.
......@@ -52,84 +52,19 @@
"url"
]
},
{
"name": "sabre/xml",
"version": "1.4.2",
"version_normalized": "1.4.2.0",
"source": {
"type": "git",
"url": "https://github.com/fruux/sabre-xml.git",
"reference": "f48d98c22a4a4bef76cabb5968ffaddbb2bb593e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fruux/sabre-xml/zipball/f48d98c22a4a4bef76cabb5968ffaddbb2bb593e",
"reference": "f48d98c22a4a4bef76cabb5968ffaddbb2bb593e",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-xmlreader": "*",
"ext-xmlwriter": "*",
"lib-libxml": ">=2.6.20",
"php": ">=5.4.1",
"sabre/uri": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "*",
"sabre/cs": "~0.0.2"
},
"time": "2016-05-19 21:56:49",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Sabre\\Xml\\": "lib/"
},
"files": [
"lib/Deserializer/functions.php",
"lib/Serializer/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Evert Pot",
"email": "me@evertpot.com",
"homepage": "http://evertpot.com/",
"role": "Developer"
},
{
"name": "Markus Staab",
"email": "markus.staab@redaxo.de",
"role": "Developer"
}
],
"description": "sabre/xml is an XML library that you may not hate.",
"homepage": "https://sabre.io/xml/",
"keywords": [
"XMLReader",
"XMLWriter",
"dom",
"xml"
]
},
{
"name": "sabre/vobject",
"version": "4.1.0",
"version_normalized": "4.1.0.0",
"version": "4.1.1",
"version_normalized": "4.1.1.0",
"source": {
"type": "git",
"url": "https://github.com/fruux/sabre-vobject.git",
"reference": "8899c0e856b3178b17f4e9a4e85010209f32a2fa"
"reference": "a3a59b06947f122af2d45d52b72172cdc1efd68f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fruux/sabre-vobject/zipball/8899c0e856b3178b17f4e9a4e85010209f32a2fa",
"reference": "8899c0e856b3178b17f4e9a4e85010209f32a2fa",
"url": "https://api.github.com/repos/fruux/sabre-vobject/zipball/a3a59b06947f122af2d45d52b72172cdc1efd68f",
"reference": "a3a59b06947f122af2d45d52b72172cdc1efd68f",
"shasum": ""
},
"require": {
......@@ -144,7 +79,7 @@
"suggest": {
"hoa/bench": "If you would like to run the benchmark scripts"
},
"time": "2016-04-07 00:48:27",
"time": "2016-07-15 19:52:17",
"bin": [
"bin/vobject",
"bin/generate_vcards"
......@@ -191,6 +126,7 @@
"availability",
"freebusy",
"iCalendar",
"ical",
"ics",
"jCal",
"jCard",
......@@ -208,6 +144,7 @@
"rfc6638",
"rfc6715",
"rfc6868",
"vCalendar",
"vCard",
"vcf",
"xCal",
......@@ -330,46 +267,6 @@
"http"
]
},
{
"name": "psr/log",
"version": "1.0.0",
"version_normalized": "1.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "fe0936ee26643249e916849d48e3a51d5f5e278b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b",
"reference": "fe0936ee26643249e916849d48e3a51d5f5e278b",
"shasum": ""
},
"time": "2012-12-21 11:40:51",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"Psr\\Log\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"keywords": [
"log",
"psr",
"psr-3"
]
},
{
"name": "sabre/dav",
"version": "3.2.0",
......@@ -454,5 +351,119 @@
"framework",
"iCalendar"
]
},
{
"name": "sabre/xml",
"version": "1.5.0",
"version_normalized": "1.5.0.0",
"source": {
"type": "git",
"url": "https://github.com/fruux/sabre-xml.git",
"reference": "59b20e5bbace9912607481634f97d05a776ffca7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fruux/sabre-xml/zipball/59b20e5bbace9912607481634f97d05a776ffca7",
"reference": "59b20e5bbace9912607481634f97d05a776ffca7",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-xmlreader": "*",
"ext-xmlwriter": "*",
"lib-libxml": ">=2.6.20",
"php": ">=5.5.5",
"sabre/uri": ">=1.0,<3.0.0"
},
"require-dev": {
"phpunit/phpunit": "*",
"sabre/cs": "~1.0.0"
},
"time": "2016-10-09 22:57:52",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Sabre\\Xml\\": "lib/"
},
"files": [
"lib/Deserializer/functions.php",
"lib/Serializer/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Evert Pot",
"email": "me@evertpot.com",
"homepage": "http://evertpot.com/",
"role": "Developer"
},
{
"name": "Markus Staab",
"email": "markus.staab@redaxo.de",
"role": "Developer"
}
],
"description": "sabre/xml is an XML library that you may not hate.",
"homepage": "https://sabre.io/xml/",
"keywords": [
"XMLReader",
"XMLWriter",
"dom",
"xml"
]
},
{
"name": "psr/log",
"version": "1.0.2",
"version_normalized": "1.0.2.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2016-10-10 12:19:37",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
]
}
]
......@@ -15,8 +15,9 @@ abstract class AbstractLogger implements LoggerInterface
* System is unusable.
*
* @param string $message
* @param array $context
* @return null
* @param array $context
*
* @return void
*/
public function emergency($message, array $context = array())
{
......@@ -30,8 +31,9 @@ abstract class AbstractLogger implements LoggerInterface
* trigger the SMS alerts and wake you up.
*
* @param string $message
* @param array $context
* @return null
* @param array $context
*
* @return void
*/
public function alert($message, array $context = array())
{
......@@ -44,8 +46,9 @@ abstract class AbstractLogger implements LoggerInterface
* Example: Application component unavailable, unexpected exception.
*
* @param string $message
* @param array $context
* @return null
* @param array $context
*
* @return void
*/
public function critical($message, array $context = array())
{
......@@ -57,8 +60,9 @@ abstract class AbstractLogger implements LoggerInterface
* be logged and monitored.
*
* @param string $message
* @param array $context
* @return null
* @param array $context
*
* @return void
*/
public function error($message, array $context = array())
{
......@@ -72,8 +76,9 @@ abstract class AbstractLogger implements LoggerInterface
* that are not necessarily wrong.
*
* @param string $message
* @param array $context
* @return null
* @param array $context
*
* @return void
*/
public function warning($message, array $context = array())
{
......@@ -84,8 +89,9 @@ abstract class AbstractLogger implements LoggerInterface
* Normal but significant events.
*
* @param string $message
* @param array $context
* @return null
* @param array $context
*
* @return void
*/
public function notice($message, array $context = array())
{
......@@ -98,8 +104,9 @@ abstract class AbstractLogger implements LoggerInterface
* Example: User logs in, SQL logs.
*
* @param string $message
* @param array $context
* @return null
* @param array $context
*
* @return void
*/
public function info($message, array $context = array())
{
......@@ -110,8 +117,9 @@ abstract class AbstractLogger implements LoggerInterface
* Detailed debug information.
*
* @param string $message
* @param array $context
* @return null
* @param array $context
*
* @return void
*/
public function debug($message, array $context = array())
{
......
......@@ -3,16 +3,16 @@
namespace Psr\Log;
/**
* Describes log levels
* Describes log levels.
*/
class LogLevel
{
const EMERGENCY = 'emergency';
const ALERT = 'alert';
const CRITICAL = 'critical';
const ERROR = 'error';
const WARNING = 'warning';
const NOTICE = 'notice';
const INFO = 'info';
const DEBUG = 'debug';
const ALERT = 'alert';
const CRITICAL = 'critical';
const ERROR = 'error';
const WARNING = 'warning';
const NOTICE = 'notice';
const INFO = 'info';
const DEBUG = 'debug';