Skip to content

Commit

Permalink
Make Template::load static.
Browse files Browse the repository at this point in the history
Execution will be shorter and is still compatible with previous
versions.
  • Loading branch information
rsur committed Jun 16, 2019
1 parent e7e3193 commit 28054f2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
9 changes: 3 additions & 6 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ WARN_LOGFILE =
#---------------------------------------------------------------------------
# Configuration options related to the input files
#---------------------------------------------------------------------------
INPUT =
INPUT = src README.md
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.php
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = */vendor/* \
*/tests/*
EXCLUDE_PATTERNS =
EXCLUDE_SYMBOLS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
Expand All @@ -118,7 +117,7 @@ INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
FILTER_SOURCE_PATTERNS =
USE_MDFILE_AS_MAINPAGE =
USE_MDFILE_AS_MAINPAGE = README.md
#---------------------------------------------------------------------------
# Configuration options related to source browsing
#---------------------------------------------------------------------------
Expand All @@ -131,8 +130,6 @@ REFERENCES_LINK_SOURCE = YES
SOURCE_TOOLTIPS = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
CLANG_ASSISTED_PARSING = NO
CLANG_OPTIONS =
#---------------------------------------------------------------------------
# Configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ class Filter {
}
}

(new Template())->load('template.php',
[
Template::load('template.php', [
'group' => "Extraordinary Gents",
'members' => [
'Allan Quatermain',
'Henry Jekyll',
],
], [
[(new Filter()), 'whoami'],
[(new Filter), 'whoami'],
]
);
```
Expand Down
15 changes: 11 additions & 4 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@

namespace BFITech\ZapTemplate;


/**
* Template class.
*/
class Template {

/**
* Constructor.
*/
public function __construct() {
# nothing to be done
}
Expand Down Expand Up @@ -52,22 +59,22 @@ public function __construct() {
* }
* }
*
* (new Template())->load('template.php',
* Template::load('template.php',
* [
* 'group' => "Extraordinary Gents",
* 'members' => [
* 'Allan Quatermain',
* 'Henry Jekyll',
* ],
* ], [
* [(new Filter()), 'whoami']
* [(new Filter), 'whoami']
* ]
* );
*
* @endcode
*/
public function load(
$template, $args=[], $filter_args=[], $buffered=null
public static function load(
$template, $args=[], $filter_args=[], $buffered=false
) {

if ($buffered)
Expand Down
21 changes: 6 additions & 15 deletions tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,14 @@ public static function filter_array($val) {

class TemplateTest extends TestCase {

public static $prc;
public static $tpl;
public static $args;

public static function setupBeforeClass() {
self::$prc = new Template();
self::$tpl = __DIR__ . '/index.php';
self::$args = [
'test_string' => 'Test String',
'test_array' => [
1,
'a',
],
'test_array' => [1, 'a'],
];
}

Expand All @@ -60,28 +55,24 @@ private function compare($rendered) {
}

public function test_constructor() {
$prc = new Template();
# the only method available
# @todo Should we make this whole thing static?
$this->assertTrue(
method_exists($prc, 'load'));
$this->assertTrue(method_exists((new Template()), 'load'));
}

public function test_print() {
ob_start();
self::$prc->load(self::$tpl, self::$args);
Template::load(self::$tpl, self::$args);
$rv = ob_get_clean();
$this->compare($rv);
}

public function test_buffered() {
$rv = self::$prc->load(self::$tpl, self::$args, [], true);
$rv = Template::load(self::$tpl, self::$args, [], true);
$this->compare($rv);
}

public function test_filtered() {
$filter = new Filter();
$rv = self::$prc->load(self::$tpl, self::$args, [
$filter = new Filter;
$rv = Template::load(self::$tpl, self::$args, [
[$filter, 'filter_string'],
[$filter, 'filter_array'],
], true);
Expand Down

0 comments on commit 28054f2

Please sign in to comment.