detect() public method

Start Magento detection
public detect ( string $folder, array $subFolders = [] ) : boolean
$folder string
$subFolders array [optional] sub-folders to check
return boolean
Exemplo n.º 1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function chooseInstallationFolder(InputInterface $input, OutputInterface $output)
 {
     $validateInstallationFolder = function ($folderName) use($input) {
         $folderName = rtrim(trim($folderName, ' '), '/');
         if (substr($folderName, 0, 1) == '.') {
             $cwd = \getcwd();
             if (empty($cwd) && isset($_SERVER['PWD'])) {
                 $cwd = $_SERVER['PWD'];
             }
             $folderName = $cwd . substr($folderName, 1);
         }
         if (empty($folderName)) {
             throw new \InvalidArgumentException('Installation folder cannot be empty');
         }
         if (!is_dir($folderName)) {
             if (!@mkdir($folderName, 0777, true)) {
                 throw new \InvalidArgumentException('Cannot create folder.');
             }
             return $folderName;
         }
         if ($input->hasOption('noDownload') && $input->getOption('noDownload')) {
             /** @var MagentoHelper $magentoHelper */
             $magentoHelper = new MagentoHelper();
             $magentoHelper->detect($folderName);
             if ($magentoHelper->getRootFolder() !== $folderName) {
                 throw new \InvalidArgumentException(sprintf('Folder %s is not a Magento working copy.', $folderName));
             }
             $localXml = $folderName . '/app/etc/local.xml';
             if (file_exists($localXml)) {
                 throw new \InvalidArgumentException(sprintf('Magento working copy in %s seems already installed. Please remove %s and retry.', $folderName, $localXml));
             }
         }
         return $folderName;
     };
     if (($installationFolder = $input->getOption('installationFolder')) == null) {
         $defaultFolder = './magento';
         $question[] = "<question>Enter installation folder:</question> [<comment>" . $defaultFolder . "</comment>]";
         $installationFolder = $this->getHelper('dialog')->askAndValidate($output, $question, $validateInstallationFolder, false, $defaultFolder);
     } else {
         // @Todo improve validation and bring it to 1 single function
         $installationFolder = $validateInstallationFolder($installationFolder);
     }
     $this->config['installationFolder'] = realpath($installationFolder);
     \chdir($this->config['installationFolder']);
 }
Exemplo n.º 2
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param array|PackageInterface $config
  * @param string $targetFolder
  * @param bool $preferSource
  * @return \Composer\Package\CompletePackage
  */
 protected function downloadByComposerConfig(InputInterface $input, OutputInterface $output, $config, $targetFolder, $preferSource = true)
 {
     $dm = $this->getComposerDownloadManager($input, $output);
     if (!$config instanceof PackageInterface) {
         $package = $this->createComposerPackageByConfig($config);
     } else {
         $package = $config;
     }
     $helper = new \N98\Util\Console\Helper\MagentoHelper();
     $helper->detect($targetFolder);
     if ($this->isSourceTypeRepository($package->getSourceType()) && $helper->getRootFolder() == $targetFolder) {
         $package->setInstallationSource('source');
         $this->checkRepository($package, $targetFolder);
         $dm->update($package, $package, $targetFolder);
     } else {
         $dm->download($package, $targetFolder, $preferSource);
     }
     return $package;
 }