public static function primaryNamespace($package)
    {
        $primaryNs = null;
        $autoLoad = $package->getAutoload();
        foreach ($autoLoad as $type => $pathMap) {
            if ($type !== 'psr-4') {
                continue;
            }
            $count = count($pathMap);

            if ($count === 1) {
                $primaryNs = key($pathMap);
                break;
            }

            $matches = preg_grep('#^(\./)?src/?$#', $pathMap);
            if ($matches) {
                $primaryNs = key($matches);
                break;
            }

            foreach (['', '.'] as $path) {
                $key = array_search($path, $pathMap, true);
                if ($key !== false) {
                    $primaryNs = $key;
                }
            }
            break;
        }

        if (!$primaryNs) {
            throw new RuntimeException(
                sprintf(
                    "Unable to get primary namespace for package %s." .
                    "\nEnsure you have added proper 'autoload' section to your plugin's config.",
                    $package->getName()
                )
            );
        }
        return trim($primaryNs, '\\');
    }
public static function primaryNamespace($package)
    {
        $primaryNs = null;
        $autoLoad = $package->getAutoload();
        foreach ($autoLoad as $type => $pathMap) {
            if ($type !== 'psr-4') {
                continue;
            }
            $count = count($pathMap);

            if ($count === 1) {
                $primaryNs = key($pathMap);
                break;
            }

            $matches = preg_grep('#^(\./)?src/?$#', $pathMap);
            if ($matches) {
                $primaryNs = key($matches);
                break;
            }

            foreach (['', '.'] as $path) {
                $key = array_search($path, $pathMap, true);
                if ($key !== false) {
                    $primaryNs = $key;
                }
            }
            break;
        }

        if (!$primaryNs) {
            throw new RuntimeException(
                sprintf(
                    "Unable to get primary namespace for package %s." .
                    "\nEnsure you have added proper 'autoload' section to your plugin's config.",
                    $package->getName()
                )
            );
        }
        return trim($primaryNs, '\\');
    }
public static function primaryNamespace ( $ package ) { $ primaryNs = null ; $ autoLoad = $ package -> getAutoload ( ) ; foreach ( $ autoLoad as $ type => $ pathMap ) { if ( $ type !== 'psr-4' ) { continue ; } $ count = count ( $ pathMap ) ; if ( $ count === 1 ) { $ primaryNs = key ( $ pathMap ) ; break ; } $ matches = preg_grep ( '#^(\./)?src/?$#' , $ pathMap ) ; if ( $ matches ) { $ primaryNs = key ( $ matches ) ; break ; } foreach ( [ '' , '.' ] as $ path ) { $ key = array_search ( $ path , $ pathMap , true ) ; if ( $ key !== false ) { $ primaryNs = $ key ; } } break ; } if ( ! $ primaryNs ) { throw new RuntimeException ( sprintf ( "Unable to get primary namespace for package %s." . "\nEnsure you have added proper 'autoload' section to your plugin's config." , $ package -> getName ( ) ) ) ; } return trim ( $ primaryNs , '\\' ) ; }
Get the primary namespace for a plugin package.

@param \Composer\Package\PackageInterface $package composer object.

@return string The package's primary namespace.

@throws \RuntimeException When the package's primary namespace cannot be determined.
Get the primary namespace for a plugin package .