| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * File containing the {@see Mailcode_Factory_CommandSets_Set_Show} class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @package Mailcode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @subpackage Utilities | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @see Mailcode_Factory_CommandSets_Set_Show | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Mailcode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Command set used to create showxxx commands. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @package Mailcode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @subpackage Utilities | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @author Sebastian Mordziol <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class Mailcode_Factory_CommandSets_Set_Show extends Mailcode_Factory_CommandSets_Set | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function var(string $variableName) : Mailcode_Commands_Command_ShowVariable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $variableName = $this->instantiator->filterVariableName($variableName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $cmd = $this->commands->createCommand( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             'ShowVariable', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             $variableName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             '{showvar:'.$variableName.'}' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $this->instantiator->checkCommand($cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         if($cmd instanceof Mailcode_Commands_Command_ShowVariable) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             return $cmd; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         throw $this->instantiator->exceptionUnexpectedType('ShowVariable', $cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function date(string $variableName, string $formatString="") : Mailcode_Commands_Command_ShowDate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $variableName = $this->instantiator->filterVariableName($variableName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $format = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         if(!empty($formatString)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $format = sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 ' "%s"', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 $formatString | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $cmd = $this->commands->createCommand( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             'ShowDate', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             $variableName.$format, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 '{showdate: %s%s}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 $variableName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 $format | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $this->instantiator->checkCommand($cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         if($cmd instanceof Mailcode_Commands_Command_ShowDate) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             return $cmd; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         throw $this->instantiator->exceptionUnexpectedType('ShowDate', $cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     public function number(string $variableName, string $formatString="") : Mailcode_Commands_Command_ShowNumber | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $variableName = $this->instantiator->filterVariableName($variableName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $format = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         if(!empty($formatString)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             $format = sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                 ' "%s"', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 $formatString | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $cmd = $this->commands->createCommand( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             'ShowNumber', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             $variableName.$format, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                 '{shownumber: %s%s}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 $variableName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                 $format | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $this->instantiator->checkCommand($cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         if($cmd instanceof Mailcode_Commands_Command_ShowNumber) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             return $cmd; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         throw $this->instantiator->exceptionUnexpectedType('ShowNumber', $cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * Creates a `showphone` command. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * @param string $variableName The name of the variable, with or without $ sign. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * @param string $sourceFormat Two-letter country code, case insensitive. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * @param string $urlEncoding The URL encoding mode, if any. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @return Mailcode_Commands_Command_ShowPhone | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * @throws Mailcode_Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * @throws Mailcode_Factory_Exception | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 121 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |     public function phone(string $variableName, string $sourceFormat, string $urlEncoding=Mailcode_Factory::URL_ENCODING_NONE) : Mailcode_Commands_Command_ShowPhone | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |         $variableName = $this->instantiator->filterVariableName($variableName); | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |         $params = sprintf( | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |             '%s "%s"', | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |             $variableName, | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |             strtoupper($sourceFormat) | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |         $cmd = $this->commands->createCommand( | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |             'ShowPhone', | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |             '', | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |             $params, | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |             sprintf( | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |                 '{showphone: %s}', | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |                 $params | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |             ) | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |         $this->instantiator->checkCommand($cmd); | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |         $this->instantiator->setEncoding($cmd, $urlEncoding); | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |         if($cmd instanceof Mailcode_Commands_Command_ShowPhone) | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |         { | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |             return $cmd; | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |         throw $this->instantiator->exceptionUnexpectedType('ShowPhone', $cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |     public function snippet(string $snippetName) : Mailcode_Commands_Command_ShowSnippet | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         $snippetName = $this->instantiator->filterVariableName($snippetName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         $cmd = $this->commands->createCommand( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             'ShowSnippet', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             $snippetName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             '{showsnippet:'.$snippetName.'}' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         $this->instantiator->checkCommand($cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         if($cmd instanceof Mailcode_Commands_Command_ShowSnippet) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             return $cmd; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         throw $this->instantiator->exceptionUnexpectedType('ShowSnippet', $cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 173 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 174 |  |  |  |