5 Commits
1.0.7 ... 1.0.8

5 changed files with 57 additions and 35 deletions

View File

@ -36,6 +36,16 @@ class Components {
self::$components[ $name ] = $value;
return true;
}
public static function setIfNull( $name, $value = '' ) {
if ( ! empty( self::$components[ $name ] ) ) {
return;
}
if ( null == $value ) {
$value = '';
}
self::$components[ $name ] = $value;
return true;
}
public static function unset( $name ) {
if ( isset( self::$components[ $name ] ) ) {
unset( self::$components[ $name ] );

View File

@ -48,7 +48,20 @@ class Filters {
}
foreach ( self::$filters as $pattern ) {
if ( $pattern['enabled'] || false !== $force ) {
$data = trim( preg_replace( $pattern['match'], $pattern['replace'], $data ) );
if ( ! empty( $pattern['callback'] ) && is_array( $pattern['callback'] ) ) {
$result = preg_replace_callback(
$pattern['match'],
$pattern['callback'],
$data
);
} else {
$result = preg_replace(
$pattern['match'],
$pattern['replace'],
$data
);
}
$data = trim( $result );
}
}
return $data;
@ -59,13 +72,20 @@ class Filters {
return $data;
}
if ( self::$filters[$name]['enabled'] || false !== $force ) {
$data = trim(
preg_replace(
if ( ! empty( self::$filters[$name]['callback'] ) && is_array( self::$filters[$name]['callback'] ) ) {
$result = preg_replace_callback(
self::$filters[$name]['match'],
self::$filters[$name]['callback'],
$data
);
} else {
$result = preg_replace(
self::$filters[$name]['match'],
self::$filters[$name]['replace'],
$data
)
);
);
}
$data = trim( $result );
}
return $data;
}
@ -78,12 +98,21 @@ class Filters {
* @param {string} [$replace]
* @param {bool} [$enabled] - Whether the filter should be enabled or disabled.
*/
public static function add( $filterName, $match, $replace, $enabled = false ) {
public static function add( $filterName, $match, $replace, $enabled = false, $callback = false ) {
if ( isset( self::$filters[$filterName] ) ) {
Debug::error( "Filter already exists: $filterName" );
return;
}
self::$filters[$filterName] = [
if ( $callback === true ) {
self::$filters[ $filterName ] = [
'name' => $filterName,
'match' => $match,
'callback' => $replace,
'enabled' => $enabled,
];
return;
}
self::$filters[ $filterName ] = [
'name' => $filterName,
'match' => $match,
'replace' => $replace,

View File

@ -15,9 +15,8 @@
namespace TheTempusProject\Houdini\Classes;
use TheTempusProject\Canary\Bin\Canary as Debug;
use TheTempusProject\Canary\Classes\CustomException;
use TheTempusProject\Hermes\Functions\Route as Routes;
// use TheTempusProject\Bedrock\Functions\Date;
// use TheTempusProject\Bedrock\Classes\CustomException;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Houdini\Classes\Forms;
use TheTempusProject\Houdini\Classes\Filters;
@ -108,7 +107,7 @@ class Template {
return self::loadTemplate( $location, $name );
}
}
// new CustomException( 'template', $docLocation );
new CustomException( 'template', $docLocation );
}
/**
@ -126,7 +125,7 @@ class Template {
$fullPath = $path . $name . '.inc.php';
$className = APP_SPACE . '\\Templates\\' . ucfirst( $name ) . 'Loader';
if ( !file_exists( $fullPath ) ) {
// new CustomException( 'templateLoader', $fullPath );
new CustomException( 'templateLoader', $fullPath );
} else {
Debug::log( 'Requiring template loader: ' . $name );
require_once $fullPath;
@ -202,7 +201,7 @@ class Template {
self::buildRobot();
self::buildHeaders();
if ( empty( self::$templateLocation ) ) {
// throw an error here @todo
new CustomException( 'templateLocation', self::$templateLocation );
return;
}
if ( !Debug::status( 'render' ) ) {
@ -315,7 +314,6 @@ class Template {
* be used as components for the provided html.
* @return string - The fully parsed html output.
*/
public static function parse( $template, $data = null, $flags = null ) {
if ( empty( $template ) ) {
return $template;
@ -330,22 +328,6 @@ class Template {
$template = preg_replace( '#\{OPTION\=(.*?)\}#is', '', $template );
}
//Convert any dates into preferred Date/Time format. User preference will be applied her in the future.
// @todo - there must be something to migrate this ability from the top to the bottom when a user has a pref
$dtc = '#{DTC(.*?)}(.*?){/DTC}#is';
$template = preg_replace_callback(
$dtc,
function ( $data ) {
if ( empty( $data[2] ) ) {
return '';
}
return $data[2]; // @todo need a way to decouple this from houdini to bedrock
// return Date::formatTimestamp( $data[1], $data[2] );
},
$template
);
//Run through our full list of generated filters.
$template = Filters::apply( $template );

View File

@ -12,6 +12,7 @@
namespace TheTempusProject\Houdini\Classes;
use TheTempusProject\Canary\Bin\Canary as Debug;
use TheTempusProject\Canary\Classes\CustomException;
class Views extends Template {
public static $additionalLocations = [];
@ -34,7 +35,7 @@ class Views extends Template {
if ( !empty( $out ) ) {
self::$content .= $out;
} else {
// new CustomException( 'view', $viewName );
new CustomException( 'view', $viewName );
}
}
@ -96,7 +97,7 @@ class Views extends Template {
}
}
// @todo - this would be awesome, if i actually caught the exception anywhere :/
// throw new CustomException('simpleView', $path);
new CustomException('simpleView', $path);
return false;
}

8
composer.lock generated
View File

@ -12,7 +12,7 @@
"source": {
"type": "git",
"url": "https://git.thetempusproject.com/the-tempus-project/canary",
"reference": "7ce988fbd95c0d9b975e7647f2e4d7ee3d5e3aad"
"reference": "35415fbf3c5888ccdb8a8695989176a120026c7f"
},
"require": {
"php": ">=8.1.0"
@ -48,7 +48,7 @@
"thetempusproject",
"tools"
],
"time": "2024-08-10T18:58:57+00:00"
"time": "2024-08-20T10:26:09+00:00"
},
{
"name": "thetempusproject/hermes",
@ -56,7 +56,7 @@
"source": {
"type": "git",
"url": "https://git.thetempusproject.com/the-tempus-project/hermes",
"reference": "171183c0abdbbdf12b3b577821636dd1c51ec752"
"reference": "31c51c1a5bad2871df800c89f27ace0a49848583"
},
"require": {
"php": ">=8.1.0"
@ -92,7 +92,7 @@
"thetempusproject",
"tools"
],
"time": "2024-08-13T02:56:27+00:00"
"time": "2024-08-20T10:26:47+00:00"
}
],
"packages-dev": [],