| Conditions | 3 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | public static function saveStringToFile($string, $filename, $fileExtension = '.dat') |
||
| 28 | { |
||
| 29 | // Create dir if not exists |
||
| 30 | if (!is_dir(dirname($filename))) { |
||
| 31 | Text::debug('Creating missing directory: '.dirname($filename)); |
||
| 32 | mkdir(dirname($filename)); |
||
| 33 | } |
||
| 34 | |||
| 35 | // Warn about overwriting file |
||
| 36 | if (file_exists($filename.$fileExtension)) { |
||
| 37 | Text::message('File '.$filename.$fileExtension.' exists and it will be overwritten!'); |
||
| 38 | Input::dieOnDenyUserConfirm(); |
||
| 39 | } |
||
| 40 | |||
| 41 | Text::message('Saving to file...'); |
||
| 42 | |||
| 43 | $outputFileBytes = file_put_contents($filename.$fileExtension, $string, LOCK_EX); |
||
| 44 | |||
| 45 | Text::message('Output file '.$filename.$fileExtension.' generated with '.$outputFileBytes.' bytes.'); |
||
| 46 | } |
||
| 48 |