mirror of
https://github.com/e107inc/e107.git
synced 2025-08-21 05:41:58 +02:00
e_file_inspector_json_phar: Smaller core image
e_file_inspector_json_phar is an extended implementation of e_file_inspector_json that encapsulates a JSON core image into a gzip-compressed phar. This results in space savings of over 60% compared to plain JSON.
This commit is contained in:
@@ -193,7 +193,7 @@ class e107
|
||||
'e_bb_base' => '{e_HANDLER}bbcode_handler.php',
|
||||
'e_customfields' => '{e_HANDLER}e_customfields_class.php',
|
||||
'e_file' => '{e_HANDLER}file_class.php',
|
||||
'e_file_inspector' => '{e_HANDLER}e_file_inspector_json.php',
|
||||
'e_file_inspector' => '{e_HANDLER}e_file_inspector_json_phar.php',
|
||||
'e_form' => '{e_HANDLER}form_handler.php',
|
||||
'e_jshelper' => '{e_HANDLER}js_helper.php',
|
||||
'e_media' => '{e_HANDLER}media_class.php',
|
||||
|
@@ -11,7 +11,7 @@ require_once("e_file_inspector.php");
|
||||
|
||||
class e_file_inspector_json extends e_file_inspector
|
||||
{
|
||||
private $coreImage;
|
||||
protected $coreImage;
|
||||
|
||||
/**
|
||||
* @param $jsonFilePath string Absolute path to the file inspector database
|
||||
@@ -72,7 +72,7 @@ class e_file_inspector_json extends e_file_inspector
|
||||
* @copyright Copyright (c) Taylor Otwell
|
||||
* @license https://github.com/illuminate/support/blob/master/LICENSE.md MIT License
|
||||
*/
|
||||
private static function array_slash($array, $prepend = '')
|
||||
protected static function array_slash($array, $prepend = '')
|
||||
{
|
||||
$results = array();
|
||||
|
||||
|
53
e107_handlers/e_file_inspector_json_phar.php
Normal file
53
e107_handlers/e_file_inspector_json_phar.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) 2008-2020 e107 Inc (e107.org)
|
||||
* Released under the terms and conditions of the
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
*/
|
||||
|
||||
require_once("e_file_inspector_json.php");
|
||||
|
||||
class e_file_inspector_json_phar extends e_file_inspector_json
|
||||
{
|
||||
/**
|
||||
* @param $jsonPharFilePath string Absolute path to the file inspector database
|
||||
*/
|
||||
public function __construct($jsonPharFilePath = null)
|
||||
{
|
||||
parent::__construct($jsonPharFilePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function loadDatabase()
|
||||
{
|
||||
Phar::loadPhar($this->database, "core_image.phar");
|
||||
$tmpFile = tmpfile();
|
||||
$tmpFilePath = stream_get_meta_data($tmpFile)['uri'];
|
||||
$this->copyUrlToResource("phar://core_image.phar/core_image.json", $tmpFile);
|
||||
$this->coreImage = json_decode(file_get_contents($tmpFilePath), true);
|
||||
if (!is_array($this->coreImage)) $this->coreImage = [];
|
||||
$this->coreImage = self::array_slash($this->coreImage);
|
||||
if (!$this->coreImage) $this->coreImage = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy file to destination with low memory footprint
|
||||
* @param $source string URL of the source
|
||||
* @param $destination resource File pointer of the destination
|
||||
*/
|
||||
private function copyUrlToResource($source, $destination)
|
||||
{
|
||||
$dbFile = fopen($source, "r");
|
||||
while (!feof($dbFile))
|
||||
{
|
||||
$buffer = fread($dbFile, 4096);
|
||||
fwrite($destination, $buffer);
|
||||
}
|
||||
unset($buffer);
|
||||
fclose($dbFile);
|
||||
}
|
||||
}
|
@@ -89,7 +89,6 @@ class e_file_inspector_sqlphar extends e_file_inspector
|
||||
return $this->currentVersion = $statement->fetchColumn();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy file to destination with low memory footprint
|
||||
* @param $source string URL of the source
|
||||
|
Reference in New Issue
Block a user