| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is part of the FreshCentrifugoBundle. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * (c) Artem Henvald <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | namespace Fresh\CentrifugoBundle\Token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * JwtPayloadForPrivateChannel. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @see https://centrifugal.github.io/centrifugo/server/private_channels/#claims | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @author Artem Henvald <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | final class JwtPayloadForPrivateChannel extends AbstractJwtPayload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private $client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     private $channel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** @var bool|null */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     private $eto; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @param string      $client | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param string      $channel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @param array       $info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @param int|null    $expirationTime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @param string|null $base64info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param bool        $eto | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function __construct(string $client, string $channel, array $info = [], ?int $expirationTime = null, ?string $base64info = null, bool $eto = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->client = $client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->channel = $channel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->eto = $eto; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         parent::__construct($info, $expirationTime, $base64info); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function getClient(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return $this->client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     public function getChannel(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         return $this->channel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @return bool|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     public function isEto(): ?bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         return $this->eto; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |     public function getPayloadData(): array | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |         $data = [ | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |             'client' => $this->getClient(), | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |             'channel' => $this->getChannel(), | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |         ]; | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |         if (null !== $this->getExpirationTime()) { | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |             $data['exp'] = $this->getExpirationTime(); | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |         if (!empty($this->getInfo())) { | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |             $data['info'] = $this->getInfo(); | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |         if (null !== $this->getBase64Info()) { | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |             $data['b64info'] = $this->getBase64Info(); | 
            
                                                        
            
                                    
            
            
                | 94 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |         if (null !== $this->isEto()) { | 
            
                                                        
            
                                    
            
            
                | 97 |  |  |             $data['eto'] = $this->isEto(); | 
            
                                                        
            
                                    
            
            
                | 98 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 100 |  |  |         return $data; | 
            
                                                        
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 102 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 103 |  |  |  |