-
Notifications
You must be signed in to change notification settings - Fork 1
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
27 changed files
with
351 additions
and
102 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,30 @@ | ||
<?php | ||
|
||
namespace Tii\Telepath\Cache; | ||
|
||
use Cache\Bridge\SimpleCache\SimpleCacheBridge; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
use Psr\SimpleCache\CacheInterface; | ||
|
||
trait UsesCache | ||
{ | ||
|
||
protected ?CacheInterface $cache = null; | ||
|
||
public function enableCaching(CacheInterface|CacheItemPoolInterface $cache): static | ||
{ | ||
if ($cache instanceof CacheItemPoolInterface) { | ||
$cache = new SimpleCacheBridge($cache); | ||
} | ||
|
||
$this->cache = $cache; | ||
|
||
return $this; | ||
} | ||
|
||
public function cache(): ?CacheInterface | ||
{ | ||
return $this->cache; | ||
} | ||
|
||
} |
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,56 @@ | ||
<?php | ||
|
||
namespace Tii\Telepath\Conversations; | ||
|
||
use Tii\Telepath\Telegram\Update; | ||
use Tii\Telepath\TelegramBot; | ||
|
||
abstract class Conversation | ||
{ | ||
|
||
protected ?string $next = null; | ||
|
||
public function __construct( | ||
protected TelegramBot $bot | ||
) {} | ||
|
||
public static function conversationKey(Update $update) | ||
{ | ||
return "telepath.conversation.{$update->user()->id}.{$update->chat()->id}"; | ||
} | ||
|
||
public function next(string $method) | ||
{ | ||
$cache = $this->bot->cache(); | ||
$conversationKey = static::conversationKey($this->bot->latestUpdate()); | ||
|
||
$this->next = $method; | ||
$cache->set($conversationKey, $this); | ||
} | ||
|
||
public function end() | ||
{ | ||
$cache = $this->bot->cache(); | ||
$conversationKey = static::conversationKey($this->bot->latestUpdate()); | ||
|
||
$cache->delete($conversationKey); | ||
} | ||
|
||
public function __serialize(): array | ||
{ | ||
$data = get_object_vars($this); | ||
unset($data['bot']); | ||
|
||
return $data; | ||
} | ||
|
||
public function __invoke(Update $update) | ||
{ | ||
if ($this->next === null) { | ||
return null; | ||
} | ||
|
||
return $this->{$this->next}($update); | ||
} | ||
|
||
} |
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
4 changes: 2 additions & 2 deletions
4
...ndler/CallbackQuery/CallbackQueryData.php → ...dlers/CallbackQuery/CallbackQueryData.php
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
2 changes: 1 addition & 1 deletion
2
src/Handler/ChatJoinRequest.php → src/Handlers/ChatJoinRequest.php
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
2 changes: 1 addition & 1 deletion
2
src/Handler/ChosenInlineResult.php → src/Handlers/ChosenInlineResult.php
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
2 changes: 1 addition & 1 deletion
2
src/Handler/EditedChannelPost.php → src/Handlers/EditedChannelPost.php
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
Oops, something went wrong.