revert scalar type hints to retain support for PHP < 7.0

This commit is contained in:
El RIDO 2019-05-10 21:35:36 +02:00
parent 0f42bd818f
commit 632d70412a
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
4 changed files with 28 additions and 27 deletions

View File

@ -72,7 +72,7 @@ abstract class AbstractData
* @param array $paste * @param array $paste
* @return bool * @return bool
*/ */
abstract public function create(string $pasteid, array $paste); abstract public function create($pasteid, array $paste);
/** /**
* Read a paste. * Read a paste.
@ -81,7 +81,7 @@ abstract class AbstractData
* @param string $pasteid * @param string $pasteid
* @return stdClass|false * @return stdClass|false
*/ */
abstract public function read(string $pasteid); abstract public function read($pasteid);
/** /**
* Delete a paste and its discussion. * Delete a paste and its discussion.
@ -89,7 +89,7 @@ abstract class AbstractData
* @access public * @access public
* @param string $pasteid * @param string $pasteid
*/ */
abstract public function delete(string $pasteid); abstract public function delete($pasteid);
/** /**
* Test if a paste exists. * Test if a paste exists.
@ -98,7 +98,7 @@ abstract class AbstractData
* @param string $pasteid * @param string $pasteid
* @return bool * @return bool
*/ */
abstract public function exists(string $pasteid); abstract public function exists($pasteid);
/** /**
* Create a comment in a paste. * Create a comment in a paste.
@ -110,7 +110,7 @@ abstract class AbstractData
* @param array $comment * @param array $comment
* @return bool * @return bool
*/ */
abstract public function createComment(string $pasteid, string $parentid, string $commentid, array $comment); abstract public function createComment($pasteid, $parentid, $commentid, array $comment);
/** /**
* Read all comments of paste. * Read all comments of paste.
@ -119,7 +119,7 @@ abstract class AbstractData
* @param string $pasteid * @param string $pasteid
* @return array * @return array
*/ */
abstract public function readComments(string $pasteid); abstract public function readComments($pasteid);
/** /**
* Test if a comment exists. * Test if a comment exists.
@ -130,7 +130,7 @@ abstract class AbstractData
* @param string $commentid * @param string $commentid
* @return bool * @return bool
*/ */
abstract public function existsComment(string $pasteid, string $parentid, string $commentid); abstract public function existsComment($pasteid, $parentid, $commentid);
/** /**
* Returns up to batch size number of paste ids that have expired * Returns up to batch size number of paste ids that have expired
@ -139,7 +139,7 @@ abstract class AbstractData
* @param int $batchsize * @param int $batchsize
* @return array * @return array
*/ */
abstract protected function _getExpiredPastes(int $batchsize); abstract protected function _getExpiredPastes($batchsize);
/** /**
* Perform a purge of old pastes, at most the given batchsize is deleted. * Perform a purge of old pastes, at most the given batchsize is deleted.

View File

@ -154,7 +154,7 @@ class Database extends AbstractData
* @param array $paste * @param array $paste
* @return bool * @return bool
*/ */
public function create(string $pasteid, array $paste) public function create($pasteid, array $paste)
{ {
if ( if (
array_key_exists($pasteid, self::$_cache) array_key_exists($pasteid, self::$_cache)
@ -223,7 +223,7 @@ class Database extends AbstractData
* @param string $pasteid * @param string $pasteid
* @return array|false * @return array|false
*/ */
public function read(string $pasteid) public function read($pasteid)
{ {
if (array_key_exists($pasteid, self::$_cache)) { if (array_key_exists($pasteid, self::$_cache)) {
return self::$_cache[$pasteid]; return self::$_cache[$pasteid];
@ -287,7 +287,7 @@ class Database extends AbstractData
* @access public * @access public
* @param string $pasteid * @param string $pasteid
*/ */
public function delete(string $pasteid) public function delete($pasteid)
{ {
self::_exec( self::_exec(
'DELETE FROM ' . self::_sanitizeIdentifier('paste') . 'DELETE FROM ' . self::_sanitizeIdentifier('paste') .
@ -311,7 +311,7 @@ class Database extends AbstractData
* @param string $pasteid * @param string $pasteid
* @return bool * @return bool
*/ */
public function exists(string $pasteid) public function exists($pasteid)
{ {
if ( if (
!array_key_exists($pasteid, self::$_cache) !array_key_exists($pasteid, self::$_cache)
@ -331,7 +331,7 @@ class Database extends AbstractData
* @param array $comment * @param array $comment
* @return bool * @return bool
*/ */
public function createComment(string $pasteid, string $parentid, string $commentid, array $comment) public function createComment($pasteid, $parentid, $commentid, array $comment)
{ {
if (array_key_exists('data', $comment)) { if (array_key_exists('data', $comment)) {
$version = 1; $version = 1;
@ -370,7 +370,7 @@ class Database extends AbstractData
* @param string $pasteid * @param string $pasteid
* @return array * @return array
*/ */
public function readComments(string $pasteid) public function readComments($pasteid)
{ {
$rows = self::_select( $rows = self::_select(
'SELECT * FROM ' . self::_sanitizeIdentifier('comment') . 'SELECT * FROM ' . self::_sanitizeIdentifier('comment') .
@ -414,7 +414,7 @@ class Database extends AbstractData
* @param string $commentid * @param string $commentid
* @return bool * @return bool
*/ */
public function existsComment(string $pasteid, string $parentid, string $commentid) public function existsComment($pasteid, $parentid, $commentid)
{ {
return (bool) self::_select( return (bool) self::_select(
'SELECT dataid FROM ' . self::_sanitizeIdentifier('comment') . 'SELECT dataid FROM ' . self::_sanitizeIdentifier('comment') .
@ -456,7 +456,7 @@ class Database extends AbstractData
* @throws PDOException * @throws PDOException
* @return bool * @return bool
*/ */
private static function _exec(string $sql, array $params) private static function _exec($sql, array $params)
{ {
$statement = self::$_db->prepare($sql); $statement = self::$_db->prepare($sql);
$result = $statement->execute($params); $result = $statement->execute($params);
@ -475,7 +475,7 @@ class Database extends AbstractData
* @throws PDOException * @throws PDOException
* @return array * @return array
*/ */
private static function _select(string $sql, array $params, bool $firstOnly = false) private static function _select($sql, array $params, bool $firstOnly = false)
{ {
$statement = self::$_db->prepare($sql); $statement = self::$_db->prepare($sql);
$statement->execute($params); $statement->execute($params);

View File

@ -29,7 +29,7 @@ class Filesystem extends AbstractData
* @param array $options * @param array $options
* @return Filesystem * @return Filesystem
*/ */
public static function getInstance($options = null) public static function getInstance(array $options)
{ {
// if needed initialize the singleton // if needed initialize the singleton
if (!(self::$_instance instanceof self)) { if (!(self::$_instance instanceof self)) {
@ -53,7 +53,7 @@ class Filesystem extends AbstractData
* @param array $paste * @param array $paste
* @return bool * @return bool
*/ */
public function create($pasteid, $paste) public function create($pasteid, array $paste)
{ {
$storagedir = self::_dataid2path($pasteid); $storagedir = self::_dataid2path($pasteid);
$file = $storagedir . $pasteid . '.php'; $file = $storagedir . $pasteid . '.php';
@ -121,7 +121,7 @@ class Filesystem extends AbstractData
* @param string $pasteid * @param string $pasteid
* @return bool * @return bool
*/ */
public function exists($pasteid) public functio(($pasteid)
{ {
$basePath = self::_dataid2path($pasteid) . $pasteid; $basePath = self::_dataid2path($pasteid) . $pasteid;
$pastePath = $basePath . '.php'; $pastePath = $basePath . '.php';
@ -155,7 +155,7 @@ class Filesystem extends AbstractData
* @param array $comment * @param array $comment
* @return bool * @return bool
*/ */
public function createComment($pasteid, $parentid, $commentid, $comment) public function createComment($pasteid, $parentid, $commentid, array $comment)
{ {
$storagedir = self::_dataid2discussionpath($pasteid); $storagedir = self::_dataid2discussionpath($pasteid);
$file = $storagedir . $pasteid . '.' . $commentid . '.' . $parentid . '.php'; $file = $storagedir . $pasteid . '.' . $commentid . '.' . $parentid . '.php';
@ -230,7 +230,7 @@ class Filesystem extends AbstractData
* @param int $batchsize * @param int $batchsize
* @return array * @return array
*/ */
protected function _getExpiredPastes($batchsize) protected function _getExpiredPastes(int $batchsize)
{ {
$pastes = array(); $pastes = array();
$mainpath = DataStore::getPath(); $mainpath = DataStore::getPath();

View File

@ -3,6 +3,7 @@
use PrivateBin\Persistence\ServerSalt; use PrivateBin\Persistence\ServerSalt;
error_reporting(E_ALL | E_STRICT); error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
// change this, if your php files and data is outside of your webservers document root // change this, if your php files and data is outside of your webservers document root
if (!defined('PUBLIC_PATH')) { if (!defined('PUBLIC_PATH')) {
@ -120,7 +121,7 @@ class Helper
* @param array $meta * @param array $meta
* @return array * @return array
*/ */
public static function getPaste(int $version = 2, array $meta = array()) public static function getPaste($version = 2, array $meta = array())
{ {
$example = self::getPasteWithAttachment($version, $meta); $example = self::getPasteWithAttachment($version, $meta);
// v1 has the attachment stored in a separate property // v1 has the attachment stored in a separate property
@ -137,7 +138,7 @@ class Helper
* @param array $meta * @param array $meta
* @return array * @return array
*/ */
public static function getPasteWithAttachment(int $version = 2, array $meta = array()) public static function getPasteWithAttachment($version = 2, array $meta = array())
{ {
$example = $version === 1 ? self::$pasteV1 : self::$pasteV2; $example = $version === 1 ? self::$pasteV1 : self::$pasteV2;
$example['meta']['salt'] = ServerSalt::generate(); $example['meta']['salt'] = ServerSalt::generate();
@ -152,7 +153,7 @@ class Helper
* @param array $meta * @param array $meta
* @return array * @return array
*/ */
public static function getPastePost(int $version = 2, array $meta = array()) public static function getPastePost($version = 2, array $meta = array())
{ {
$example = self::getPaste($version, $meta); $example = self::getPaste($version, $meta);
$example['meta'] = array('expire' => $example['meta']['expire']); $example['meta'] = array('expire' => $example['meta']['expire']);
@ -165,7 +166,7 @@ class Helper
* @param array $meta * @param array $meta
* @return array * @return array
*/ */
public static function getPastePostJson(int $version = 2, array $meta = array()) public static function getPastePostJson($version = 2, array $meta = array())
{ {
$example = self::getPastePost($version, $meta); $example = self::getPastePost($version, $meta);
$example['adata'] = json_encode($example['adata']); $example['adata'] = json_encode($example['adata']);
@ -190,7 +191,7 @@ class Helper
* @param array $meta * @param array $meta
* @return array * @return array
*/ */
public static function getComment(int $version = 2, array $meta = array()) public static function getComment($version = 2, array $meta = array())
{ {
$example = $version === 1 ? self::$commentV1 : self::$pasteV2; $example = $version === 1 ? self::$commentV1 : self::$pasteV2;
if ($version === 2) { if ($version === 2) {