Mistralys /
mailcode
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * File containing the {@see \Mailcode\Mailcode_Factory} class. |
||
| 4 | * |
||
| 5 | * @package Mailcode |
||
| 6 | * @subpackage Factory |
||
| 7 | * @see \Mailcode\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 Factory |
||
| 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 | * Return the command set for creating variables. |
||
| 87 | * |
||
| 88 | * @return Mailcode_Factory_CommandSets_Set_Variables |
||
| 89 | */ |
||
| 90 | public static function var() : Mailcode_Factory_CommandSets_Set_Variables |
||
| 91 | { |
||
| 92 | return self::getSets()->var(); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Creates a renderer instance, which can be used to easily |
||
| 97 | * create and convert commands to strings. |
||
| 98 | * |
||
| 99 | * @return Mailcode_Renderer |
||
| 100 | */ |
||
| 101 | public static function createRenderer() : Mailcode_Renderer |
||
| 102 | { |
||
| 103 | return new Mailcode_Renderer(); |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Creates a printer instance, which works like the renderer, |
||
| 108 | * but outputs the generated strings to standard output. |
||
| 109 | * |
||
| 110 | * @return Mailcode_Printer |
||
| 111 | */ |
||
| 112 | public static function createPrinter() : Mailcode_Printer |
||
| 113 | { |
||
| 114 | return new Mailcode_Printer(); |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Gets/creates the global instance of the date format info |
||
| 119 | * class, used to handle date formatting aspects. |
||
| 120 | * |
||
| 121 | * @return Mailcode_Date_FormatInfo |
||
| 122 | */ |
||
| 123 | public static function createDateInfo() : Mailcode_Date_FormatInfo |
||
| 124 | { |
||
| 125 | return Mailcode_Date_FormatInfo::getInstance(); |
||
| 126 | } |
||
| 127 | |||
| 128 | protected static function getSets() : Mailcode_Factory_CommandSets |
||
| 129 | { |
||
| 130 | if(!isset(self::$commandSets)) |
||
| 131 | { |
||
| 132 | self::$commandSets = new Mailcode_Factory_CommandSets(); |
||
| 133 | } |
||
| 134 | |||
| 135 | return self::$commandSets; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 136 | } |
||
| 137 | } |
||
| 138 |