-
Notifications
You must be signed in to change notification settings - Fork 98
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
Showing
15 changed files
with
352 additions
and
14 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
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,44 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb\Console\Components; | ||
|
||
use Illuminate\Console\View\Components\Component; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class Message extends Component | ||
{ | ||
/** | ||
* Renders the component using the given arguments. | ||
* | ||
* @param string $first | ||
* @param string|null $second | ||
* @param int $verbosity | ||
* @return void | ||
*/ | ||
public function render($message, $verbosity = OutputInterface::VERBOSITY_NORMAL) | ||
{ | ||
$this->renderView('message', [ | ||
'message' => $message, | ||
], $verbosity); | ||
} | ||
|
||
/** | ||
* Compile the given view contents. | ||
* | ||
* @param string $view | ||
* @param array $data | ||
* @return void | ||
*/ | ||
protected function compile($view, $data) | ||
{ | ||
extract($data); | ||
|
||
ob_start(); | ||
|
||
include __DIR__."/views/$view.php"; | ||
|
||
return tap(ob_get_contents(), function () { | ||
ob_end_clean(); | ||
}); | ||
} | ||
} |
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,5 @@ | ||
<div class="flex mx-1 mb-1"> | ||
<code> | ||
<?php echo htmlspecialchars($message) ?> | ||
</code> | ||
</div> |
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,39 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb\Contracts; | ||
|
||
interface Logger | ||
{ | ||
/** | ||
* Log an infomational message. | ||
* | ||
* @param string $title | ||
* @param string|null $message | ||
* @return void | ||
*/ | ||
public function info(string $title, ?string $message = null): void; | ||
|
||
/** | ||
* Log an error message. | ||
* | ||
* @param string $message | ||
* @return void | ||
*/ | ||
public function error(string $message): void; | ||
|
||
/** | ||
* Append a new line to the log. | ||
* | ||
* @param int $lines | ||
* @return void | ||
*/ | ||
public function line(?int $lines = 1): void; | ||
|
||
/** | ||
* Log a message sent to the server. | ||
* | ||
* @param string $message | ||
* @return void | ||
*/ | ||
public function message(string $message): void; | ||
} |
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,73 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb\Loggers; | ||
|
||
use Illuminate\Console\OutputStyle; | ||
use Illuminate\Console\View\Components\Factory; | ||
use Laravel\Reverb\Console\Components\Message; | ||
use Laravel\Reverb\Contracts\Logger; | ||
|
||
class CliLogger implements Logger | ||
{ | ||
protected $components; | ||
|
||
public function __construct(protected OutputStyle $output) | ||
{ | ||
$this->components = new Factory($output); | ||
} | ||
|
||
/** | ||
* Log an infomational message. | ||
* | ||
* @param string $title | ||
* @param string|null $message | ||
* @return void | ||
*/ | ||
public function info(string $title, ?string $message = null): void | ||
{ | ||
$this->components->twoColumnDetail($title, $message); | ||
} | ||
|
||
/** | ||
* Log an error message. | ||
* | ||
* @param string $message | ||
* @return void | ||
*/ | ||
public function error(string $string): void | ||
{ | ||
$this->output->error($string); | ||
} | ||
|
||
/** | ||
* Append a new line to the log. | ||
* | ||
* @param int $lines | ||
* @return void | ||
*/ | ||
public function line(?int $lines = 1): void | ||
{ | ||
$this->output->newLine($lines); | ||
} | ||
|
||
/** | ||
* Log a message sent to the server. | ||
* | ||
* @param string $message | ||
* @return void | ||
*/ | ||
public function message(string $message): void | ||
{ | ||
$message = json_decode($message, true); | ||
|
||
if (isset($message['data']['channel_data'])) { | ||
$message['data']['channel_data'] = json_decode($message['data']['channel_data'], true); | ||
} | ||
|
||
$message = json_encode($message, JSON_PRETTY_PRINT); | ||
|
||
with(new Message($this->output))->render( | ||
$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,53 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb\Loggers; | ||
|
||
use Laravel\Reverb\Contracts\Logger; | ||
|
||
class NullLogger implements Logger | ||
{ | ||
/** | ||
* Log an infomational message. | ||
* | ||
* @param string $title | ||
* @param string|null $message | ||
* @return void | ||
*/ | ||
public function info(string $title, ?string $message = null): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Log an error message. | ||
* | ||
* @param string $message | ||
* @return void | ||
*/ | ||
public function error(string $string): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Append a new line to the log. | ||
* | ||
* @param int $lines | ||
* @return void | ||
*/ | ||
public function line(?int $lines = 1): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Log a message sent to the server. | ||
* | ||
* @param string $message | ||
* @return void | ||
*/ | ||
public function message(string $message): void | ||
{ | ||
// | ||
} | ||
} |
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,67 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb\Loggers; | ||
|
||
use Laravel\Reverb\Contracts\Logger; | ||
|
||
class StandardLogger implements Logger | ||
{ | ||
/** | ||
* Log an infomational message. | ||
* | ||
* @param string $title | ||
* @param string|null $message | ||
* @return void | ||
*/ | ||
public function info(string $title, ?string $message = null): void | ||
{ | ||
$output = $title; | ||
|
||
if ($message) { | ||
$output .= ': '.$message; | ||
} | ||
|
||
fwrite(STDOUT, $output.PHP_EOL); | ||
} | ||
|
||
/** | ||
* Log an error message. | ||
* | ||
* @param string $message | ||
* @return void | ||
*/ | ||
public function error(string $string): void | ||
{ | ||
fwrite(STDERR, $string.PHP_EOL); | ||
} | ||
|
||
/** | ||
* Append a new line to the log. | ||
* | ||
* @param int $lines | ||
* @return void | ||
*/ | ||
public function line(?int $lines = 1): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Log a message sent to the server. | ||
* | ||
* @param string $message | ||
* @return void | ||
*/ | ||
public function message(string $message): void | ||
{ | ||
$message = json_decode($message, true); | ||
|
||
if (isset($message['data']['channel_data'])) { | ||
$message['data']['channel_data'] = json_decode($message['data']['channel_data'], true); | ||
} | ||
|
||
$message = json_encode($message, JSON_PRETTY_PRINT); | ||
|
||
fwrite(STDOUT, $message.PHP_EOL); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
use Laravel\Reverb\Contracts\Logger; | ||
|
||
class Output extends Facade | ||
{ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return Logger::class; | ||
} | ||
} |
Oops, something went wrong.