Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit558dfa8

Browse files
committed
feature#36616 [Notifier] Add Zulip notifier bridge (phpfour)
This PR was merged into the 5.2-dev branch.Discussion----------[Notifier] Add Zulip notifier bridge| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| Deprecations? | no| Tickets | See#33687| License | MIT| Doc PR |symfony/symfony-docs#13604This adds a [Zulip](https://zulipchat.com/) (another popular open source Slack alternative) transport for the new Notifier component.#### Sample DSN```ZULIP_DSN=zulip://test-bot@zulipchat.com:api-key@example.zulipchat.com?channel=builds```#### Configuration```yml# config/packages/notifier.yamlframework: notifier: chatter_transports: zulip: '%env(ZULIP_DSN)%'```#### Example```phppublic function index(ChatterInterface $chatter){ $message = (new ChatMessage('New order arrived!', new ZulipOptions('Ordering'))) ->transport('zulip'); $chatter->send($message); ...}```Commits-------bd4fd32 Adds Zulip notifier bridge
2 parentsb968497 +bd4fd32 commit558dfa8

File tree

14 files changed

+328
-1
lines changed

14 files changed

+328
-1
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
useSymfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
105105
useSymfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
106106
useSymfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
107+
useSymfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory;
107108
useSymfony\Component\Notifier\Notifier;
108109
useSymfony\Component\Notifier\Recipient\AdminRecipient;
109110
useSymfony\Component\PropertyAccess\PropertyAccessor;
@@ -2082,6 +2083,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
20822083
FreeMobileTransportFactory::class =>'notifier.transport_factory.freemobile',
20832084
OvhCloudTransportFactory::class =>'notifier.transport_factory.ovhcloud',
20842085
SinchTransportFactory::class =>'notifier.transport_factory.sinch',
2086+
ZulipTransportFactory::class =>'notifier.transport_factory.zulip',
20852087
];
20862088

20872089
foreach ($classToServicesas$class =>$service) {

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
useSymfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
2222
useSymfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
2323
useSymfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
24+
useSymfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory;
2425
useSymfony\Component\Notifier\Transport\AbstractTransportFactory;
2526
useSymfony\Component\Notifier\Transport\NullTransportFactory;
2627

@@ -70,6 +71,10 @@
7071
->parent('notifier.transport_factory.abstract')
7172
->tag('texter.transport_factory')
7273

74+
->set('notifier.transport_factory.zulip', ZulipTransportFactory::class)
75+
->parent('notifier.transport_factory.abstract')
76+
->tag('texter.transport_factory')
77+
7378
->set('notifier.transport_factory.null', NullTransportFactory::class)
7479
->parent('notifier.transport_factory.abstract')
7580
->tag('chatter.transport_factory')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/Testsexport-ignore
2+
/phpunit.xml.distexport-ignore
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
5.2.0
5+
-----
6+
7+
* Added the bridge
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2020 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Zulip Notifier
2+
==============
3+
4+
Provides Zulip integration for Symfony Notifier.
5+
6+
Resources
7+
---------
8+
9+
*[Contributing](https://symfony.com/doc/current/contributing/index.html)
10+
*[Report issues](https://github.com/symfony/symfony/issues) and
11+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
12+
in the[main Symfony repository](https://github.com/symfony/symfony)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Notifier\Bridge\Zulip;
13+
14+
useSymfony\Component\Notifier\Message\MessageOptionsInterface;
15+
16+
/**
17+
* @author Mohammad Emran Hasan <phpfour@gmail.com>
18+
*
19+
* @experimental in 5.2
20+
*/
21+
finalclass ZulipOptionsimplements MessageOptionsInterface
22+
{
23+
/** @var string|null */
24+
private$topic;
25+
26+
/** @var string|null */
27+
private$recipient;
28+
29+
publicfunction__construct(?string$topic =null, ?string$recipient =null)
30+
{
31+
$this->topic =$topic;
32+
$this->recipient =$recipient;
33+
}
34+
35+
publicfunctiontoArray():array
36+
{
37+
return [
38+
'topic' =>$this->topic,
39+
'recipient' =>$this->recipient,
40+
];
41+
}
42+
43+
publicfunctiongetRecipientId(): ?string
44+
{
45+
return$this->recipient;
46+
}
47+
48+
publicfunctiontopic(string$topic):self
49+
{
50+
$this->topic =$topic;
51+
52+
return$this;
53+
}
54+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Notifier\Bridge\Zulip;
13+
14+
useSymfony\Component\Notifier\Exception\LogicException;
15+
useSymfony\Component\Notifier\Exception\TransportException;
16+
useSymfony\Component\Notifier\Message\ChatMessage;
17+
useSymfony\Component\Notifier\Message\MessageInterface;
18+
useSymfony\Component\Notifier\Message\SentMessage;
19+
useSymfony\Component\Notifier\Transport\AbstractTransport;
20+
useSymfony\Contracts\EventDispatcher\EventDispatcherInterface;
21+
useSymfony\Contracts\HttpClient\HttpClientInterface;
22+
23+
/**
24+
* @author Mohammad Emran Hasan <phpfour@gmail.com>
25+
*
26+
* @experimental in 5.2
27+
*/
28+
class ZulipTransportextends AbstractTransport
29+
{
30+
private$email;
31+
private$token;
32+
private$channel;
33+
34+
publicfunction__construct(string$email,string$token,string$channel,HttpClientInterface$client =null,EventDispatcherInterface$dispatcher =null)
35+
{
36+
$this->email =$email;
37+
$this->token =$token;
38+
$this->channel =$channel;
39+
40+
parent::__construct($client,$dispatcher);
41+
}
42+
43+
publicfunction__toString():string
44+
{
45+
returnsprintf('zulip://%s?channel=%s',$this->getEndpoint(),$this->channel);
46+
}
47+
48+
publicfunctionsupports(MessageInterface$message):bool
49+
{
50+
return$messageinstanceof ChatMessage && (null ===$message->getOptions() ||$message->getOptions()instanceof ZulipOptions);
51+
}
52+
53+
/**
54+
* @see https://zulipchat.com/api/send-message
55+
*/
56+
protectedfunctiondoSend(MessageInterface$message):SentMessage
57+
{
58+
if (!$messageinstanceof ChatMessage) {
59+
thrownewLogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).',__CLASS__, ChatMessage::class,get_debug_type($message)));
60+
}
61+
62+
if (null !==$message->getOptions() && !($message->getOptions()instanceof ZulipOptions)) {
63+
thrownewLogicException(sprintf('The "%s" transport only supports instances of "%s" for options.',__CLASS__, ZulipOptions::class));
64+
}
65+
66+
$endpoint =sprintf('https://%s/api/v1/messages',$this->getEndpoint());
67+
68+
$options = ($opts =$message->getOptions()) ?$opts->toArray() : [];
69+
$options['content'] =$message->getSubject();
70+
71+
if (null ===$message->getRecipientId() &&empty($options['topic'])) {
72+
thrownewLogicException(sprintf('The "%s" transport requires a topic when posting to streams.',__CLASS__));
73+
}
74+
75+
if (null ===$message->getRecipientId()) {
76+
$options['type'] ='stream';
77+
$options['to'] =$this->channel;
78+
}else {
79+
$options['type'] ='private';
80+
$options['to'] =$message->getRecipientId();
81+
}
82+
83+
$response =$this->client->request('POST',$endpoint, [
84+
'auth_basic' =>$this->email.':'.$this->token,
85+
'body' =>$options,
86+
]);
87+
88+
if (200 !==$response->getStatusCode()) {
89+
$result =$response->toArray(false);
90+
91+
thrownewTransportException(sprintf('Unable to post the Zulip message: "%s" (%s).',$result['msg'],$result['code']),$response);
92+
}
93+
94+
$success =$response->toArray(false);
95+
96+
$message =newSentMessage($message, (string)$this);
97+
$message->setMessageId($success['id']);
98+
99+
return$message;
100+
}
101+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Notifier\Bridge\Zulip;
13+
14+
useSymfony\Component\Notifier\Exception\UnsupportedSchemeException;
15+
useSymfony\Component\Notifier\Transport\AbstractTransportFactory;
16+
useSymfony\Component\Notifier\Transport\Dsn;
17+
useSymfony\Component\Notifier\Transport\TransportInterface;
18+
19+
/**
20+
* @author Mohammad Emran Hasan <phpfour@gmail.com>
21+
*
22+
* @experimental in 5.2
23+
*/
24+
class ZulipTransportFactoryextends AbstractTransportFactory
25+
{
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
publicfunctioncreate(Dsn$dsn):TransportInterface
30+
{
31+
$scheme =$dsn->getScheme();
32+
$email =$this->getUser($dsn);
33+
$token =$this->getPassword($dsn);
34+
$channel =$dsn->getOption('channel');
35+
$host =$dsn->getHost();
36+
$port =$dsn->getPort();
37+
38+
if ('zulip' ===$scheme) {
39+
return (newZulipTransport($email,$token,$channel,$this->client,$this->dispatcher))->setHost($host)->setPort($port);
40+
}
41+
42+
thrownewUnsupportedSchemeException($dsn,'zulip',$this->getSupportedSchemes());
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
protectedfunctiongetSupportedSchemes():array
49+
{
50+
return ['zulip'];
51+
}
52+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name":"symfony/zulip-notifier",
3+
"type":"symfony-bridge",
4+
"description":"Symfony Zulip Notifier Bridge",
5+
"keywords": ["zulip","notifier"],
6+
"homepage":"https://symfony.com",
7+
"license":"MIT",
8+
"authors": [
9+
{
10+
"name":"Mohammad Emran Hasan",
11+
"email":"phpfour@gmail.com"
12+
},
13+
{
14+
"name":"Symfony Community",
15+
"homepage":"https://symfony.com/contributors"
16+
}
17+
],
18+
"require": {
19+
"php":"^7.2.5",
20+
"symfony/http-client":"^4.3|^5.0",
21+
"symfony/notifier":"^5.0"
22+
},
23+
"autoload": {
24+
"psr-4": {"Symfony\\Component\\Notifier\\Bridge\\Zulip\\":"" },
25+
"exclude-from-classmap": [
26+
"/Tests/"
27+
]
28+
},
29+
"minimum-stability":"dev",
30+
"extra": {
31+
"branch-alias": {
32+
"dev-master":"5.2-dev"
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp