-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ashot Gharakeshishyan
committed
Aug 30, 2024
1 parent
b9cf7d3
commit a77244b
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Illuminate\View\Compilers\Concerns; | ||
|
||
trait CompilesLog | ||
{ | ||
/** | ||
* Compile the extends statements into valid PHP. | ||
* | ||
* @param string $expression | ||
* @return string | ||
*/ | ||
public function compileLog(string $expression) | ||
{ | ||
$expression = $this->stripParentheses($expression); | ||
$parts = array_map('trim', explode(',', $expression)); | ||
$message = isset($parts[0]) ? trim($parts[0], "'\"") : ''; | ||
|
||
$method = isset($parts[1]) ? trim($parts[1], "'\"") : 'info'; | ||
$resolvedClass = app()->make('log'); | ||
|
||
if (!method_exists($resolvedClass, $method)) { | ||
$method = 'info'; | ||
} | ||
|
||
return "<?php Log::{$method}('{$message}'); ?>"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Testing; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class BladeLogTest extends TestCase | ||
{ | ||
public function testLogAreCompiled() | ||
{ | ||
$this->assertSame("<?php Log::info('User authenticated.'); ?>", $this->compiler->compileString('@log(\'User authenticated.\')')); | ||
$this->assertSame("<?php Log::error('Error occurred.'); ?>", $this->compiler->compileString('@log(\'Error occurred.\', \'error\')')); | ||
$this->assertSame("<?php Log::debug('Debug occurred.'); ?>", $this->compiler->compileString('@log(\'Debug occurred.\', \'debug\')')); | ||
$this->assertSame("<?php Log::alert('Alert occurred.'); ?>", $this->compiler->compileString('@log(\'Alert occurred.\', \'alert\')')); | ||
$this->assertSame("<?php Log::critical('Critical occurred.'); ?>", $this->compiler->compileString('@log(\'Critical occurred.\', \'critical\')')); | ||
$this->assertSame("<?php Log::notice('Notice occurred.'); ?>", $this->compiler->compileString('@log(\'Notice occurred.\', \'notice\')')); | ||
$this->assertSame("<?php Log::emergency('Emergency occurred.'); ?>", $this->compiler->compileString('@log(\'Emergency occurred.\', \'emergency\')')); | ||
} | ||
} |