-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1050 from irazasyed/3.x
Support League Event 2 and 3
- Loading branch information
Showing
15 changed files
with
146 additions
and
38 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,17 @@ | ||
<?php | ||
|
||
namespace Telegram\Bot\Events; | ||
|
||
if (class_exists(\League\Event\AbstractEvent::class)) { | ||
abstract class AbstractEvent extends \League\Event\AbstractEvent implements HasEventName | ||
{ | ||
public function eventName(): string | ||
{ | ||
return $this->getName(); | ||
} | ||
} | ||
} else { | ||
abstract class AbstractEvent | ||
{ | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Telegram\Bot\Events; | ||
|
||
class Emitter extends \League\Event\Emitter implements EventDispatcherListenerContract | ||
{ | ||
public function subscribeTo(string $event, callable $listener, int $priority = 0): void | ||
{ | ||
$this->addListener($event, $listener, $priority); | ||
} | ||
|
||
public function dispatch(object $event): object | ||
{ | ||
return $this->emit($event); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Telegram\Bot\Events; | ||
|
||
use League\Event\EventDispatcher; | ||
use League\Event\PrioritizedListenerRegistry; | ||
|
||
class EventDispatcherFactory | ||
{ | ||
public static function create(): EventDispatcherListenerContract | ||
{ | ||
if (class_exists(EventDispatcher::class)) { | ||
return new LeagueEventDispatcher(new PrioritizedListenerRegistry()); | ||
} | ||
|
||
return new Emitter(); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Telegram\Bot\Events; | ||
|
||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
|
||
interface EventDispatcherListenerContract extends EventDispatcherInterface | ||
{ | ||
public function subscribeTo(string $event, callable $listener, int $priority = 0): 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
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,16 @@ | ||
<?php | ||
|
||
namespace Telegram\Bot\Events; | ||
|
||
use League\Event\EventDispatcher; | ||
|
||
if (class_exists(EventDispatcher::class)) { | ||
interface HasEventName extends \League\Event\HasEventName | ||
{ | ||
} | ||
} else { | ||
interface HasEventName | ||
{ | ||
public function eventName(): string; | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace Telegram\Bot\Events; | ||
|
||
use League\Event\EventDispatcher; | ||
|
||
class LeagueEventDispatcher extends EventDispatcher implements EventDispatcherListenerContract | ||
{ | ||
} |
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
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
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