1 | <?php |
||
8 | class GoogleStructuredDataTestTool extends Command |
||
9 | { |
||
10 | /** |
||
11 | * The name and signature of the console command. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $signature = 'google-markup:test |
||
16 | {path? : path where find url.txt, if you want to test url direct, you can use directly url that start with http} |
||
17 | {--M|mail= : If you want send result to email} |
||
18 | {--N|nomailok=false : True if you want send result to email only for alarm, false is default} |
||
19 | {--w|whitelist= : If you want exclude from alarm some url, divide by ","} |
||
20 | {verbosity=false : If you want more verbosity log} |
||
21 | '; |
||
22 | |||
23 | /** |
||
24 | * The console command description. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $description = <<<EOF |
||
29 | The <info>google-markup:test</info> command looks in url.txt file in the given path |
||
30 | and foreach url find in this file, check against google structured data testing tool API: |
||
31 | <info>php artisan google-markup:test</info> |
||
32 | If you omit path argument, command look into url defined in app config. |
||
33 | You can also pass an url in the path as an argument: |
||
34 | <info>php artisan google-markup:test https://www.padosoft.com</info> |
||
35 | By default, the command displays the result in console, but you can also |
||
36 | send an html email by using the <info>--mail</info> option: |
||
37 | <info>php artisan /path/to/my/url.txt [email protected]</info> |
||
38 | If you want to receive an email only for alarm (find markup errors) using the <info>--nomailok</info> option: |
||
39 | <info>php artisan /path/to/my/url.txt [email protected] --nomailok=true</info> |
||
40 | If you want to exclude some url from alert using the <info>--whitelist</info> option: |
||
41 | <info>php artisan /path/to/my/url.txt --whitelist=https://www.padosoft.com,https://blog.padosoft.com</info> |
||
42 | If you want more verbosity log append --verbosity=true |
||
43 | EOF; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $headersTableConsole = ['name', 'type', 'errors', 'warnings', 'isOk']; |
||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $tableEntities = []; |
||
54 | |||
55 | /** |
||
56 | * Create a new command instance. |
||
57 | * |
||
58 | */ |
||
59 | public function __construct() |
||
63 | |||
64 | /** |
||
65 | * Execute the console command. |
||
66 | * |
||
67 | * @return mixed |
||
68 | */ |
||
69 | public function handle() |
||
73 | |||
74 | /** |
||
75 | * @param $argument |
||
76 | * @param $option |
||
77 | */ |
||
78 | private function hardWork($argument, $option) |
||
107 | |||
108 | /** |
||
109 | * @param $mail |
||
110 | * @param $nomailok |
||
111 | * @param boolean $tuttoOk |
||
112 | */ |
||
113 | private function notifyResult($mail, $nomailok, $tuttoOk) |
||
125 | |||
126 | /** |
||
127 | * @param boolean $result |
||
128 | */ |
||
129 | private function notify($result) |
||
138 | |||
139 | /** |
||
140 | * |
||
141 | */ |
||
142 | private function notifyOK() |
||
148 | |||
149 | /** |
||
150 | * |
||
151 | */ |
||
152 | private function notifyKO() |
||
158 | |||
159 | /** |
||
160 | * @param $mail |
||
161 | * @param boolean $tuttoOk |
||
162 | */ |
||
163 | private function sendEmail($mail, $tuttoOk) |
||
170 | |||
171 | /** |
||
172 | * |
||
173 | * @param $url |
||
174 | * @return array with a valid url or empty array |
||
175 | */ |
||
176 | private function getUrl($url) |
||
186 | |||
187 | /** |
||
188 | * |
||
189 | * @param $path |
||
190 | * @param \Illuminate\Console\Command $cmd |
||
191 | * @return array of valid url or empty array |
||
192 | */ |
||
193 | private function getUrlsByPath($path, \Illuminate\Console\Command $cmd) |
||
215 | |||
216 | /** |
||
217 | * |
||
218 | * @param $path |
||
219 | * @param \Illuminate\Console\Command $cmd |
||
220 | * @return array of valid url |
||
221 | */ |
||
222 | private function findUrls($path, \Illuminate\Console\Command $cmd) |
||
239 | |||
240 | /** |
||
241 | * @param $url |
||
242 | * @param $whitelist |
||
243 | * @return bool |
||
244 | */ |
||
245 | private function checkStructuredData($url, $whitelist) |
||
268 | |||
269 | } |
||
270 | |||
271 |