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
107 changed files
with
4,557 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,75 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Monolog\Handler; | ||
|
||
use Monolog\Handler\AbstractHandler; | ||
use Monolog\Logger; | ||
use Symfony\Component\Notifier\Notification\Notification; | ||
use Symfony\Component\Notifier\Notifier; | ||
use Symfony\Component\Notifier\NotifierInterface; | ||
|
||
/** | ||
* Uses Notifier as a log handler. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class NotifierHandler extends AbstractHandler | ||
{ | ||
private $notifier; | ||
|
||
public function __construct(NotifierInterface $notifier, int $level = Logger::ERROR, bool $bubble = true) | ||
{ | ||
$this->notifier = $notifier; | ||
|
||
parent::__construct($level < Logger::ERROR ? Logger::ERROR : $level, $bubble); | ||
} | ||
|
||
public function handle(array $record): bool | ||
{ | ||
if (!$this->isHandling($record)) { | ||
return false; | ||
} | ||
|
||
$this->notify([$record]); | ||
|
||
return !$this->bubble; | ||
} | ||
|
||
public function handleBatch(array $records): void | ||
{ | ||
if ($records = array_filter($records, [$this, 'isHandling'])) { | ||
$this->notify($records); | ||
} | ||
} | ||
|
||
private function notify(array $records): void | ||
{ | ||
$record = max(array_column($records, 'level')); | ||
if (($record['context']['exception'] ?? null) instanceof \Throwable) { | ||
$notification = Notification::fromThrowable($record['context']['exception']); | ||
} else { | ||
$notification = new Notification($record['message']); | ||
} | ||
|
||
$notification->importanceFromLogLevelName(Logger::getLevelName($record['level'])); | ||
|
||
try { | ||
$this->notifier->send($notification, ...Notifier::getAdminReceivers()); | ||
} catch (\Throwable $e) { | ||
$message = $e->getMessage(); | ||
while ($e = $e->getPrevious()) { | ||
$message .= ' > '.$e->getMessage(); | ||
} | ||
error_log($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
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
92 changes: 92 additions & 0 deletions
92
src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier.xml
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,92 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service id="notifier" class="Symfony\Component\Notifier\Notifier"> | ||
<argument type="tagged_locator" tag="notifier.channel" index-by="channel" /> | ||
<argument type="service" id="notifier.channel_policy" on-invalid="ignore" /> | ||
<argument type="service" id="messenger.default_bus" on-invalid="ignore" /> | ||
</service> | ||
<service id="Symfony\Component\Notifier\NotifierInterface" alias="notifier" /> | ||
|
||
<service id="notifier.channel_policy" class="Symfony\Component\Notifier\Channel\ChannelPolicy"> | ||
<argument type="collection" /> <!-- policy --> | ||
</service> | ||
|
||
<service id="notifier.browser_channel" class="Symfony\Component\Notifier\Channel\BrowserChannel"> | ||
<argument type="service" id="request_stack" /> | ||
<tag name="notifier.channel" channel="browser" /> | ||
</service> | ||
|
||
<service id="notifier.chat_channel" class="Symfony\Component\Notifier\Channel\ChatChannel"> | ||
<argument type="service" id="chatter.transports" /> | ||
<tag name="notifier.channel" channel="chat" /> | ||
</service> | ||
|
||
<service id="notifier.sms_channel" class="Symfony\Component\Notifier\Channel\SmsChannel"> | ||
<argument type="service" id="texter.transports" /> | ||
<tag name="notifier.channel" channel="sms" /> | ||
</service> | ||
|
||
<service id="notifier.email_channel" class="Symfony\Component\Notifier\Channel\EmailChannel"> | ||
<argument type="service" id="mailer.transports" /> | ||
<tag name="notifier.channel" channel="email" /> | ||
</service> | ||
|
||
<service id="notifier.monolog_handler" class="Symfony\Bridge\Monolog\Handler\NotifierHandler"> | ||
<argument type="service" id="notifier" /> | ||
</service> | ||
|
||
<service id="notifier.failed_message_listener" class="Symfony\Component\Notifier\EventListener\SendFailedMessageToNotifierListener"> | ||
<argument type="service" id="notifier" /> | ||
<tag name="kernel.event_subscriber" /> | ||
</service> | ||
|
||
<!-- chatter --> | ||
<service id="chatter" class="Symfony\Component\Notifier\Chatter"> | ||
<argument type="service" id="chatter.transports" /> | ||
<argument type="service" id="messenger.default_bus" on-invalid="ignore" /> | ||
<argument type="service" id="event_dispatcher" on-invalid="ignore" /> | ||
</service> | ||
<service id="Symfony\Component\Notifier\ChatterInterface" alias="chatter" /> | ||
|
||
<service id="chatter.transports" class="Symfony\Component\Notifier\Transport\Transports"> | ||
<factory service="chatter.transport_factory" method="fromStrings" /> | ||
<argument type="collection" /> <!-- transports --> | ||
</service> | ||
|
||
<service id="chatter.transport_factory" class="Symfony\Component\Notifier\Transport"> | ||
<argument type="tagged_iterator" tag="chatter.transport_factory" /> | ||
</service> | ||
|
||
<service id="chatter.messenger.chat_handler" class="Symfony\Component\Notifier\Messenger\MessageHandler"> | ||
<argument type="service" id="chatter.transports" /> | ||
<tag name="messenger.message_handler" handles="Symfony\Component\Notifier\Message\ChatMessage" /> | ||
</service> | ||
|
||
<!-- texter --> | ||
<service id="texter" class="Symfony\Component\Notifier\Texter"> | ||
<argument type="service" id="texter.transports" /> | ||
<argument type="service" id="messenger.default_bus" on-invalid="ignore" /> | ||
<argument type="service" id="event_dispatcher" on-invalid="ignore" /> | ||
</service> | ||
<service id="Symfony\Component\Notifier\TexterInterface" alias="texter" /> | ||
|
||
<service id="texter.transports" class="Symfony\Component\Notifier\Transport\Transports"> | ||
<factory service="texter.transport_factory" method="fromStrings" /> | ||
<argument type="collection" /> <!-- transports --> | ||
</service> | ||
|
||
<service id="texter.transport_factory" class="Symfony\Component\Notifier\Transport"> | ||
<argument type="tagged_iterator" tag="texter.transport_factory" /> | ||
</service> | ||
|
||
<service id="texter.messenger.sms_handler" class="Symfony\Component\Notifier\Messenger\MessageHandler"> | ||
<argument type="service" id="texter.transports" /> | ||
<tag name="messenger.message_handler" handles="Symfony\Component\Notifier\Message\SmsMessage" /> | ||
</service> | ||
</services> | ||
</container> |
33 changes: 33 additions & 0 deletions
33
src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.xml
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,33 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service id="notifier.transport_factory.abstract" class="Symfony\Component\Notifier\Transport\AbstractTransportFactory" abstract="true"> | ||
<argument type="service" id="event_dispatcher" /> | ||
<argument type="service" id="http_client" on-invalid="ignore" /> | ||
</service> | ||
|
||
<service id="notifier.transport_factory.slack" class="Symfony\Component\Notifier\Bridge\Slack\SlackTransportFactory" parent="notifier.transport_factory.abstract"> | ||
<tag name="chatter.transport_factory" /> | ||
</service> | ||
|
||
<service id="notifier.transport_factory.telegram" class="Symfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory" parent="notifier.transport_factory.abstract"> | ||
<tag name="chatter.transport_factory" /> | ||
</service> | ||
|
||
<service id="notifier.transport_factory.nexmo" class="Symfony\Component\Notifier\Bridge\Nexmo\NexmoTransportFactory" parent="notifier.transport_factory.abstract"> | ||
<tag name="texter.transport_factory" /> | ||
</service> | ||
|
||
<service id="notifier.transport_factory.twilio" class="Symfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory" parent="notifier.transport_factory.abstract"> | ||
<tag name="texter.transport_factory" /> | ||
</service> | ||
|
||
<service id="notifier.transport_factory.null" class="Symfony\Component\Notifier\Transport\NullTransportFactory" parent="notifier.transport_factory.abstract"> | ||
<tag name="notifier.transport_factory" /> | ||
</service> | ||
</services> | ||
</container> |
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,2 @@ | ||
/Tests export-ignore | ||
/phpunit.xml.dist export-ignore |
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,3 @@ | ||
composer.lock | ||
phpunit.xml | ||
vendor/ |
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,2 @@ | ||
/Tests export-ignore | ||
/phpunit.xml.dist export-ignore |
Oops, something went wrong.