/**
  * Set installer-name based on namespace for the source path checking in
  * following order:
  *
  * - With only one autoload path the namespace for that path will be used.
  * - With multiple paths if path 'src' exists it's namespace will be used.
  * - With two autoload paths provided, the namespace of path other than
  *   'tests' will be used.
  *
  * No installer-name is set if PSR-4 autoload block is not found or if none
  * of the above conditions are met.
  *
  * @param PackageInterface $package
  */
 protected function setInstallerName(PackageInterface $package)
 {
     $primaryNS = null;
     $autoLoad = $package->getAutoload();
     foreach ($autoLoad as $type => $typeConfig) {
         if ($type !== 'psr-4') {
             continue;
         }
         $count = count($typeConfig);
         if ($count === 1) {
             $primaryNS = key($typeConfig);
             break;
         }
         $matches = preg_grep('#^(\\./)?src/?$#', $typeConfig);
         if ($matches) {
             $primaryNS = key($matches);
             break;
         }
         if ($count === 2) {
             reset($typeConfig);
             if (preg_match('#^(\\./)?tests/?$#', current($typeConfig))) {
                 next($typeConfig);
             }
             $primaryNS = key($typeConfig);
             break;
         }
         break;
     }
     if ($primaryNS) {
         $package->setExtra(array('installer-name' => trim(str_replace('\\', '/', $primaryNS), '/')));
     }
 }
Example #2
0
 /**
  * Set installer-name based on namespace for the source path
  *
  * With one autoload path this will be used as installer-name.
  * With two autoload paths the first non `tests` foldername will be set.
  * If more then 2 autoload paths are provided, installer-name will only be
  * set for if `src` folder is used.
  *
  * @param PackageInterface $package
  */
 protected function setInstallerName(PackageInterface $package)
 {
     $autoLoad = $package->getAutoload();
     foreach ($autoLoad as $type => $typeConfig) {
         if ($type !== 'psr-4') {
             continue;
         }
         $count = count($typeConfig);
         foreach ($typeConfig as $namespace => $path) {
             if ($path === 'tests') {
                 continue;
             }
             if ($count > 2 && $path !== 'src') {
                 continue;
             }
             $installerName = trim(str_replace('\\', '/', $namespace), '/');
             $package->setExtra(array('installer-name' => $installerName));
         }
         break;
     }
 }
Example #3
0
 /**
  * Adds the main file definitions from the root package.
  *
  * @param Composer         $composer
  * @param PackageInterface $package
  * @param string           $section
  */
 public static function addMainFiles(Composer $composer, PackageInterface $package, $section = 'asset-main-files')
 {
     if ($package instanceof \Composer\Package\Package) {
         $packageExtra = $package->getExtra();
         $extra = $composer->getPackage()->getExtra();
         if (isset($extra[$section])) {
             foreach ($extra[$section] as $packageName => $files) {
                 if ($packageName === $package->getName()) {
                     $packageExtra['bower-asset-main'] = $files;
                     break;
                 }
             }
         }
         $package->setExtra($packageExtra);
     }
     return $package;
 }