1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 03:40:37 +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:
Nick Liu
2020-03-23 23:43:52 -05:00
parent b425b4e45d
commit 6f6556178f
9 changed files with 111 additions and 10 deletions

View File

@@ -13,12 +13,20 @@ require_once("CoreImage.php");
class JsonCoreImage extends CoreImage
{
private $checksums = [];
protected $checksums = [];
public function __construct($exportFolder, $tempFolder, $currentVersion, $imageFile)
{
$this->create_image($exportFolder, $tempFolder, $currentVersion);
$this->saveImage($imageFile);
}
/**
* @param $imageFile
*/
protected function saveImage($imageFile)
{
$json_result = json_encode($this->checksums, JSON_PRETTY_PRINT);
$json_string_result = var_export($json_result, true);
$data = $this->generateStub();

View File

@@ -0,0 +1,41 @@
<?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("JsonCoreImage.php");
class JsonPharCoreImage extends JsonCoreImage
{
protected function saveImage($imageFile)
{
$imagePharFile = "$imageFile.phar";
$phar = new Phar($imagePharFile);
$json_result = json_encode($this->checksums);
$imageJsonFile = "$imageFile.json";
$fp = fopen($imageJsonFile, 'w');
fwrite($fp, $json_result);
fclose($fp);
$phar->startBuffering();
$phar->setStub($this->generateStub());
$phar->addFile($imageJsonFile, "core_image.json");
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
rename($imagePharFile, $imageFile);
}
protected function generateStub()
{
$data = parent::generateStub();
$data .= "__HALT_COMPILER();";
return $data;
}
}

View File

@@ -9,7 +9,7 @@
*/
require_once("OsHelper.php");
require_once("JsonCoreImage.php");
require_once("JsonPharCoreImage.php");
$builder = new e107Build();
$builder->makeBuild();
@@ -505,7 +505,7 @@ class e107Build
$imageFile = $this->tempDir . "core_image.php";
$this->status("Creating new core_image.php file ({$imageFile})", true);
new JsonCoreImage($this->exportDir, $this->tempDir, $this->version, $imageFile);
new JsonPharCoreImage($this->exportDir, $this->tempDir, $this->version, $imageFile);
$dir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/export";
$this->changeDir($dir);