Пример #1
0
 public function run()
 {
     if ($this->templateType === self::TEMPLATE_TYPE_DIR) {
         $cakeJson = $this->join(realpath($this->template), 'cheesecake.json');
     } elseif ($this->templateType === self::TEMPLATE_TYPE_REMOTE_GIT) {
         $repo = Repository::createFromRemote($this->template);
         $cakeJson = $this->join(realpath($repo->getPath()), 'cheesecake.json');
     } elseif ($this->templateType === self::TEMPLATE_TYPE_LOCAL_GIT) {
         $repo = Repository::open($this->template);
         $cakeJson = $this->join(realpath($repo->getPath()), 'cheesecake.json');
     } else {
         throw new CheesecakeUnknownTemplateException();
     }
     if (!file_exists($cakeJson)) {
         throw new CheesecakeNotFoundExeption();
     }
     $replace = [];
     $args = json_decode(file_get_contents($cakeJson), true);
     // Detect if we need the cli promt
     $diff = array_diff(array_keys($args), array_keys($this->params));
     if (count($diff) > 0 && false === $this->noInteraction) {
         foreach ($args as $key => $value) {
             // :S
             $args[$key] = cli\prompt($key, $value, $marker = ' : ');
         }
     } else {
         // Merge constructor params with cheesecake.json
         $args = array_merge($args, $this->params);
     }
     $replace = ['cheesecake' => $args];
     $tmpDir = $this->join(sys_get_temp_dir(), sha1(uniqid()));
     if (!$this->fs->copyDirectory($this->template, $tmpDir)) {
         throw new CheesecakeFilesystemExeption();
     }
     $this->processHook('pre_gen.php', $tmpDir);
     $this->processDirs($tmpDir, $replace);
     $this->processFiles($tmpDir, $replace);
     if (!$this->fs->delete($this->join($tmpDir, 'cheesecake.json'))) {
         throw new CheesecakeFilesystemExeption();
     }
     if (!$this->fs->copyDirectory($tmpDir, $this->output)) {
         throw new CheesecakeFilesystemExeption();
     }
     if (!$this->fs->deleteDirectory($tmpDir)) {
         throw new CheesecakeFilesystemExeption();
     }
     $this->processHook('post_gen.php', $this->output);
     $hookDir = $this->join($this->output, 'hooks');
     if (is_dir($hookDir)) {
         if (!$this->fs->deleteDirectory($hookDir)) {
             throw new CheesecakeFilesystemExeption();
         }
     }
     return true;
 }
 /**
  * @param array $banned_editors
  *   Indexed array containing full paths to editors that have failed.
  * @return string
  *   Full path to the preferred editor to use.
  */
 protected function locatePreferredEditor($banned_editors = [])
 {
     // Use environment variable settings without prompting if they're going to
     // work.
     if ($this->preferredEditor && !in_array($this->preferredEditor, $banned_editors)) {
         return $this->preferredEditor;
     } else {
         if ($this->envVarEditor && !in_array($this->envVarEditor, $banned_editors)) {
             $this->preferredEditor = $this->envVarEditor;
         } else {
             $available_editors = $this->locateAvailableEditors();
             $filtered = [];
             foreach ($available_editors['X'] as $path => $name) {
                 if (!in_array($path, $banned_editors)) {
                     $filtered[$path] = $name;
                 }
             }
             $available_editors['X'] = $filtered;
             $filtered = [];
             foreach ($available_editors['term'] as $path => $name) {
                 if (!in_array($path, $banned_editors)) {
                     $filtered[$path] = $name;
                 }
             }
             $available_editors['term'] = $filtered;
             $num = count($available_editors['X']) + count($available_editors['term']);
             if ($num == 1) {
                 $this->preferredEditor = current(array_keys(array_merge($available_editors['X'], $available_editors['term'])));
             } else {
                 if ($num == 0) {
                     cli\out('No text editor was found at common locations. ');
                     $editor = false;
                     while (!file_exists($editor)) {
                         $editor = cli\prompt('Enter the path to your text editor');
                     }
                 } else {
                     $choices = array_map(function ($item) {
                         return $item . ' (GUI)';
                     }, $available_editors['X']);
                     $choices += $available_editors['term'];
                     cli\out("The following text editors were found on your system:\n");
                     $this->preferredEditor = cli\menu($choices, current(array_keys($choices)), 'Enter the number of the editor you prefer');
                 }
             }
         }
     }
     return $this->preferredEditor;
 }