Introduce PSR-4 autoloading
This commit is contained in:
38
lib/auto.php
38
lib/auto.php
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PrivateBin
|
||||
*
|
||||
* a zero-knowledge paste bin
|
||||
*
|
||||
* @link https://github.com/PrivateBin/PrivateBin
|
||||
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
|
||||
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
spl_autoload_register('auto::loader');
|
||||
|
||||
/**
|
||||
* auto
|
||||
*
|
||||
* provides autoloading functionality
|
||||
*/
|
||||
class auto
|
||||
{
|
||||
/**
|
||||
* includes file for given class name
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $class_name
|
||||
* @return mixed
|
||||
*/
|
||||
public static function loader($class_name)
|
||||
{
|
||||
$filename = PATH . 'lib/' . str_replace('_', '/', $class_name) . '.php';
|
||||
if(is_readable($filename)) {
|
||||
return include $filename;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,11 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
use Exception;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* configuration
|
||||
*
|
||||
|
||||
@@ -10,12 +10,14 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin\data;
|
||||
|
||||
/**
|
||||
* privatebin_abstract
|
||||
*
|
||||
* Abstract model for PrivateBin data access, implemented as a singleton.
|
||||
*/
|
||||
abstract class privatebin_abstract
|
||||
abstract class AbstractData
|
||||
{
|
||||
/**
|
||||
* singleton instance
|
||||
@@ -10,12 +10,14 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin\data;
|
||||
|
||||
/**
|
||||
* privatebin_data
|
||||
*
|
||||
* Model for data access, implemented as a singleton.
|
||||
*/
|
||||
class privatebin_data extends privatebin_abstract
|
||||
class data extends AbstractData
|
||||
{
|
||||
/**
|
||||
* directory where data is stored
|
||||
@@ -248,7 +250,7 @@ class privatebin_data extends privatebin_abstract
|
||||
if (!is_dir($path)) continue;
|
||||
$thirdLevel = array_filter(
|
||||
scandir($path),
|
||||
array('model_paste', 'isValidId')
|
||||
array('PrivateBin\\model\\paste', 'isValidId')
|
||||
);
|
||||
if (count($thirdLevel) == 0) continue;
|
||||
$thirdKey = array_rand($thirdLevel);
|
||||
@@ -10,12 +10,20 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin\data;
|
||||
|
||||
use Exception;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use PrivateBin\privatebin;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* privatebin_db
|
||||
*
|
||||
* Model for DB access, implemented as a singleton.
|
||||
*/
|
||||
class privatebin_db extends privatebin_abstract
|
||||
class db extends AbstractData
|
||||
{
|
||||
/**
|
||||
* cache for select queries
|
||||
@@ -10,6 +10,11 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
use Exception;
|
||||
use PrivateBin\i18n;
|
||||
|
||||
/**
|
||||
* filter
|
||||
*
|
||||
@@ -28,7 +33,7 @@ class filter
|
||||
public static function stripslashes_deep($value)
|
||||
{
|
||||
return is_array($value) ?
|
||||
array_map('filter::stripslashes_deep', $value) :
|
||||
array_map('PrivateBin\\filter::stripslashes_deep', $value) :
|
||||
stripslashes($value);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
/**
|
||||
* i18n
|
||||
*
|
||||
@@ -82,7 +84,7 @@ class i18n
|
||||
*/
|
||||
public static function _($messageId)
|
||||
{
|
||||
return call_user_func_array(array('i18n', 'translate'), func_get_args());
|
||||
return call_user_func_array(array('self', 'translate'), func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
use PrivateBin\model\paste;
|
||||
|
||||
/**
|
||||
* model
|
||||
*
|
||||
@@ -50,7 +54,7 @@ class model
|
||||
*/
|
||||
public function getPaste($pasteId = null)
|
||||
{
|
||||
$paste = new model_paste($this->_conf, $this->_getStore());
|
||||
$paste = new paste($this->_conf, $this->_getStore());
|
||||
if ($pasteId !== null) $paste->setId($pasteId);
|
||||
return $paste;
|
||||
}
|
||||
@@ -76,10 +80,18 @@ class model
|
||||
*/
|
||||
private function _getStore()
|
||||
{
|
||||
// FIXME
|
||||
// Workaround so that config value don't need to be changed
|
||||
$callable = str_replace(
|
||||
array('privatebin_data', 'privatebin_db'),
|
||||
array('PrivateBin\\data\\data', 'PrivateBin\\data\\db'),
|
||||
$this->_conf->getKey('class', 'model')
|
||||
);
|
||||
|
||||
if ($this->_store === null)
|
||||
{
|
||||
$this->_store = forward_static_call(
|
||||
array($this->_conf->getKey('class', 'model'), 'getInstance'),
|
||||
array($callable, 'getInstance'),
|
||||
$this->_conf->getSection('model_options')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,12 +10,20 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin\Model;
|
||||
|
||||
use Exception;
|
||||
use PrivateBin\configuration;
|
||||
use PrivateBin\data\AbstractData;
|
||||
use PrivateBin\sjcl;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* model_abstract
|
||||
*
|
||||
* Abstract model for PrivateBin objects.
|
||||
*/
|
||||
abstract class model_abstract
|
||||
abstract class AbstractModel
|
||||
{
|
||||
/**
|
||||
* Instance ID.
|
||||
@@ -57,7 +65,7 @@ abstract class model_abstract
|
||||
* @param privatebin_abstract $storage
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(configuration $configuration, privatebin_abstract $storage)
|
||||
public function __construct(configuration $configuration, AbstractData $storage)
|
||||
{
|
||||
$this->_conf = $configuration;
|
||||
$this->_store = $storage;
|
||||
@@ -10,12 +10,19 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin\model;
|
||||
|
||||
use Exception;
|
||||
use PrivateBin\sjcl;
|
||||
use PrivateBin\trafficlimiter;
|
||||
use PrivateBin\vizhash16x16;
|
||||
|
||||
/**
|
||||
* model_comment
|
||||
*
|
||||
* Model of a PrivateBin comment.
|
||||
*/
|
||||
class model_comment extends model_abstract
|
||||
class comment extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* Instance's parent.
|
||||
@@ -118,7 +125,7 @@ class model_comment extends model_abstract
|
||||
* @throws Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setPaste(model_paste $paste)
|
||||
public function setPaste(paste $paste)
|
||||
{
|
||||
$this->_paste = $paste;
|
||||
$this->_data->meta->pasteid = $paste->getId();
|
||||
|
||||
@@ -10,12 +10,19 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin\model;
|
||||
|
||||
use Exception;
|
||||
use PrivateBin\privatebin;
|
||||
use PrivateBin\serversalt;
|
||||
use PrivateBin\sjcl;
|
||||
|
||||
/**
|
||||
* model_paste
|
||||
*
|
||||
* Model of a PrivateBin paste.
|
||||
*/
|
||||
class model_paste extends model_abstract
|
||||
class paste extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* Get paste data.
|
||||
@@ -130,7 +137,7 @@ class model_paste extends model_abstract
|
||||
{
|
||||
throw new Exception('Invalid data.', 62);
|
||||
}
|
||||
$comment = new model_comment($this->_conf, $this->_store);
|
||||
$comment = new comment($this->_conf, $this->_store);
|
||||
$comment->setPaste($this);
|
||||
$comment->setParentId($parentId);
|
||||
if ($commentId !== null) $comment->setId($commentId);
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* persistence
|
||||
*
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* privatebin
|
||||
*
|
||||
@@ -419,7 +423,7 @@ class privatebin
|
||||
}
|
||||
|
||||
// translate all the formatter options
|
||||
$formatters = array_map(array('i18n', 'translate'), $this->_conf->getSection('formatter_options'));
|
||||
$formatters = array_map(array('PrivateBin\\i18n', 'translate'), $this->_conf->getSection('formatter_options'));
|
||||
|
||||
// set language cookie if that functionality was enabled
|
||||
$languageselection = '';
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
/**
|
||||
* purgelimiter
|
||||
*
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
/**
|
||||
* request
|
||||
*
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* serversalt
|
||||
*
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
/**
|
||||
* sjcl
|
||||
*
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
/**
|
||||
* trafficlimiter
|
||||
*
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
* @version 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* view
|
||||
*
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
* @version 0.0.4 beta PrivateBin 0.22
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
/**
|
||||
* vizhash16x16
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user