Skip to content

Commit

Permalink
wrapping mustache engine to suppress deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardTMiles committed Jun 20, 2024
1 parent 48540c2 commit 9c649ea
Show file tree
Hide file tree
Showing 25 changed files with 163 additions and 151 deletions.
5 changes: 3 additions & 2 deletions carbonphp/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use CarbonPHP\Error\PrivateAlert;
use CarbonPHP\Error\PublicAlert;
use CarbonPHP\Extras\MustacheEngine;

/**
* Class View
Expand Down Expand Up @@ -85,7 +86,7 @@ public static function content(string $file, string|null $directoryContext = nul

if (pathinfo($file, PATHINFO_EXTENSION) === 'hbs') {

$mustache = new \Mustache_Engine;
$mustache = new MustacheEngine;

if (CarbonPHP::$socket || (!self::$forceWrapper && CarbonPHP::$pjax && CarbonPHP::$ajax)) { // Send JSON To Socket

Expand Down Expand Up @@ -116,7 +117,7 @@ public static function content(string $file, string|null $directoryContext = nul
#################### Send the Outer Wrapper
} else if (pathinfo(self::$wrapper, PATHINFO_EXTENSION) === 'hbs') { // Outer Wrapper is Mustache
$json['content'] = $buffer;
$mustache = $mustache ?? new \Mustache_Engine;
$mustache = $mustache ?? new MustacheEngine;
print $mustache->render(file_get_contents(self::$wrapper), $json);
} else { // Outer Wrapper is PHP?
self::$bufferedContent = $buffer;
Expand Down
62 changes: 0 additions & 62 deletions carbonphp/abstracts/Swagger.php

This file was deleted.

4 changes: 2 additions & 2 deletions carbonphp/error/ThrowableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use CarbonPHP\CarbonPHP;
use CarbonPHP\Database;
use CarbonPHP\Enums\ThrowableReportDisplay;
use CarbonPHP\Extras\MustacheEngine;
use CarbonPHP\Interfaces\iColorCode;
use CarbonPHP\Rest;
use CarbonPHP\Tables\Reports;
use Mustache_Engine;
use PDOException;
use ReflectionException;
use ReflectionMethod;
Expand Down Expand Up @@ -1164,7 +1164,7 @@ protected static function errorTemplate(array $message, int $code = 200): string

// @note if the Mustache_Engine fails, then tries to re-load itsself the message will say "Class "Mustache_Engine" not found"
// This is very deceptive as the class is found, but failing to be loaded via compile time error. E_DEPRECATED is the first sign
$return = (new Mustache_Engine)->render(self::$errorTemplate, $mustacheInfo);
$return = (new MustacheEngine)->render(self::$errorTemplate, $mustacheInfo);

self::start();

Expand Down
59 changes: 59 additions & 0 deletions carbonphp/extras/MustacheEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace CarbonPHP\Extras;

use CarbonPHP\Error\ThrowableHandler;
use Mustache_Engine;
use Throwable;

class MustacheEngine extends Mustache_Engine
{
public function __construct(array $options = [])
{
try {

ThrowableHandler::stop();

error_reporting(ThrowableHandler::$level ^ (E_NOTICE | E_WARNING | E_DEPRECATED));

// @note if the Mustache_Engine fails, then tries to re-load itsself the message will say "Class "Mustache_Engine" not found"
// This is very deceptive as the class is found, but failing to be loaded via compile time error. E_DEPRECATED is the first sign
parent::__construct($options);

ThrowableHandler::start();

} catch (Throwable $e) {

sortDump(['Mustache_Engine Failed', $e->getMessage(), $e->getTraceAsString()]);

exit(11);

}
}

public function render($template, $context = array())
{
try {

ThrowableHandler::stop();

error_reporting(ThrowableHandler::$level ^ (E_NOTICE | E_WARNING | E_DEPRECATED));

// @note if the Mustache_Engine fails, then tries to re-load itsself the message will say "Class "Mustache_Engine" not found"
// This is very deceptive as the class is found, but failing to be loaded via compile time error. E_DEPRECATED is the first sign
$result = parent::render($template, $context);

ThrowableHandler::start();

return $result;

} catch (Throwable $e) {

sortDump(['Mustache_Engine Failed', $e->getMessage(), $context]);

exit(11);

}
}
}

3 changes: 2 additions & 1 deletion carbonphp/programs/RestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use CarbonPHP\Error\PrivateAlert;
use CarbonPHP\Error\PublicAlert;
use CarbonPHP\Error\ThrowableHandler;
use CarbonPHP\Extras\MustacheEngine;
use CarbonPHP\Interfaces\iColorCode;
use CarbonPHP\Interfaces\iCommand;
use CarbonPHP\Interfaces\iRest;
Expand Down Expand Up @@ -398,7 +399,7 @@ public function run(array $argv): void
}

// This is our mustache template engine implemented in php, used for rendering user content
$mustache = new \Mustache_Engine;
$mustache = new MustacheEngine;

$verbose and var_dump(MySQL::$mysqldump);

Expand Down
11 changes: 6 additions & 5 deletions carbonphp/tables/Carbons.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,15 @@ public function __construct(array &$return = [])
// typically used to validate the full request, add additional data to the request, and even creating a history log
static fn() => self::disallowPublicAccess(self::class)
],
self::FINISH => [
self::PRE_EXECUTE => [
// the compiled sql is passed to the callback, the statement has not been executed yet
]
],
self::GET => [
self::PREPROCESS => [
static fn() => self::disallowPublicAccess(self::class)
]
],
self::PRE_EXECUTE => []
],
self::POST => [
self::PREPROCESS => [
Expand Down Expand Up @@ -320,7 +321,7 @@ public function __construct(array &$return = [])
* Method validations under the main 'PREPROCESS' key will be run first, while validations specific to
* ( GET | POST | PUT | DELETE )::PREPROCESS will be run directly after.
*
* FINAL::
* PRE_EXECUTE::
* Each method will be passed the final ( & $SQL ), which may be a sub-query, by reference.
* Modifying the SQL string will effect the parent function. This can have disastrous effects.
*
Expand Down Expand Up @@ -354,7 +355,7 @@ public function __construct(array &$return = [])
* Each method will be passed ( POST => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
* POST will BE PASSED NULL.
*
* FINAL::
* PRE_EXECUTE::
* Run directly after method specific [FINAL] callbacks.
* The final, 'final' callback set. After these run rest will return.
* Each method will be passed ( GET => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
Expand Down Expand Up @@ -383,7 +384,7 @@ public function __construct(array &$return = [])
* Each method will be passed ( POST => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
* POST will BE PASSED NULL.
*
* FINAL::
* PRE_EXECUTE::
* Passed the ( & $return )
* Run before any other column validation
*
Expand Down
11 changes: 6 additions & 5 deletions carbonphp/tables/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,15 @@ public function __construct(array &$return = [])
// typically used to validate the full request, add additional data to the request, and even creating a history log
static fn() => self::disallowPublicAccess(self::class)
],
self::FINISH => [
self::PRE_EXECUTE => [
// the compiled sql is passed to the callback, the statement has not been executed yet
]
],
self::GET => [
self::PREPROCESS => [
static fn() => self::disallowPublicAccess(self::class)
]
],
self::PRE_EXECUTE => []
],
self::POST => [
self::PREPROCESS => [
Expand Down Expand Up @@ -298,7 +299,7 @@ public function __construct(array &$return = [])
* Method validations under the main 'PREPROCESS' key will be run first, while validations specific to
* ( GET | POST | PUT | DELETE )::PREPROCESS will be run directly after.
*
* FINAL::
* PRE_EXECUTE::
* Each method will be passed the final ( & $SQL ), which may be a sub-query, by reference.
* Modifying the SQL string will effect the parent function. This can have disastrous effects.
*
Expand Down Expand Up @@ -332,7 +333,7 @@ public function __construct(array &$return = [])
* Each method will be passed ( POST => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
* POST will BE PASSED NULL.
*
* FINAL::
* PRE_EXECUTE::
* Run directly after method specific [FINAL] callbacks.
* The final, 'final' callback set. After these run rest will return.
* Each method will be passed ( GET => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
Expand Down Expand Up @@ -361,7 +362,7 @@ public function __construct(array &$return = [])
* Each method will be passed ( POST => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
* POST will BE PASSED NULL.
*
* FINAL::
* PRE_EXECUTE::
* Passed the ( & $return )
* Run before any other column validation
*
Expand Down
11 changes: 6 additions & 5 deletions carbonphp/tables/Documentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ public function __construct(array &$return = [])
// typically used to validate the full request, add additional data to the request, and even creating a history log
static fn() => self::disallowPublicAccess(self::class)
],
self::FINISH => [
self::PRE_EXECUTE => [
// the compiled sql is passed to the callback, the statement has not been executed yet
]
],
self::GET => [
self::PREPROCESS => [
static fn() => self::disallowPublicAccess(self::class)
]
],
self::PRE_EXECUTE => []
],
self::POST => [
self::PREPROCESS => [
Expand Down Expand Up @@ -294,7 +295,7 @@ public function __construct(array &$return = [])
* Method validations under the main 'PREPROCESS' key will be run first, while validations specific to
* ( GET | POST | PUT | DELETE )::PREPROCESS will be run directly after.
*
* FINAL::
* PRE_EXECUTE::
* Each method will be passed the final ( & $SQL ), which may be a sub-query, by reference.
* Modifying the SQL string will effect the parent function. This can have disastrous effects.
*
Expand Down Expand Up @@ -328,7 +329,7 @@ public function __construct(array &$return = [])
* Each method will be passed ( POST => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
* POST will BE PASSED NULL.
*
* FINAL::
* PRE_EXECUTE::
* Run directly after method specific [FINAL] callbacks.
* The final, 'final' callback set. After these run rest will return.
* Each method will be passed ( GET => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
Expand Down Expand Up @@ -357,7 +358,7 @@ public function __construct(array &$return = [])
* Each method will be passed ( POST => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
* POST will BE PASSED NULL.
*
* FINAL::
* PRE_EXECUTE::
* Passed the ( & $return )
* Run before any other column validation
*
Expand Down
6 changes: 3 additions & 3 deletions carbonphp/tables/Feature_Group_References.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function __construct(array &$return = [])
* Method validations under the main 'PREPROCESS' key will be run first, while validations specific to
* ( GET | POST | PUT | DELETE )::PREPROCESS will be run directly after.
*
* FINAL::
* PRE_EXECUTE::
* Each method will be passed the final ( & $SQL ), which may be a sub-query, by reference.
* Modifying the SQL string will effect the parent function. This can have disastrous effects.
*
Expand Down Expand Up @@ -322,7 +322,7 @@ public function __construct(array &$return = [])
* Each method will be passed ( POST => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
* POST will BE PASSED NULL.
*
* FINAL::
* PRE_EXECUTE::
* Run directly after method specific [FINAL] callbacks.
* The final, 'final' callback set. After these run rest will return.
* Each method will be passed ( GET => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
Expand Down Expand Up @@ -351,7 +351,7 @@ public function __construct(array &$return = [])
* Each method will be passed ( POST => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
* POST will BE PASSED NULL.
*
* FINAL::
* PRE_EXECUTE::
* Passed the ( & $return )
* Run before any other column validation
*
Expand Down
6 changes: 3 additions & 3 deletions carbonphp/tables/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function __construct(array &$return = [])
* Method validations under the main 'PREPROCESS' key will be run first, while validations specific to
* ( GET | POST | PUT | DELETE )::PREPROCESS will be run directly after.
*
* FINAL::
* PRE_EXECUTE::
* Each method will be passed the final ( & $SQL ), which may be a sub-query, by reference.
* Modifying the SQL string will effect the parent function. This can have disastrous effects.
*
Expand Down Expand Up @@ -324,7 +324,7 @@ public function __construct(array &$return = [])
* Each method will be passed ( POST => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
* POST will BE PASSED NULL.
*
* FINAL::
* PRE_EXECUTE::
* Run directly after method specific [FINAL] callbacks.
* The final, 'final' callback set. After these run rest will return.
* Each method will be passed ( GET => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
Expand Down Expand Up @@ -353,7 +353,7 @@ public function __construct(array &$return = [])
* Each method will be passed ( POST => void|&$returnID, DELETE => &$remove, PUT => &$returnUpdated ) by reference.
* POST will BE PASSED NULL.
*
* FINAL::
* PRE_EXECUTE::
* Passed the ( & $return )
* Run before any other column validation
*
Expand Down
Loading

0 comments on commit 9c649ea

Please sign in to comment.