Skip to content
This repository was archived by the owner on May 5, 2019. It is now read-only.

Commit 1c2ebd5

Browse files
committed
Options no longer uses ArrayAccess
1 parent 0c3eba3 commit 1c2ebd5

10 files changed

+48
-52
lines changed

Diff for: .gdbinit

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file ~/.phpenv/versions/5.6.18/bin/php
2+
set args \
3+
-c $PWD/php.ini \
4+
-d "extension=$PWD/../php-handlebars/modules/handlebars.so" \
5+
-n ./vendor/bin/phpunit $*

Diff for: generate-tests.php

+18-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@
33

44
require __DIR__ . '/vendor/autoload.php';
55

6-
$specialSuites = array('parser', 'tokenizer', 'delimiters', '~lambdas');
7-
6+
// Process arguments
7+
$options = array_merge(array(
8+
'handlebars-spec' => __DIR__ . '/vendor/jbboehr/handlebars-spec/',
9+
'mustache-spec' => __DIR__ . '/vendor/jbboehr/mustache-spec/',
10+
), getopt('', array(
11+
'handlebars-spec:',
12+
'mustache-spec',
13+
'help'
14+
)));
815

16+
if( isset($options['help']) ) {
17+
echo "Usage: generate-tests.php [--handlebars-spec <path>] [--mustache-spec <path>]\n";
18+
exit(0);
19+
}
20+
$handlebarsSpecDir = $options['handlebars-spec'];
21+
$mustacheSpecDir = $options['mustache-spec'];
22+
$specialSuites = array('parser', 'tokenizer', 'delimiters', '~lambdas');
923

1024
// List files
11-
$exportDir = __DIR__ . '/vendor/jbboehr/handlebars-spec/export/';
25+
$exportDir = $handlebarsSpecDir . '/export/';
1226
$exportFiles = array();
1327
foreach( scandir($exportDir) as $file ) {
1428
if( $file[0] === '.' || substr($file, -5) !== '.json' ) {
@@ -52,7 +66,7 @@
5266

5367

5468
// Mustache tests
55-
$mustacheDir = __DIR__ . '/vendor/jbboehr/mustache-spec/specs/';
69+
$mustacheDir = $mustacheSpecDir . '/specs/';
5670
$mustacheFiles = array();
5771
foreach( scandir($mustacheDir) as $file ) {
5872
if( $file[0] === '.' || substr($file, -5) !== '.json' ) {

Diff for: src/Registry/DefaultRegistry.php renamed to src/DefaultRegistry.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Handlebars\Registry;
3+
namespace Handlebars;
44

55
use ArrayObject;
66

Diff for: src/Helper/BlockHelperMissing.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public function __invoke($context, $runtime, $options)
3232
} else {
3333
$tmpOptions = $options;
3434
if( $options->data !== null && $options->ids !== null ) {
35-
$data = Utils::createFrame($options['data']);
36-
$data['contextPath'] = Utils::appendContextPath($options['data'], $options['name']);
35+
$data = Utils::createFrame($options->data);
36+
$data['contextPath'] = Utils::appendContextPath($options->data, $options->name);
3737
$options = array('data' => $data);
3838
}
3939
$fn = $tmpOptions->fn;

Diff for: src/Helper/Each.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __invoke($context, $options = null)
2323

2424
$contextPath = null;
2525
if( $options->data !== null && $options->ids !== null ) {
26-
$contextPath = Utils::appendContextPath($options['data'], $options->ids[0]) . '.';
26+
$contextPath = Utils::appendContextPath($options->data, $options->ids[0]) . '.';
2727
}
2828

2929
if( Utils::isCallable($context) ) {

Diff for: src/Helper/With.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public function __invoke($context, $options)
2020
}
2121
if( $context !== null ) { // An empty object is true in javascript...
2222
$fn = $options->fn;
23-
$data = $options['data'];
23+
$data = $options->data;
2424
if( $options->data !== null && $options->ids !== null ) {
25-
$data = Utils::createFrame($options['data']);
26-
$data['contextPath'] = Utils::appendContextPath($options['data'], $options['ids'][0]);
25+
$data = Utils::createFrame($options->data);
26+
$data['contextPath'] = Utils::appendContextPath($options->data, $options->ids[0]);
2727
}
2828
return $fn($context, array(
2929
'data' => $data,

Diff for: src/Registry/Registry.php renamed to src/Registry.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Handlebars\Registry;
3+
namespace Handlebars;
44

55
use ArrayAccess;
66
use IteratorAggregate;

Diff for: src/Runtime.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,7 @@ private function wrapProgram($fn, $data = null, $declaredBlockParams = null, $bl
339339
if( !$options ) {
340340
$options = array();
341341
}
342-
if( isset($options['data']) ) {
343-
$data = $options['data'];
344-
}
342+
$data = Utils::nameLookup($options, 'data');
345343
if( null !== $blockParams ) {
346344
$blockParams = array_merge(array(
347345
Utils::nameLookup($options, 'blockParams'),

Diff for: src/VM/VM.php

+16-15
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ public function executeProgramByRef(CompileContext $program, $context = null, $o
212212
$frame->context = $context;
213213

214214
// Set internal options
215-
if( !empty($options['internal']) ) {
216-
$frame->internal = $options['internal'];
217-
}
215+
$frame->internal = Utils::nameLookup($options, 'internal');
218216

219217
// Push depths
220218
$pushedDepths = false;
@@ -224,13 +222,16 @@ public function executeProgramByRef(CompileContext $program, $context = null, $o
224222
}
225223

226224
// Set data
227-
$frame->data = isset($options['data']) && $options['data'] !== true ? $options['data'] :
228-
($parentFrame ? $parentFrame->data : null);
225+
if( null !== ($data = Utils::nameLookup($options, 'data')) && $data !== true ) {
226+
$frame->data = $data;
227+
} else if( $parentFrame ) {
228+
$frame->data = $parentFrame->data;
229+
}
229230

230231
// Set block params
231232
$pushedBlockParams = false;
232-
if( isset($options['blockParams']) ) {
233-
$this->blockParamStack->push($options['blockParams']);
233+
if( null !== ($bp = Utils::nameLookup($options, 'blockParams')) ) {
234+
$this->blockParamStack->push($bp);
234235
$pushedBlockParams = true;
235236
}
236237

@@ -802,25 +803,25 @@ private function invokePartial($isDynamic, $name, $indent)
802803

803804
if( $isDynamic ) {
804805
$name = $this->pop();
805-
unset($options['name']);
806+
unset($options->name);
806807
}
807808
$params[] = $options;
808809

809810

810811
$context = $params[0];
811-
$hash = !empty($options['hash']) ? $options['hash'] : null;
812+
$hash = Utils::nameLookup($options, 'hash');
812813

813814
if( is_array($hash) ) {
814-
$context = $context ? array_merge($context, $hash) : $hash;
815+
$context = $context ? array_merge((array) $context, $hash) : $hash;
815816
$hash = null;
816817
}
817818

818819
//$options['name'] = $name;
819-
$options['helpers'] = $this->runtime->getHelpers();
820-
$options['partials'] = $this->runtime->getPartials();
821-
$options['decorators'] = $this->runtime->getDecorators();
822-
$options['depths'] = $this->depths;
823-
$options['blockParams'] = $this->blockParamStack;
820+
$options->helpers = $this->runtime->getHelpers();
821+
$options->partials = $this->runtime->getPartials();
822+
$options->decorators = $this->runtime->getDecorators();
823+
$options->depths = $this->depths;
824+
$options->blockParams = $this->blockParamStack;
824825

825826
if( !$isDynamic ) {
826827
$partial = $this->runtime->nameLookup($this->partials, $name);

Diff for: tests/OptionsTest.php

-22
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,4 @@ public function testInverseWithoutFunction()
4444
$options = new Options();
4545
$options->inverse();
4646
}
47-
48-
public function testOffsetGetWithMissingOffset()
49-
{
50-
$options = new Options();
51-
$this->assertEmpty($options['undefinedOffset']);
52-
}
53-
54-
public function testOffsetSet()
55-
{
56-
$options = new Options();
57-
$options['undefinedOffset'] = 'value';
58-
$this->assertEquals('value', $options->undefinedOffset);
59-
}
60-
61-
public function testOffsetUnset()
62-
{
63-
$options = new Options();
64-
$options['undefinedOffset'] = 'value';
65-
unset($options['undefinedOffset']);
66-
$this->assertEmpty($options['undefinedOffset']);
67-
$this->assertTrue(!isset($options->undefinedOffset));
68-
}
6947
}

0 commit comments

Comments
 (0)