/**
  * Scans all directories in the packages directories for available packages.
  * For each package a Package object is created and stored in $this->packages.
  *
  * @return void
  * @throws \TYPO3\Flow\Package\Exception\DuplicatePackageException
  */
 protected function scanAvailablePackages()
 {
     $previousPackageStatesConfiguration = $this->packageStatesConfiguration;
     if (isset($this->packageStatesConfiguration['packages'])) {
         foreach ($this->packageStatesConfiguration['packages'] as $packageKey => $configuration) {
             if (!file_exists($this->packagesBasePath . $configuration['packagePath'])) {
                 unset($this->packageStatesConfiguration['packages'][$packageKey]);
             }
         }
     } else {
         $this->packageStatesConfiguration['packages'] = array();
     }
     $packagePaths = array();
     foreach (new \DirectoryIterator($this->packagesBasePath) as $parentFileInfo) {
         $parentFilename = $parentFileInfo->getFilename();
         if ($parentFilename[0] !== '.' && $parentFileInfo->isDir()) {
             $packagePaths = array_merge($packagePaths, $this->scanPackagesInPath($parentFileInfo->getPathName()));
         }
     }
     /**
      * @todo similar functionality in registerPackage - should be refactored
      */
     foreach ($packagePaths as $packagePath => $composerManifestPath) {
         try {
             $composerManifest = self::getComposerManifest($composerManifestPath);
             $packageKey = PackageFactory::getPackageKeyFromManifest($composerManifest, $packagePath, $this->packagesBasePath);
             $this->composerNameToPackageKeyMap[strtolower($composerManifest->name)] = $packageKey;
             $this->packageStatesConfiguration['packages'][$packageKey]['manifestPath'] = substr($composerManifestPath, strlen($packagePath)) ?: '';
             $this->packageStatesConfiguration['packages'][$packageKey]['composerName'] = $composerManifest->name;
         } catch (MissingPackageManifestException $exception) {
             $relativePackagePath = substr($packagePath, strlen($this->packagesBasePath));
             $packageKey = substr($relativePackagePath, strpos($relativePackagePath, '/') + 1, -1);
         }
         if (!isset($this->packageStatesConfiguration['packages'][$packageKey]['state'])) {
             /**
              * @todo doesn't work, settings not available at this time
              */
             if (is_array($this->settings['package']['inactiveByDefault']) && in_array($packageKey, $this->settings['package']['inactiveByDefault'], true)) {
                 $this->packageStatesConfiguration['packages'][$packageKey]['state'] = 'inactive';
             } else {
                 $this->packageStatesConfiguration['packages'][$packageKey]['state'] = 'active';
             }
         }
         $this->packageStatesConfiguration['packages'][$packageKey]['packagePath'] = str_replace($this->packagesBasePath, '', $packagePath);
         // Change this to read the target from Composer or any other source
         $this->packageStatesConfiguration['packages'][$packageKey]['classesPath'] = Package::DIRECTORY_CLASSES;
     }
     $this->registerPackagesFromConfiguration();
     if ($this->packageStatesConfiguration != $previousPackageStatesConfiguration) {
         $this->sortAndSavePackageStates();
     }
 }
Exemplo n.º 2
0
 /**
  * Resolves package key from Composer manifest
  *
  * If it is a Flow package the name of the containing directory will be used.
  *
  * Else if the composer name of the package matches the first part of the lowercased namespace of the package, the mixed
  * case version of the composer name / namespace will be used, with backslashes replaced by dots.
  *
  * Else the composer name will be used with the slash replaced by a dot
  *
  * @param object $manifest
  * @param string $packagePath
  * @param string $packagesBasePath
  * @throws \TYPO3\Flow\Package\Exception\InvalidPackageManifestException
  * @return string
  */
 public static function getPackageKeyFromManifest($manifest, $packagePath, $packagesBasePath)
 {
     if (!is_object($manifest)) {
         throw new \TYPO3\Flow\Package\Exception\InvalidPackageManifestException('Invalid composer manifest in package path: ' . $packagePath, 1348146451);
     }
     if (isset($manifest->type) && substr($manifest->type, 0, 10) === 'typo3-cms-') {
         $relativePackagePath = substr($packagePath, strlen($packagesBasePath));
         $packageKey = substr($relativePackagePath, strpos($relativePackagePath, '/') + 1, -1);
         /**
          * @todo check that manifest name and directory follows convention
          */
         $packageKey = preg_replace('/[^A-Za-z0-9._-]/', '', $packageKey);
         return $packageKey;
     } else {
         return parent::getPackageKeyFromManifest($manifest, $packagePath, $packagesBasePath);
     }
 }