54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* classes/components.php
|
|
*
|
|
* This class is for managing template components.
|
|
*
|
|
* @version 3.0
|
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
|
* @link https://TheTempusProject.com/Houdini
|
|
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
|
*/
|
|
namespace TheTempusProject\Houdini\Classes;
|
|
|
|
class Components {
|
|
public static $components = [];
|
|
|
|
public static function parse( $data ) {
|
|
foreach ( self::$components as $key => $replace ) {
|
|
$find = "~{($key)}~i";
|
|
$data = preg_replace( $find, $replace, $data );
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Adds a $key->$value combination to the $components array.
|
|
*
|
|
* @param {string} [$key]
|
|
* @param {wild} [$value]
|
|
* @return {bool}
|
|
*/
|
|
public static function set( $name, $value = '' ) {
|
|
if ( null == $value ) {
|
|
$value = '';
|
|
}
|
|
self::$components[ $name ] = $value;
|
|
return true;
|
|
}
|
|
public static function unset( $name ) {
|
|
if ( isset( self::$components[ $name ] ) ) {
|
|
unset( self::$components[ $name ] );
|
|
}
|
|
return true;
|
|
}
|
|
public static function append( $name, $value ) {
|
|
if ( ! isset( self::$components[ $name ] ) ) {
|
|
return self::set( $name, $value );
|
|
}
|
|
$curr = self::$components[ $name ];
|
|
self::$components[ $name ] = $curr . $value;
|
|
return true;
|
|
}
|
|
}
|