sonrac /
laravel-wamp
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created by PhpStorm. |
||
| 4 | * |
||
| 5 | * @author Donii Sergii <[email protected]> |
||
| 6 | * Date: 10/25/17 |
||
| 7 | * Time: 12:18 PM |
||
| 8 | */ |
||
| 9 | |||
| 10 | namespace sonrac\WAMP; |
||
| 11 | |||
| 12 | use Thruway\Peer\Client as PeerClient; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Class Client |
||
| 16 | * Client class. |
||
| 17 | * |
||
| 18 | * @author Donii Sergii <[email protected]> |
||
| 19 | */ |
||
| 20 | class Client extends PeerClient |
||
| 21 | { |
||
| 22 | protected $routePath = null; |
||
| 23 | |||
| 24 | protected $session; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Session start event |
||
| 28 | * |
||
| 29 | * @param \Thruway\ClientSession $session |
||
| 30 | * @param \Thruway\Transport\TransportInterface $transport |
||
| 31 | * |
||
| 32 | * @author Donii Sergii <[email protected]> |
||
| 33 | */ |
||
| 34 | 3 | public function onSessionStart($session, $transport) |
|
| 35 | { |
||
| 36 | 3 | $this->includeRoutes($session, $transport); |
|
| 37 | 3 | } |
|
| 38 | |||
| 39 | 2 | public function setRoutePath($path) |
|
| 40 | { |
||
| 41 | 2 | $this->routePath = $path; |
|
| 42 | 2 | } |
|
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritdoc} |
||
| 46 | */ |
||
| 47 | 1 | public function start($startLoop = true) |
|
| 48 | { |
||
| 49 | 1 | app()->wampRouter->parseGroups(); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 50 | 1 | parent::start($startLoop); |
|
| 51 | 1 | } |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Include routes |
||
| 55 | * |
||
| 56 | * @param \Thruway\ClientSession $session Client session |
||
| 57 | * @param \Thruway\Transport\TransportInterface $transport Transport provider |
||
| 58 | * |
||
| 59 | * @author Donii Sergii <[email protected]> |
||
| 60 | */ |
||
| 61 | 3 | protected function includeRoutes($session, $transport) |
|
| 62 | { |
||
| 63 | 3 | if (!is_dir($this->routePath) && !is_file($this->routePath)) { |
|
| 64 | 1 | return; |
|
| 65 | } |
||
| 66 | |||
| 67 | 2 | $session = $this->session = $session; |
|
| 68 | 2 | $client = $this; |
|
| 69 | |||
| 70 | /* @scrutinizer ignore-call */ |
||
| 71 | 2 | app()->wampRouter->setClient($client); |
|
| 72 | |||
| 73 | 2 | if (is_file($this->routePath)) { |
|
| 74 | 1 | require $this->routePath; |
|
| 75 | 1 | return; |
|
| 76 | } |
||
| 77 | |||
| 78 | 1 | if (is_dir($this->routePath)) { |
|
| 79 | 1 | $files = scandir($this->routePath); |
|
| 80 | |||
| 81 | 1 | foreach ($files as $file) { |
|
| 82 | 1 | if ($file === '.' || $file === '..') { |
|
| 83 | 1 | continue; |
|
| 84 | } |
||
| 85 | |||
| 86 | 1 | if (pathinfo($file, PATHINFO_EXTENSION) === 'php') { |
|
| 87 | 1 | require $this->routePath.DIRECTORY_SEPARATOR.$file; |
|
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | 1 | } |
|
| 92 | } |
||
| 93 |