示例#1
0
 /**
  * @param \Venne\Packages\IPackage $package
  */
 public function install(IPackage $package)
 {
     try {
         $name = $package->getName();
         $configuration = $package->getConfiguration();
         // create resources dir
         if ($package->getRelativePublicPath()) {
             $resourcesDir = $this->resourcesDir;
             $packageDir = $resourcesDir . '/' . $name;
             $targetDir = realpath($package->getPath() . $package->getRelativePublicPath());
             if (!is_dir($packageDir) && is_dir($targetDir)) {
                 umask(00);
                 @mkdir(dirname($packageDir), 0777, true);
                 if (!@symlink(Helpers::getRelativePath(dirname($packageDir), $targetDir), $packageDir) && !is_dir($packageDir)) {
                     FileSystem::copy($targetDir, $packageDir);
                 }
                 $this->actions[] = function () use($resourcesDir) {
                     if (is_link($resourcesDir)) {
                         unlink($resourcesDir);
                     } else {
                         FileSystem::delete($resourcesDir);
                     }
                 };
             }
         }
         // update main config.neon
         if (count($configuration) > 0) {
             $orig = $data = $this->loadConfig();
             $data = array_merge_recursive($data, $configuration);
             $this->saveConfig($data);
             $this->actions[] = function ($self) use($orig) {
                 $self->saveConfig($orig);
             };
         }
     } catch (\Exception $e) {
         $actions = array_reverse($this->actions);
         try {
             foreach ($actions as $action) {
                 $action($this);
             }
         } catch (\Exception $ex) {
             echo $ex->getMessage();
         }
         throw $e;
     }
 }
示例#2
0
 /**
  * @param string $file
  * @return string
  */
 private function getPackageClassByFile($file)
 {
     $classes = Helpers::getClassesFromFile($file);
     if (count($classes) !== 1) {
         throw new InvalidArgumentException(sprintf('File \'%s\' must contain only one class.', $file));
     }
     return $classes[0];
 }