Skip to content
This repository has been archived by the owner on Apr 11, 2022. It is now read-only.

Commit

Permalink
PHP 7.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Oct 28, 2020
1 parent 899020b commit 034e106
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ Minimal template configuration:
</mj-section>
</mj-body>
</mjml>
```
```
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
}
],
"require": {
"php": ">=7.1.0"
"php": ">=7.4.0"
},
"require-dev": {
"phpstan/phpstan": "^0.12.18",
"tracy/tracy": "^2.7",
"phpstan/phpstan-nette": "^0.12.6"
"phpstan/phpstan-nette": "^0.12.6",
"symplify/easy-coding-standard": "^7.2"
},
"autoload": {
"classmap": [
Expand Down
38 changes: 3 additions & 35 deletions src/MjmlServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

final class MjmlServer
{

/** @var string */
private $cacheDir;
private string $cacheDir;


public function __construct(?string $cacheDir = null)
Expand Down Expand Up @@ -39,10 +37,6 @@ public function run(): void
}


/**
* @param string $template
* @return string
*/
public function process(string $template): string
{
$templateContentHash = md5($template);
Expand All @@ -65,14 +59,9 @@ public function process(string $template): string
}


/**
* @param string $file
* @return string
*/
private function processReturn(string $file): string
{
$return = str_replace(["\r\n", "\r"], "\n", $this->read($file));

if (preg_match('/Error: ([^\n]+)/', $return, $parser)) {
throw new \RuntimeException($parser[1]);
}
Expand All @@ -81,10 +70,6 @@ private function processReturn(string $file): string
}


/**
* @param string $dir
* @param int $mode
*/
private function createDir(string $dir, int $mode = 0777): void
{
if (!is_dir($dir) && !@mkdir($dir, $mode, true) && !is_dir($dir)) { // @ - dir may already exist
Expand All @@ -93,10 +78,6 @@ private function createDir(string $dir, int $mode = 0777): void
}


/**
* @param string $file
* @return string
*/
private function read(string $file): string
{
$content = @file_get_contents($file); // @ is escalated to exception
Expand All @@ -108,11 +89,6 @@ private function read(string $file): string
}


/**
* @param string $file
* @param string $content
* @param int|null $mode
*/
private function write(string $file, string $content, ?int $mode = 0666): void
{
$this->createDir(dirname($file));
Expand All @@ -125,31 +101,23 @@ private function write(string $file, string $content, ?int $mode = 0666): void
}


/**
* @return string
*/
private function getLastError(): string
{
return preg_replace('#^\w+\(.*?\): #', '', error_get_last()['message']);
}


/**
* @param string $functionName
* @return bool
*/
private function functionIsAvailable(string $functionName): bool
{
static $disabled;

if (\function_exists($functionName)) {
if ($disabled === null && \is_string($disableFunctions = ini_get('disable_functions'))) {
$disabled = explode(',', $disableFunctions) ?: [];
$disabled = explode(',', $disableFunctions);
}

return \in_array($functionName, $disabled, true) === false;
}

return false;
}
}
}

0 comments on commit 034e106

Please sign in to comment.