Skip to content

Commit

Permalink
wip (#36356)
Browse files Browse the repository at this point in the history
  • Loading branch information
crnkovic authored Feb 23, 2021
1 parent 663f7e7 commit 11d7c7e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/View/Compilers/Concerns/CompilesInjections.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ trait CompilesInjections
*/
protected function compileInject($expression)
{
$segments = explode(',', preg_replace("/[\(\)\\\"\']/", '', $expression));
$segments = explode(',', preg_replace("/[\(\)]/", '', $expression));

$variable = trim($segments[0]);
$variable = trim($segments[0], " '\"");

$service = trim($segments[1]);

return "<?php \${$variable} = app('{$service}'); ?>";
return "<?php \${$variable} = app({$service}); ?>";
}
}
34 changes: 34 additions & 0 deletions tests/View/Blade/BladeInjectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Illuminate\Tests\View\Blade;

class BladeInjectTest extends AbstractBladeTestCase
{
public function testDependenciesInjectedAsStringsAreCompiled()
{
$string = "Foo @inject('baz', 'SomeNamespace\SomeClass') bar";
$expected = "Foo <?php \$baz = app('SomeNamespace\SomeClass'); ?> bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testDependenciesInjectedAsStringsAreCompiledWhenInjectedWithDoubleQuotes()
{
$string = 'Foo @inject("baz", "SomeNamespace\SomeClass") bar';
$expected = 'Foo <?php $baz = app("SomeNamespace\SomeClass"); ?> bar';
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testDependenciesAreCompiled()
{
$string = "Foo @inject('baz', SomeNamespace\SomeClass::class) bar";
$expected = "Foo <?php \$baz = app(SomeNamespace\SomeClass::class); ?> bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testDependenciesAreCompiledWithDoubleQuotes()
{
$string = 'Foo @inject("baz", SomeNamespace\SomeClass::class) bar';
$expected = "Foo <?php \$baz = app(SomeNamespace\SomeClass::class); ?> bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
}
}

0 comments on commit 11d7c7e

Please sign in to comment.