Skip to content

Commit c8c37c7

Browse files
committed
Drop compileWithoutDependencies and handle catchDependencies as an option
1 parent 9cbc5c6 commit c8c37c7

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

src/JsPhpize/Compiler/Compiler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ protected function visitVariable(Variable $variable, $indent)
267267
public function compile(Block $block, $indent = '')
268268
{
269269
$output = '';
270-
$line = array();
271270

272271
foreach ($block->instructions as $instruction) {
273272
$output .= $this->visitNode($instruction, $indent);

src/JsPhpize/JsPhpize.php

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ class JsPhpize extends JsPhpizeOptions
3838
*
3939
* @param string $input file or content
4040
* @param string $filename if specified, input is used as content and filename as its name
41-
* @param bool $catchDependencies if true, dependencies are not compiled and can be grouped and get separatly
4241
*
4342
* @return string
4443
*/
45-
public function compile($input, $filename = null, $catchDependencies = false)
44+
public function compile($input, $filename = null)
4645
{
4746
if ($filename === null) {
4847
$filename = file_exists($input) ? $input : null;
@@ -54,7 +53,7 @@ public function compile($input, $filename = null, $catchDependencies = false)
5453
$php = $compiler->compile($block);
5554

5655
$dependencies = $compiler->getDependencies();
57-
if ($catchDependencies) {
56+
if ($this->getOption('catchDependencies')) {
5857
$this->dependencies = $dependencies;
5958
$dependencies = array();
6059
}
@@ -67,39 +66,24 @@ public function compile($input, $filename = null, $catchDependencies = false)
6766
* Compile a file.
6867
*
6968
* @param string $file input file
70-
* @param bool $catchDependencies if true, dependencies are not compiled and can be grouped and get separatly
7169
*
7270
* @return string
7371
*/
74-
public function compileFile($file, $catchDependencies = false)
72+
public function compileFile($file)
7573
{
76-
return $this->compile(file_get_contents($file), $file, $catchDependencies);
74+
return $this->compile(file_get_contents($file), $file);
7775
}
7876

7977
/**
8078
* Compile raw code.
8179
*
8280
* @param string $code input code
83-
* @param bool $catchDependencies if true, dependencies are not compiled and can be grouped and get separatly
8481
*
8582
* @return string
8683
*/
87-
public function compileCode($code, $catchDependencies = false)
84+
public function compileCode($code)
8885
{
89-
return $this->compile($code, 'source.js', $catchDependencies);
90-
}
91-
92-
/**
93-
* Compile without the dependencies.
94-
*
95-
* @param string $input file or content
96-
* @param string $filename if specified, input is used as content and filename as its name
97-
*
98-
* @return string
99-
*/
100-
public function compileWithoutDependencies($input, $filename = null)
101-
{
102-
return $this->compile($input, $filename, true);
86+
return $this->compile($code, 'source.js');
10387
}
10488

10589
/**

tests/compile.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public function testJsPhpizeGeneration($phpFile, $jsFile)
3636

3737
public function testCompileWithoutDependencies()
3838
{
39-
$jsPhpize = new JsPhpize();
40-
$result = $jsPhpize->compileWithoutDependencies('4 + 5');
39+
$jsPhpize = new JsPhpize(array(
40+
'catchDependencies' => true,
41+
));
42+
$result = $jsPhpize->compileCode('4 + 5');
4143

4244
$expected = str_replace("\r", '', trim("call_user_func(\$GLOBALS['__jpv_plus'], 4, 5);"));
4345
$actual = str_replace("\r", '', trim($result));

tests/mainMethods.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public function testCompileFile()
2020
$this->assertSame($expected, $actual);
2121
$this->assertSame('', $jsPhpize->compileDependencies());
2222

23-
$actual = $jsPhpize->compileFile(__DIR__ . '/../examples/basic.js', true);
23+
$jsPhpizeCatchDeps = new JsPhpize(array(
24+
'catchDependencies' => true,
25+
));
26+
$actual = $jsPhpizeCatchDeps->compileFile(__DIR__ . '/../examples/basic.js');
2427
$expected = <<<'EOD'
2528
$foo = array( 'bar' => array( "baz" => "hello" ) );
2629
$biz = 'bar';
@@ -30,16 +33,16 @@ public function testCompileFile()
3033
$expected = preg_replace('/\s/', '', $expected);
3134
$this->assertSame($expected, $actual);
3235

33-
$actual = $jsPhpize->compileDependencies();
36+
$actual = $jsPhpizeCatchDeps->compileDependencies();
3437
$expected = '$GLOBALS[\'__jpv_dot\'] = ' . file_get_contents(__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Dot.h') . ';';
3538
$expected .= '$GLOBALS[\'__jpv_plus\'] = ' . file_get_contents(__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Plus.h') . ';';
3639

3740
$actual = preg_replace('/\s/', '', $actual);
3841
$expected = preg_replace('/\s/', '', $expected);
3942
$this->assertSame($expected, $actual);
4043

41-
$jsPhpize->compileFile(__DIR__ . '/../examples/calcul.js', true);
42-
$actual = $jsPhpize->compileDependencies();
44+
$jsPhpizeCatchDeps->compileFile(__DIR__ . '/../examples/calcul.js');
45+
$actual = $jsPhpizeCatchDeps->compileDependencies();
4346
$expected = '$GLOBALS[\'__jpv_plus\'] = ' . file_get_contents(__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Plus.h') . ';';
4447
$actual = preg_replace('/\s/', '', $actual);
4548
$expected = preg_replace('/\s/', '', $expected);

0 commit comments

Comments
 (0)