Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function run(ArrayAccess $paths)
 {
     $dest = $this->targetPath($paths);
     if (!$this->overwrite->should($dest)) {
         $this->io->comment("  - {$this->name} skipped.");
         return;
     }
     $this->actionSource[0] === 'download' ? $this->download($this->actionSource[1], $dest) : $this->copy($this->actionSource[1], $dest, $paths);
 }
Exemplo n.º 2
0
 /**
  * Fetch languages from wordpress.org API.
  *
  * @param  bool       $ssl
  * @return array|bool
  */
 private function fetchLanguages($ssl = true)
 {
     static $languages;
     if (!is_null($languages)) {
         return $languages;
     }
     $url = $ssl ? 'https' : 'http';
     $url .= '://api.wordpress.org/translations/core/1.0/?version=';
     $remote = new UrlDownloader($url . $this->config['wp-version']);
     $result = $remote->fetch(true);
     if (!$result) {
         return $ssl ? $this->fetchLanguages(false) : false;
     }
     try {
         $all = (array) json_decode($result, true);
         $languages = isset($all['translations']) ? array() : false;
         if (is_array($languages)) {
             foreach ($all['translations'] as $lang) {
                 $languages[] = $lang['language'];
             }
         }
     } catch (Exception $e) {
         $languages = false;
     }
     if ($languages === false) {
         $this->io->comment('Error on loading languages from wordpress.org');
     }
     return $languages;
 }
Exemplo n.º 3
0
 /**
  * Download .gitignore from a given url.
  *
  * @param  \ArrayAccess $paths
  * @return int
  */
 private function download(ArrayAccess $paths)
 {
     if (!UrlDownloader::checkSoftware()) {
         $this->io->comment('WP Starter needs cUrl installed to download files from url.');
         return $this->create($paths);
     }
     $remote = new UrlDownloader($this->config);
     if ($remote->save($this->targetPath($paths))) {
         return self::SUCCESS;
     }
     $this->error = 'Error on downloading and saving .gitignore. ' . $remote->error();
     return self::ERROR;
 }
Exemplo n.º 4
0
 /**
  * Download a remote .env.example in root folder.
  *
  * @param  string       $url
  * @param  string       $dest
  * @param  \ArrayAccess $paths
  * @return int
  */
 private function download($url, $dest, ArrayAccess $paths)
 {
     if (!UrlDownloader::checkSoftware()) {
         $this->io->comment('WP Starter needs cUrl installed to download files from url.');
         return $this->copy($paths, $dest);
     }
     $remote = new UrlDownloader($url);
     if (!$remote->save($dest)) {
         $this->error = 'Error on downloading and save .env.example: ' . $remote->error() . '.';
         return self::ERROR;
     }
     return self::SUCCESS;
 }
Exemplo n.º 5
0
 /**
  * @param  \WCM\WPStarter\Setup\Steps\StepInterface $step
  * @param  \ArrayAccess                             $paths
  * @return bool
  */
 private function shouldProcess(StepInterface $step, ArrayAccess $paths)
 {
     $comment = '';
     $process = $step->allowed($this->config, $paths);
     if ($process && $step instanceof FileStepInterface) {
         /** @var \WCM\WPStarter\Setup\Steps\FileStepInterface $step */
         $path = $step->targetPath($paths);
         $process = $this->overwrite->should($path);
         $comment = $process ? '' : '- ' . basename($path) . ' exists and will be preserved.';
     }
     if ($process && $step instanceof OptionalStepInterface) {
         /** @var \WCM\WPStarter\Setup\Steps\OptionalStepInterface $step */
         $process = $step->question($this->config, $this->io);
         $comment = $process ? '' : $step->skipped();
     }
     $process or $this->io->comment($comment);
     return $process;
 }