| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * File containing the {@see Mailcode_Factory} class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @package Mailcode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @subpackage Utilities | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @see Mailcode_Factory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Mailcode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Factory utility used to create commands. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @package Mailcode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @subpackage Utilities | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @author Sebastian Mordziol <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class Mailcode_Factory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public const ERROR_INVALID_COMMAND_CREATED = 50001; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     public const ERROR_UNEXPECTED_COMMAND_TYPE = 50002; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public const URL_ENCODING_NONE = 'none'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public const URL_ENCODING_ENCODE = 'encode'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public const URL_ENCODING_DECODE = 'decode'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     * @var Mailcode_Factory_CommandSets|NULL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     private static ?Mailcode_Factory_CommandSets $commandSets = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * Returns the command set for `show` commands. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @return Mailcode_Factory_CommandSets_Set_Show | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     public static function show() : Mailcode_Factory_CommandSets_Set_Show | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         return self::getSets()->show(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * Return the command set for `set` commands. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @return Mailcode_Factory_CommandSets_Set_Set | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     public static function set() : Mailcode_Factory_CommandSets_Set_Set | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         return self::getSets()->set(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * Return the command set for `if` commands. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @return Mailcode_Factory_CommandSets_Set_If | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public static function if() : Mailcode_Factory_CommandSets_Set_If | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         return self::getSets()->if(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * Return the command set for `else if` commands. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * @return Mailcode_Factory_CommandSets_Set_ElseIf | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     public static function elseIf() : Mailcode_Factory_CommandSets_Set_ElseIf | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         return self::getSets()->elseIf(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * Return the command set for `miscellaneous` commands. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @return Mailcode_Factory_CommandSets_Set_Misc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     public static function misc() : Mailcode_Factory_CommandSets_Set_Misc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         return self::getSets()->misc(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     * Creates a renderer instance, which can be used to easily | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     * create and convert commands to strings. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     * @return Mailcode_Renderer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public static function createRenderer() : Mailcode_Renderer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return new Mailcode_Renderer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |    /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     * Creates a printer instance, which works like the renderer, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     * but outputs the generated strings to standard output. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     * @return Mailcode_Printer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     public static function createPrinter() : Mailcode_Printer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         return new Mailcode_Printer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |    /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     * Gets/creates the global instance of the date format info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     * class, used to handle date formatting aspects. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     * @return Mailcode_Date_FormatInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     public static function createDateInfo() : Mailcode_Date_FormatInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         return Mailcode_Date_FormatInfo::getInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |     protected static function getSets() : Mailcode_Factory_CommandSets | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |         if(!isset(self::$commandSets)) | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |         { | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |             self::$commandSets = new Mailcode_Factory_CommandSets(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         return self::$commandSets; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 127 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 128 |  |  |  |