Get the source configuration directory to publish.

@param  string  $package
@param  string  $name
@param  string  $packagePath
@return string

@throws \InvalidArgumentException
14432
protected function getSource($package, $name, $packagePath)
	{
		$source = $packagePath."/{$package}/src/config";

		if ( ! $this->files->isDirectory($source))
		{
			throw new \InvalidArgumentException("Configuration not found.");
		}

		return $source;
	}
1158810
protected function package($name)
    {
        $exists = in_array($name, array_keys($this->packages));

        if ($exists === false || ! class_exists($this->packages[$name])) {
            $message = 'Package "' . $name . '" does not exists!';

            throw new \InvalidArgumentException((string) $message);
        }

        $function = array(new $this->packages[$name], $this->type);

        if (! $source = call_user_func_array($function, array())) {
            $message = '"%s" does not provide a path for the list of %s!';

            $message = sprintf($message, ucfirst($name), $this->type);

            throw new \InvalidArgumentException((string) $message);
        }

        return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $source);
    }
37698
public function publishPackage($package, $packagePath = null)
	{
		list($vendor, $name) = explode('/', $package);

		// First we will figure out the source of the package's configuration location
		// which we do by convention. Once we have that we will move the files over
		// to the "main" configuration directory for this particular application.
		$path = $packagePath ?: $this->packagePath;

		$source = $this->getSource($package, $name, $path);

		return $this->publish($package, $source);
	}
886234
public function getUrl($name, $includeBasePath = true)
    {
        if ($this->callerNotSelfOrPathsProxy()) {
            Deprecated::method(3.3, 'Use UrlGenerator or Asset Packages instead.');
        }

        if (($name === 'canonical' || $name === 'canonicalurl') && isset($this->app['canonical'])) {
            if ($url = $this->app['canonical']->getUrl()) {
                return $url;
            }
        }

        if (!$this->requestInitialized && $this->app) {
            $this->initializeRequest($this->app, $this->requestObject);
        }

        if (!$this->configInitialized && in_array($name, ['theme', 'bolt', 'templates', 'templatespath'])) {
            $this->initializeConfig();
        }

        if (array_key_exists($name . 'url', $this->urls) && $name !== 'root') {
            return $this->urls[$name . 'url'];
        }
        if (! array_key_exists($name, $this->urls)) {
            throw new \InvalidArgumentException("Requested url $name is not available", 1);
        }

        $url = $this->urls[$name];

        if (!$includeBasePath || strpos($url, 'http') === 0 || strpos($url, '//') === 0) {
            return $url;
        }

        return $this->urlPrefix . $url;
    }
1295496
private function updateConfigFile(PackageInterface $package)
    {
        $defaultConfigFile = $this->projectPath . self::DS .
            'App' . self::DS . 'Resource' . self::DS . 'config' . self::DS . 'config.default.php';

        if (is_writeable($defaultConfigFile)) {
            $output = include $defaultConfigFile;
            $bundleConf = [
                'bundles' => [
                    $this->getPackageName($package) => []
                ]
            ];

            $data = array_merge($output, $bundleConf);

            if (false === file_put_contents($defaultConfigFile, '<?php return ' . var_export($data, true) . ';')) {
                throw new RuntimeException(sprintf('Cannot update config file "%s"', $defaultConfigFile));
            }
        }
    }
883192
public function publishPackage($package, $packagePath = null)
    {
        $source = $this->getSource($package, $packagePath ?: $this->packagePath);

        return $this->publish($package, $source);
    }
1221737
protected static function calculateResourcePathname($filenamePath, $source)
    {
        $sourceFile = preg_replace("/'/", "", $source[1]);
        if (preg_match('/\#/', $sourceFile)) {
            $sourceFile = explode("#", $sourceFile);
            $sourceFile = $sourceFile[0];
        }
        if (preg_match('/\?/', $sourceFile)) {
            $sourceFile = explode("?", $sourceFile);
            $sourceFile = $sourceFile[0];
        }
        $orig = realpath(dirname($filenamePath) . DIRECTORY_SEPARATOR . $sourceFile);
        return $orig;
    }
1250694
public static function ModulePath($name)
    {
        // BC for a couple fo the key modules in the old syntax. Reduces merge brittleness but can
        // be removed before 4.0 stable
        $legacyMapping = [
            'framework' => 'silverstripe/framework',
            'frameworkadmin' => 'silverstripe/admin',
        ];
        if (isset($legacyMapping[$name])) {
            $name = $legacyMapping[$name];
        }

        return ModuleLoader::getModule($name)->getRelativePath();
    }
1241218
public function package($package, $namespace = null, $path = null)
    {
        $namespace = $this->getPackageNamespace($package, $namespace);
        $files     = $this->app->make('files');

        $path = $path ? : $this->guessPackagePath();

        if ($files->isDirectory($config = $path . '/config')) {
            $this->addConfigComponent($package, $namespace, $config);
        }


        if ($files->isDirectory($lang = $path . '/lang')) {
            $this->addLanguageComponent($package, $namespace, $lang);
        }


        if ($files->isDirectory($views = $path . '/views')) {
            $this->addViewComponent($package, $namespace, $views);
        }
    }
982207
public function parseDirectory($packageHandle, $packageVersion, $path, $relDirectory = '', $searchDictionaryFiles = self::DICTIONARY_ALL)
    {
        if (!$this->filesystem->isDirectory($path)) {
            throw new UserMessageException(t('Unable to find the directory %s', $path));
        }
        if ('' === (string) $relDirectory && '' !== (string) $packageHandle) {
            switch ($packageHandle) {
                case 'concrete5':
                    $relDirectory = 'concrete';
                    break;
                default:
                    $relDirectory = 'packages/' . $packageHandle;
                    break;
            }
        }
        $result = null;
        $pot = new Translations();
        $pot->setLanguage($this->app->make('community_translation/sourceLocale'));
        C5TLParser::clearCache();
        $m = null;
        if (preg_match('/^' . preg_quote(Version::DEV_PREFIX, '/') . '(\d+(?:\.\d+)*)/', $packageVersion, $m)) {
            $checkVersion = $m[1] . '.99.99';
        } else {
            $checkVersion = $packageVersion;
        }
        foreach (C5TLParser::getAllParsers() as $parser) {
            /* @var C5TLParser $parser */
            if ($parser->canParseDirectory()) {
                if ($packageHandle !== 'concrete5' || $parser->canParseConcreteVersion($checkVersion)) {
                    $parser->parseDirectory($path, $relDirectory, $pot);
                }
            }
        }
        if (count($pot) > 0) {
            $result = new Parsed();
            $result->setSourceStrings($pot);
        }
        if ($searchDictionaryFiles !== self::DICTIONARY_NONE) {
            foreach ($this->filesystem->allFiles($path) as $file) {
                $kind = self::DICTIONARY_NONE;
                switch (strtolower($file->getExtension())) {
                    case 'pot':
                        if ($searchDictionaryFiles & self::DICTIONARY_SOURCE) {
                            $kind = self::DICTIONARY_SOURCE;
                        }
                        break;
                    case 'po':
                        if ($searchDictionaryFiles & self::DICTIONARY_LOCALIZED_SOURCE) {
                            $kind = self::DICTIONARY_LOCALIZED_SOURCE;
                        }
                        break;
                    case 'mo':
                        if ($searchDictionaryFiles & self::DICTIONARY_LOCALIZED_COMPILED) {
                            $kind = self::DICTIONARY_LOCALIZED_COMPILED;
                        }
                        break;
                }
                if ($kind === self::DICTIONARY_NONE) {
                    continue;
                }
                $parsed = $this->parseDictionaryFile($packageHandle, $packageVersion, $file->getPathname(), $kind);
                if ($parsed !== null) {
                    if ($result === null) {
                        $result = $parsed;
                    } else {
                        $result->mergeWith($parsed);
                    }
                }
            }
        }

        return $result;
    }
678963
protected function findNamedPathView($name)
    {
        list($namespace, $view) = $this->getNamespaceSegments($name);

        $paths = $this->hints[$namespace];

        if (Str::endsWith($path = head($this->paths), DS .'Overrides')) {
            $path = $path .DS .'Packages' .DS .$namespace;

            if (! in_array($path, $paths) && $this->files->isDirectory($path)) {
                array_unshift($paths, $path);
            }
        }

        return $this->findInPaths($view, $paths);
    }
650145
protected function getCustomVendorPathFromComposer($composerConfigurationPath)
    {
        $composerFile = file_get_contents($composerConfigurationPath);
        $composerJson = json_decode($composerFile, true);

        return isset($composerJson['config']['vendor-dir']) ? $composerJson['config']['vendor-dir'] : 'vendor';
    }
1242106
private function loadConfiguration($filePath)
    {
        if (!is_file($filePath)) {
            throw new \InvalidArgumentException(sprintf('The configuration file "%s" does not exit', $filePath));
        }

        $config = include $filePath;

        if (!$config instanceof Configuration) {
            throw new \InvalidArgumentException(
                sprintf(
                    'The configuration file "%s" must return a "Akeneo\CouplingDetector\Configuration\Configuration"',
                    $filePath
                )
            );
        }

        return $config;
    }
1108486
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, '\\');
    }
248067
protected function findBestVersionForPackage(string $name): string
    {
        // find the latest version allowed in this pool
        $package = $this->versionSelector->findBestCandidate($name, null, null, 'stable');

        if ($package === false) {
            throw new InvalidArgumentException(\sprintf(
                'Could not find package %s at any version for your minimum-stability (%s).'
                . ' Check the package spelling or your minimum-stability.',
                $name,
                $this->stability
            ));
        }

        return $this->versionSelector->findRecommendedRequireVersion($package);
    }
1151607
protected function getRootPath(PackageInterface $package)
    {
        $rootPath = $this->vendorDir . '/raulfraile/ladybug-themes/Ladybug/';

        if ($this->composer->getPackage()->getName() === 'raulfraile/ladybug') {
            $rootPath = 'data/' . ($package->getType() === self::PACKAGE_TYPE_THEME ? 'themes' : 'plugins') . '/Ladybug/';
        }

        $rootPath .= ($package->getType() === self::PACKAGE_TYPE_THEME) ? 'Theme' : 'Plugin';

        return $rootPath;
    }
1275292
private function getPackageByName(iterable $packages, string $name): ?PackageInterface
    {
        foreach ($packages as $package) {
            if ($package->getName() === $name) {
                return $package;
            }
        }

        return null;
    }