1 | <?php |
||
12 | * @license https://github.com/lmihaylov2512/pass-generator/blob/master/LICENSE.md MIT License |
||
13 | */ |
||
14 | class App |
||
15 | { |
||
16 | /** |
||
17 | * @var integer whether the app is in debug mode |
||
18 | */ |
||
19 | const DEBUG_MODE = 0; |
||
20 | |||
21 | /** |
||
22 | * @var array options with title and description |
||
23 | */ |
||
24 | protected static $options = [ |
||
25 | 'upperCase' => [ |
||
26 | 'title' => 'upper case', |
||
27 | 'desc' => 'use alphabet upper letters [A-Z]', |
||
28 | ], |
||
29 | 'lowerCase' => [ |
||
30 | 'title' => 'lower case', |
||
31 | 'desc' => 'use alphabet lower letters [a-z]', |
||
32 | ], |
||
33 | 'digits' => [ |
||
34 | 'title' => 'digits', |
||
35 | 'desc' => 'all numbers [0-9]', |
||
36 | ], |
||
37 | 'special' => [ |
||
38 | 'title' => 'special', |
||
39 | 'desc' => 'special symbols ~, !, @, #, ...' |
||
40 | ], |
||
41 | 'brackets' => [ |
||
42 | 'title' => 'brackets', |
||
43 | 'desc' => 'all kind of brackets (, ), {, }, [, ]', |
||
44 | ], |
||
45 | 'minus' => [ |
||
46 | 'title' => 'minus', |
||
47 | 'desc' => 'minus sign -', |
||
48 | ], |
||
49 | 'underline' => [ |
||
50 | 'title' => 'underline', |
||
51 | 'desc' => 'underline sign _', |
||
52 | ], |
||
53 | 'space' => [ |
||
54 | 'title' => 'space', |
||
55 | 'desc' => 'space character \' \'', |
||
56 | ], |
||
57 | ]; |
||
58 | /** |
||
59 | * @var Generator password generator instance |
||
60 | */ |
||
61 | protected static $generator; |
||
62 | |||
63 | /** |
||
64 | * Check whether the current request is ajax. |
||
65 | * |
||
66 | * @return boolean the result from checking |
||
67 | */ |
||
68 | public static function isAjaxRequest() |
||
72 | |||
73 | /** |
||
74 | * Return post variable, if exists, or specific default value. |
||
75 | * |
||
76 | * @param mixed $default default value, if post doesn't exist |
||
77 | * @return mixed |
||
78 | */ |
||
79 | public static function getPost($default = null) |
||
83 | |||
84 | /** |
||
85 | * Get all options array. |
||
86 | * |
||
87 | * @return array options array |
||
88 | */ |
||
89 | public static function getOptions() |
||
93 | |||
94 | /** |
||
95 | * Create password generator, if necessary and return it. |
||
96 | * |
||
97 | * @return Generator password generator instance |
||
98 | */ |
||
99 | public static function getGenerator() |
||
106 | |||
107 | /** |
||
108 | * If is ajax request and post exists, generate password and cancel script execution. |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | public static function run() |
||
113 | { |
||
114 | if (static::isAjaxRequest() && ($data = static::getPost()) !== null) { |
||
115 | foreach ($data as $option => $value) { |
||
116 | static::getGenerator()->$option = $value; |
||
117 | } |
||
118 | |||
119 | die(static::getGenerator()->generate()); |
||
120 | } |
||
121 | } |
||
212 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.