Exemple #1
0
 /**
  * @param \Venne\Module\IModule $module
  */
 public function install(IModule $module)
 {
     try {
         $name = $module->getName();
         $configuration = $module->getConfiguration();
         // create resources dir
         $resourcesDir = $this->resourcesDir;
         $moduleDir = $resourcesDir . "/{$name}Module";
         $targetDir = new \SplFileInfo($module->getPath() . $module->getRelativePublicPath());
         $targetDir = $targetDir->getRealPath();
         if (!file_exists($moduleDir) && file_exists($targetDir)) {
             umask(00);
             @mkdir(dirname($moduleDir), 0777, TRUE);
             if (!@symlink(File::getRelativePath(dirname($moduleDir), $targetDir), $moduleDir) && !file_exists($moduleDir)) {
                 File::copy($targetDir, $moduleDir);
             }
             $this->actions[] = function () use($resourcesDir) {
                 if (is_link($resourcesDir)) {
                     unlink($resourcesDir);
                 } else {
                     File::rmdir($resourcesDir, TRUE);
                 }
             };
         }
         // 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;
     }
 }