| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace JeroenNoten\LaravelAdminLte\Helpers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Support\Facades\File; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Support\Str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class CommandHelper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |      * The path to the package's root folder. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     protected static $packagePath = __DIR__.'/../../'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * The path to the package's stubs folder. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     protected static $stubsPath = __DIR__.'/../Console/stubs'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * Copies a directory to the specified destination. Returns whether the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * directory could be copied successfully. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @param  string  $directory  The path of the directory to be copied | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @param  string  $destination  The path of the destination folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @param  bool  $force  Whether to force the overwrite of existing files | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @param  bool  $recursive  Whether to copy subfolders recursively | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @param  array  $ignores  An array of name patterns to ignore while copying | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 28 |  |     public static function copyDirectory( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $directory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $destination, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $force = false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $recursive = false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $ignores = [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         // Check if we can open the source folder. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 28 |  |         if (! is_resource($dirHandler = @opendir($directory))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 2 |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         // Ensure the destination folder exists. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 26 |  |         File::ensureDirectoryExists($destination); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         // Copy the folder to the destination. Note we will skip dots items. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 26 |  |         $avoids = array_merge($ignores, ['.', '..']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 26 |  |         while (($item = readdir($dirHandler)) !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 26 |  |             $s = $directory.DIRECTORY_SEPARATOR.$item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 26 |  |             $t = $destination.DIRECTORY_SEPARATOR.$item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             // Check if this item should be copied or ignored. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 26 |  |             if (! self::shouldCopyItem($s, $t, $force, $recursive, $avoids)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 26 |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             // Finally, copy the file/folder to destination. If the item is a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             // folder we proceed recursively. Otherwise, copy the file to the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             // destination. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 26 |  |             $res = File::isDirectory($s) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 21 |  |                 ? self::copyDirectory($s, $t, $force, $recursive, $ignores) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 26 |  |                 : File::copy($s, $t); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 26 |  |             if (! $res) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 closedir($dirHandler); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 26 |  |         closedir($dirHandler); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 26 |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * Compares two directories file by file. Returns a boolean indicating | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * whether the two directories are equal, or null when one of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * directories does not exists. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @param  string  $dir1  The path of the first folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @param  string  $dir2  The path of the second folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param  bool  $recursive  Whether to compare subfolders recursively | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @param  array  $ignores  An array of name patterns to ignore while comparing | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @return bool|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 25 |  |     public static function compareDirectories( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $dir1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $dir2, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $recursive = false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $ignores = [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         // Check if we can open the first folder. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 25 |  |         if (! is_resource($dirHandler = @opendir($dir1))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 1 |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         // Check if the second folder exists. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 25 |  |         if (! is_dir($dir2)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 12 |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         // Now, compare the folders. Note we will skip dots items. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 24 |  |         $avoids = array_merge($ignores, ['.', '..']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 24 |  |         while (($item = readdir($dirHandler)) !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 24 |  |             $s = $dir1.DIRECTORY_SEPARATOR.$item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 24 |  |             $t = $dir2.DIRECTORY_SEPARATOR.$item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             // Check if this item should be compared or ignored. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 | 24 |  |             if (! self::shouldCompareItem($s, $recursive, $avoids)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 23 |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             // Finally, compare the files/folders. If the item to compare is a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |             // folder we proceed recursively. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 24 |  |             $res = File::isDirectory($s) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 20 |  |                 ? (bool) self::compareDirectories($s, $t, $recursive, $ignores) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 23 |  |                 : self::compareFiles($s, $t); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 24 |  |             if (! $res) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 | 7 |  |                 closedir($dirHandler); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 | 7 |  |                 return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 22 |  |         closedir($dirHandler); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 22 |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * Checks if two files are equals by comparing their hash values. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * @param  string  $file1  The path to the first file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * @param  string  $file2  The path to the second file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 23 |  |     public static function compareFiles($file1, $file2) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 | 23 |  |         if (! File::isFile($file1) || ! File::isFile($file2)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 | 6 |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 | 23 |  |         return File::hash($file1) === File::hash($file2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * Gets the fully qualified path to the specified package resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * @param  string  $path  Relative path to the resource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 169 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 170 | 24 |  |     public static function getPackagePath($path = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 172 | 24 |  |         if (empty($path)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 173 | 1 |  |             return self::$packagePath; | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 176 | 24 |  |         return self::$packagePath.DIRECTORY_SEPARATOR.$path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * Gets the fully qualified path to the specified package stub resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      * @param  string  $path  Relative path to the stub resource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 | 24 |  |     public static function getStubPath($path = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 | 24 |  |         if (empty($path)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 | 1 |  |             return self::$stubsPath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 | 24 |  |         return self::$stubsPath.DIRECTORY_SEPARATOR.$path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |      * Gets the fully qualified path to the specified view resource, relative to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |      * the configured view path. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |      * @param  string  $path  Relative path to some view resource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 | 24 |  |     public static function getViewPath($path = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 | 24 |  |         $basePath = config('view.paths')[0] ?? resource_path('views'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 | 24 |  |         if (empty($path)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 | 24 |  |             return $basePath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 | 24 |  |         return $basePath.DIRECTORY_SEPARATOR.$path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |      * Checks whether an item (file or folder) should be copied to the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |      * specified destination by analyzing the recursive and force flags, and a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |      * set of item name patterns to be ignored. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |      * @param  string  $s  The source item path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |      * @param  string  $t  The target destination path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |      * @param  bool  $fFlag  The value of the force flag | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |      * @param  bool  $rFlag  The value of the recursive flag | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |      * @param  array  $ignores  An array of name patterns to be ignored | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 | 26 |  |     protected static function shouldCopyItem($s, $t, $fFlag, $rFlag, $ignores) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |         // At first, we should copy the item when it's a directoy and the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         // recursive flag is set, or when it's a file and the target path does | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         // not exists or the force flag is set. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 | 26 |  |         $shouldCopy = File::isDirectory($s) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 | 26 |  |             ? $rFlag | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 | 26 |  |             : (! File::exists($t) || $fFlag); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         // Then we should also check the item name does not match any of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |         // ignore patterns. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 | 26 |  |         return $shouldCopy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 | 26 |  |             && ! self::isIgnoredItem(File::basename($s), $ignores); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |      * Checks whether an item (file or folder) should be compared by analyzing | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |      * the recursive flag, and a set of item name patterns to be ignored. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |      * @param  string  $s  The source item path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |      * @param  bool  $rFlag  The value of the recursive flag | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |      * @param  array  $ignores  An array of name patterns to be ignored | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 | 24 |  |     protected static function shouldCompareItem($s, $rFlag, $ignores) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |         // At first, we should compare the item when it's a file or when it's | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         // a directory and the recursive flag is set. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 | 24 |  |         $shouldCompare = File::isFile($s) || $rFlag; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |         // Then we should also check that the item name does not match any of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |         // the ignore patterns. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 | 24 |  |         return $shouldCompare | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 | 24 |  |             && ! self::isIgnoredItem(File::basename($s), $ignores); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |      * Checks if the name of a folder or file belongs to a set of specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |      * patterns to be ignored. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |      * @param  string  $name  The name of the folder or file to verify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |      * @param  array  $ignores  An array of name patterns to be ignored | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 | 31 |  |     protected static function isIgnoredItem($name, $ignores) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 | 31 |  |         foreach ($ignores as $pattern) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 | 31 |  |             $match = Str::startsWith($pattern, 'regex:') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 | 2 |  |                 ? preg_match(Str::substr($pattern, 6), $name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 | 31 |  |                 : Str::is($pattern, $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 | 31 |  |             if ($match) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 | 29 |  |                 return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 | 31 |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 286 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 287 |  |  |  |