Esempio n. 1
0
 public function zfAction()
 {
     if (!extension_loaded('zip')) {
         return $this->sendError('You need to install the ZIP extension of PHP');
     }
     $console = $this->getServiceLocator()->get('console');
     $tmpDir = sys_get_temp_dir();
     $request = $this->getRequest();
     $version = $request->getParam('version');
     $path = rtrim($request->getParam('path'), '/');
     if (file_exists($path)) {
         return $this->sendError("The directory {$path} already exists. You cannot install the ZF2 library here.");
     }
     if (empty($version)) {
         $version = Zf::getLastVersion();
         if (false === $version) {
             return $this->sendError("I cannot connect to the Zend Framework website.");
         }
     } else {
         if (!Zf::checkVersion($version)) {
             return $this->sendError("The specified ZF version, {$version}, doesn't exist.");
         }
     }
     $tmpFile = ZF::getTmpFileName($tmpDir, $version);
     if (!file_exists($tmpFile)) {
         if (!Zf::downloadZip($tmpFile, $version)) {
             return $this->sendError("I cannot download the ZF2 library from github.");
         }
     }
     $zip = new \ZipArchive();
     if ($zip->open($tmpFile)) {
         $zipFolders = $zip->statIndex(0);
         $zipFolder = $tmpDir . '/' . rtrim($zipFolders['name'], "/");
         if (!$zip->extractTo($tmpDir)) {
             return $this->sendError("Error during the unzip of {$tmpFile}.");
         }
         $result = Utility::copyFiles($zipFolder, $path);
         if (file_exists($zipFolder)) {
             Utility::deleteFolder($zipFolder);
         }
         $zip->close();
         if (false === $result) {
             return $this->sendError("Error during the copy of the files in {$path}.");
         }
     }
     $console->writeLine("The ZF library {$version} has been installed in {$path}.", Color::GREEN);
 }
Esempio n. 2
0
 public function testDeleteFolder()
 {
     $result = Utility::deleteFolder($this->tmp);
     $this->assertTrue($result);
     $this->assertFalse(file_exists($this->tmp));
 }
Esempio n. 3
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');
 }
Esempio n. 4
0
 /**
  * @return mixed
  */
 public function zfAction()
 {
     // check for help mode
     if ($this->requestOptions->getFlagHelp()) {
         return $this->zfHelp();
     }
     // output header
     $this->consoleHeader('Installing Zend Framework 2 library');
     // check for zip extension
     if (!extension_loaded('zip')) {
         return $this->sendError(array(array(Color::NORMAL => 'You need to install the ZIP extension of PHP.')));
     }
     // get needed options to shorten code
     $path = $this->requestOptions->getPath();
     $tmpDir = $this->requestOptions->getTmpDir();
     $version = $this->requestOptions->getVersion();
     // check if path provided
     if ($path == '.') {
         return $this->sendError(array(array(Color::NORMAL => 'Please provide the path to install the ZF2 library 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 install the ZF2 library here.')));
     }
     // check version
     if (empty($version)) {
         $version = Zf::getLastVersion();
         if (false === $version) {
             return $this->sendError(array(array(Color::NORMAL => 'I cannot connect to the Zend Framework website.')));
         }
     } else {
         if (!Zf::checkVersion($version)) {
             return $this->sendError(array(array(Color::NORMAL => 'The specified ZF version, '), array(Color::RED => $version), array(Color::NORMAL => ' does not exist.')));
         }
     }
     // get tmp file and check it
     $tmpFile = ZF::getTmpFileName($tmpDir, $version);
     if (!file_exists($tmpFile)) {
         if (!Zf::downloadZip($tmpFile, $version)) {
             return $this->sendError(array(array(Color::NORMAL => 'I cannot download the ZF2 library from GitHub.')));
         }
     }
     // unzip archive
     $zip = new \ZipArchive();
     if ($zip->open($tmpFile)) {
         $zipFolders = $zip->statIndex(0);
         $zipFolder = $tmpDir . '/' . rtrim($zipFolders['name'], "/");
         if (!$zip->extractTo($tmpDir)) {
             return $this->sendError(array(array(Color::NORMAL => 'Error during the unzip of '), array(Color::RED => $tmpFile)));
         }
         $result = Utility::copyFiles($zipFolder, $path);
         if (file_exists($zipFolder)) {
             Utility::deleteFolder($zipFolder);
         }
         $zip->close();
         if (false === $result) {
             return $this->sendError(array(array(Color::NORMAL => 'Error during the copy of the files in '), array(Color::RED => $path)));
         }
     }
     $this->console->write(' Done ', Color::NORMAL, Color::CYAN);
     $this->console->write(' ');
     $this->console->write('The ZF library ');
     $this->console->write($version, Color::GREEN);
     $this->console->write(' has been installed in ');
     $this->console->writeLine(realpath($path), Color::GREEN);
     // output footer
     $this->consoleFooter('library was successfully installed');
 }
Esempio n. 5
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");
 }