|
| 1 | +<?php |
| 2 | + |
| 3 | +/*! |
| 4 | + * File Util Class |
| 5 | + * |
| 6 | + * Copyright (c) 2014 Dave Olsen, http://dmolsen.com |
| 7 | + * Licensed under the MIT license |
| 8 | + * |
| 9 | + * Generic file related functions that are used throughout Pattern Lab |
| 10 | + * |
| 11 | + */ |
| 12 | + |
| 13 | +namespace PatternLab; |
| 14 | + |
| 15 | +use \PatternLab\Config; |
| 16 | + |
| 17 | +class FileUtil { |
| 18 | + |
| 19 | + /** |
| 20 | + * Copies a file from the given source path to the given public path. |
| 21 | + * THIS IS NOT FOR PATTERNS |
| 22 | + * @param {String} the source file |
| 23 | + * @param {String} the public file |
| 24 | + */ |
| 25 | + protected static function moveFile($s,$p) { |
| 26 | + if (file_exists(Config::$options["sourceDir"]."/".$s)) { |
| 27 | + copy(Config::$options["sourceDir"]."/".$s,__DIR__.Config::$options["patternPublicDir"]."/".$p); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Moves static files that aren't directly related to Pattern Lab |
| 33 | + * @param {String} file name to be moved |
| 34 | + * @param {String} copy for the message to be printed out |
| 35 | + * @param {String} part of the file name to be found for replacement |
| 36 | + * @param {String} the replacement |
| 37 | + */ |
| 38 | + public static function moveStaticFile($fileName,$copy = "", $find = "", $replace = "") { |
| 39 | + self::moveFile($fileName,str_replace($find, $replace, $fileName)); |
| 40 | + Util::updateChangeTime(); |
| 41 | + if ($copy != "") { |
| 42 | + print $fileName." ".$copy."...\n"; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Check to see if a given filename is in a directory that should be ignored |
| 48 | + * @param {String} file name to be checked |
| 49 | + * |
| 50 | + * @return {Boolean} whether the directory should be ignored |
| 51 | + */ |
| 52 | + public static function ignoreDir($fileName) { |
| 53 | + foreach (Config::$options["id"] as $dir) { |
| 54 | + $pos = strpos(DIRECTORY_SEPARATOR.$fileName,DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR); |
| 55 | + if ($pos !== false) { |
| 56 | + return true; |
| 57 | + } |
| 58 | + } |
| 59 | + return false; |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments