Example #1
0
 public function __construct(array $config = [])
 {
     $include = ArrHelper::remove('include', $config, $this->defaultOptions()['include']);
     $exclude = ArrHelper::remove('exclude', $config, $this->defaultOptions()['exclude']);
     $this->finder = new FileFinder(['include' => $include, 'exclude' => $exclude]);
     ObjectHelper::loadAttrs($this, $config);
 }
Example #2
0
 /**
  * Change the owner of an array of files or directories.
  * @from Symfony-filesystem
  * @param string|array|\Traversable $files     A filename, an array of files, or a \Traversable instance to change owner
  * @param string                    $user      The new owner user name
  * @param bool                      $recursive Whether change the owner recursively or not
  *
  * @throws IOException When the change fail
  */
 public static function chown($files, $user, $recursive = false)
 {
     foreach (ArrHelper::toIterator($files) as $file) {
         if ($recursive && is_dir($file) && !is_link($file)) {
             self::chown(new \FilesystemIterator($file), $user, true);
         }
         if (is_link($file) && function_exists('lchown')) {
             if (true !== @lchown($file, $user)) {
                 throw new IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
             }
         } else {
             if (true !== @chown($file, $user)) {
                 throw new IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
             }
         }
     }
 }