public function testGetLastZip()
 {
     $tmpFile = sys_get_temp_dir() . '/' . Skeleton::SKELETON_FILE . '_test.zip';
     Skeleton::getSkeletonApp($tmpFile);
     if (file_exists($tmpFile)) {
         $result = Skeleton::getLastZip(sys_get_temp_dir());
         $this->assertTrue(!empty($result));
         unlink($tmpFile);
     } else {
         $this->markTestSkipped('The ZF2 Skeleton github repository is not accessible.');
     }
 }
Beispiel #2
0
 /**
  * Create a project
  *
  * @return ConsoleModel
  */
 public function projectAction()
 {
     // check for help mode
     if ($this->requestOptions->getFlagHelp()) {
         return $this->projectHelp();
     }
     // output header
     $this->consoleHeader('Creating new Zend Framework 2 project');
     // check for zip extension
     if (!extension_loaded('zip')) {
         return $this->sendError(array(array(Color::NORMAL => 'You need to install the ZIP extension of PHP.')));
     }
     // check for openssl extension
     if (!extension_loaded('openssl')) {
         return $this->sendError(array(array(Color::NORMAL => 'You need to install the OpenSSL extension of PHP.')));
     }
     // get needed options to shorten code
     $path = $this->requestOptions->getPath();
     $tmpDir = $this->requestOptions->getTmpDir();
     // check if path provided
     if ($path == '.') {
         return $this->sendError(array(array(Color::NORMAL => 'Please provide the path to create the project in.')));
     }
     // check if path exists
     if (file_exists($path)) {
         return $this->sendError(array(array(Color::NORMAL => 'The directory '), array(Color::RED => $path), array(Color::NORMAL => ' already exists. '), array(Color::NORMAL => 'You cannot create a ZF2 project here.')));
     }
     // check last commit
     $commit = Skeleton::getLastCommit();
     if (false === $commit) {
         // error on github connection
         $tmpFile = Skeleton::getLastZip($tmpDir);
         if (empty($tmpFile)) {
             return $this->sendError(array(array(Color::NORMAL => 'I cannot access the API of GitHub.')));
         }
         $this->console->writeLine('Warning: I cannot connect to GitHub, I will use the last ' . 'download of ZF2 Skeleton.', Color::LIGHT_RED);
     } else {
         $tmpFile = Skeleton::getTmpFileName($tmpDir, $commit);
     }
     // check for Skeleton App
     if (!file_exists($tmpFile)) {
         if (!Skeleton::getSkeletonApp($tmpFile)) {
             return $this->sendError(array(array(Color::NORMAL => 'I cannot access the ZF2 skeleton application in GitHub.')));
         }
     }
     // set Zip Archive
     $zip = new \ZipArchive();
     if ($zip->open($tmpFile)) {
         $stateIndex0 = $zip->statIndex(0);
         $tmpSkeleton = $tmpDir . '/' . rtrim($stateIndex0['name'], "/");
         if (!$zip->extractTo($tmpDir)) {
             return $this->sendError(array(array(Color::NORMAL => 'Error during the unzip of '), array(Color::RED => $tmpFile), array(Color::NORMAL => '.')));
         }
         $result = Utility::copyFiles($tmpSkeleton, $path);
         if (file_exists($tmpSkeleton)) {
             Utility::deleteFolder($tmpSkeleton);
         }
         $zip->close();
         if (false === $result) {
             return $this->sendError(array(array(Color::NORMAL => 'Error during the copy of the files in '), array(Color::RED => $path), array(Color::NORMAL => '.')));
         }
     }
     // check for composer
     if (file_exists($path . '/composer.phar')) {
         exec('php ' . $path . '/composer.phar self-update');
     } else {
         if (!file_exists($tmpDir . '/composer.phar')) {
             if (!file_exists($tmpDir . '/composer_installer.php')) {
                 file_put_contents($tmpDir . '/composer_installer.php', '?>' . file_get_contents('https://getcomposer.org/installer'));
             }
             exec('php ' . $tmpDir . '/composer_installer.php --install-dir ' . $tmpDir);
         }
         copy($tmpDir . '/composer.phar', $path . '/composer.phar');
     }
     chmod($path . '/composer.phar', 0755);
     $this->console->write(' Done ', Color::NORMAL, Color::CYAN);
     $this->console->write(' ');
     $this->console->write('ZF2 skeleton application installed in ');
     $this->console->writeLine(realpath($path), Color::GREEN);
     $this->console->writeLine();
     $this->console->writeLine('       => In order to execute the skeleton application you need to install the ZF2 library.');
     $this->console->write('       => Execute: ');
     $this->console->write('composer.phar install', Color::GREEN);
     $this->console->write(' in ');
     $this->console->writeLine(realpath($path), Color::GREEN);
     $this->console->write('       => For more info please read ');
     $this->console->writeLine(realpath($path) . '/README.md', Color::GREEN);
     // output footer
     $this->consoleFooter('project was successfully created');
 }
Beispiel #3
0
 public function projectAction()
 {
     if (!extension_loaded('zip')) {
         return $this->sendError('You need to install the ZIP extension of PHP');
     }
     if (!extension_loaded('openssl')) {
         return $this->sendError('You need to install the OpenSSL extension of PHP');
     }
     $console = $this->getServiceLocator()->get('console');
     $tmpDir = sys_get_temp_dir();
     $request = $this->getRequest();
     $path = rtrim($request->getParam('path'), '/');
     if (file_exists($path)) {
         return $this->sendError("The directory {$path} already exists. You cannot create a ZF2 project here.");
     }
     $commit = Skeleton::getLastCommit();
     if (false === $commit) {
         // error on github connection
         $tmpFile = Skeleton::getLastZip($tmpDir);
         if (empty($tmpFile)) {
             return $this->sendError('I cannot access the API of github.');
         }
         $console->writeLine("Warning: I cannot connect to github, I will use the last download of ZF2 Skeleton.", Color::GRAY);
     } else {
         $tmpFile = Skeleton::getTmpFileName($tmpDir, $commit);
     }
     if (!file_exists($tmpFile)) {
         if (!Skeleton::getSkeletonApp($tmpFile)) {
             return $this->sendError('I cannot access the ZF2 skeleton application in github.');
         }
     }
     $zip = new \ZipArchive();
     if ($zip->open($tmpFile)) {
         $stateIndex0 = $zip->statIndex(0);
         $tmpSkeleton = $tmpDir . '/' . rtrim($stateIndex0['name'], "/");
         if (!$zip->extractTo($tmpDir)) {
             return $this->sendError("Error during the unzip of {$tmpFile}.");
         }
         $result = Utility::copyFiles($tmpSkeleton, $path);
         if (file_exists($tmpSkeleton)) {
             Utility::deleteFolder($tmpSkeleton);
         }
         $zip->close();
         if (false === $result) {
             return $this->sendError("Error during the copy of the files in {$path}.");
         }
     }
     if (file_exists("{$path}/composer.phar")) {
         exec("php {$path}/composer.phar self-update");
     } else {
         if (!file_exists("{$tmpDir}/composer.phar")) {
             if (!file_exists("{$tmpDir}/composer_installer.php")) {
                 file_put_contents("{$tmpDir}/composer_installer.php", '?>' . file_get_contents('https://getcomposer.org/installer'));
             }
             exec("php {$tmpDir}/composer_installer.php --install-dir {$tmpDir}");
         }
         copy("{$tmpDir}/composer.phar", "{$path}/composer.phar");
     }
     chmod("{$path}/composer.phar", 0755);
     $console->writeLine("ZF2 skeleton application installed in {$path}.", Color::GREEN);
     $console->writeLine("In order to execute the skeleton application you need to install the ZF2 library.");
     $console->writeLine("Execute: \"composer.phar install\" in {$path}");
     $console->writeLine("For more info in {$path}/README.md");
 }