Exemple #1
0
 private function runEmpty(array $directories)
 {
     foreach ($directories as $directory) {
         if (!is_dir($directory)) {
             continue;
         }
         Path::emptyDirectory($directory);
     }
 }
Exemple #2
0
 /**
  * Prepare rules and sym links address. After all packages is ran is required to cal method writeConfiguration()
  * @param PackageInterface $package
  * @param bool $isMain
  * @return string|void
  */
 function run(PackageInterface $package, $isMain = true)
 {
     $extra = $package->getExtra();
     $this->initPaths($extra, $isMain);
     if (!isset($extra['media']) or !isset($extra['media']['directories']) or !is_array($extra['media']['directories'])) {
         return;
     }
     if ($isMain and isset($extra['media']['web.config'])) {
         $this->webConfigTarget = isset($extra['media']['web.config']['target']) ? $extra['media']['web.config']['target'] : self::WEB_CONFIG;
         $this->webConfigSource = isset($extra['media']['web.config']['source']) ? $extra['media']['web.config']['source'] : $this->webConfigTarget;
     }
     $vendorName = trim("vendor/" . $package->getName(), '\\/');
     foreach ($extra['media']['directories'] as $name => $path) {
         if (in_array($name, $this->ignored)) {
             continue;
         }
         if (!preg_match("/^[a-zA-Z0-9_-]+\$/", $name)) {
             throw new \OutOfRangeException("Name must be corresponding to expression: a-zA-Z0-9_-");
         }
         //generate create config
         $relativePath = "/" . ($isMain ? "" : $vendorName . '/') . trim($path, '\\/');
         $absolutePath = Path::normalize($this->cwd . $relativePath);
         $absoluteMediaPath = Path::normalize($this->cwd . '/' . trim($this->wwwRoot . '/' . $this->basePath, "\\/"));
         if (!is_dir($absoluteMediaPath)) {
             throw new \OutOfRangeException("Media directory does not exist for expected path: {$absoluteMediaPath}");
         }
         if (!is_dir($absolutePath)) {
             throw new \OutOfRangeException("Directory declared by relative path: '{$path}' does not exist on absolute path {$absolutePath}");
         }
         $this->addRule($relativePath, $name);
         //create symlink for unix
         $module = $absoluteMediaPath . '/' . $name;
         if (!is_dir($module) and !is_link($module)) {
             $this->addLink($absolutePath, $module);
         }
     }
 }