@param $file
@param $package

@return string
356104
private function getConfigFilename($file, $package)
    {
        $name = preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($file));

        $filename = $this->prefix.'.'.$package.'.'.$name;

        return $filename;
    }
319493
public static function inject($injector, $package)
    {
        $dir = __DIR__."/../../$package/src/Injectors";
        $files = is_dir($dir) ? scandir($dir) : [];

        foreach ($files as $file) {
            if (substr($file, 0, -4) == $injector and substr($file, -4) == '.php') {
                $file = $dir.'/'.$file;

                return include $file;
            }
        }

        return '';
    }
181454
private function getPackageDevName(string $package) {
		$bundle = explode("/", $package)[1];
		$explode = explode("-", $bundle);
		
		$package_name = "";
		
		foreach ($explode as $string) {
			$package_name .= ucfirst($string);
		}
		
		return $package_name;
	}
927427
public static function menu($package)
    {
        $dir = __DIR__.'/../../'.$package.'/src';
        $files = is_dir($dir) ? scandir($dir) : [];

        foreach ($files as $file) {
            if ($file == 'Menu.json') {
                $file_r = file_get_contents($dir.'/'.$file);

                return json_decode($file_r, true);
            }
        }

        return [];
    }
43684
public function getManifest($package)
    {
        if (is_array($package['extra'][self::EXTRA_FIELD])) {
            return $package['extra'][self::EXTRA_FIELD];
        } else if (is_string($package['extra'][self::EXTRA_FIELD])) {
            $manifestFile = $this->vendorPath . DIRECTORY_SEPARATOR . $package['name'] . DIRECTORY_SEPARATOR . $package['extra'][self::EXTRA_FIELD];
            if (is_file($manifestFile)) {
                return include($manifestFile);
            }
        }
        return [];
    }
154311
public static final function get(string $identify, string $package, Array $data = null): string {
    $text = $identify;
    if (!empty($identify)) {
      if ($language = Lang::loadPackage($package)) {
        if (isset($language->{$identify})) {
          $text = Lang::replace($language->{$identify}, $data);
        }
      }
    }
    return $text;
  }
350997
public function createManifest(Package $package)
    {
        $manifestData = array();
        foreach (Package::$packageFiles as $rawFile) {
            $filePath = sprintf('%s/%s', $package->getPackageDir(), $rawFile);
            $manifestData[$rawFile] = sha1(file_get_contents($filePath));
        }

        $manifestJsonPath = sprintf('%s/manifest.json', $package->getPackageDir());
        $manifestJson = json_encode((object) $manifestData);

        file_put_contents($manifestJsonPath, $manifestJson);

        return $manifestJsonPath;
    }
106385
public static function copyPackage($package_file, $tmp)
    {
        $package_file = realpath($package_file);

        if (file_exists($package_file)) {
            $filename = basename($package_file);
            Folder::create($tmp);
            copy(realpath($package_file), $tmp . DS . $filename);
            return $tmp . DS . $filename;
        }

        return null;
    }
162319
protected function getNamespace($file)
    {
        $basename = $this->packageInfo->get('basename');

        if ($this->packageInfo->get('type') == 'module') {
            $namespace = str_replace($this->packagesPath .DS .$basename, '', $file);
        } else {
            $namespace = str_replace($this->packagesPath .DS .$basename .DS .'src', '', $file);
        }

        $find = basename($namespace);

        $namespace = strrev(preg_replace(strrev("/$find/"), '', strrev($namespace), 1));

        $namespace = $this->packageInfo->get('namespace') .'\\' .trim($namespace, '\\/');

        return str_replace('/', '\\', $namespace);
    }
1271423
public function getForPackage($package, $key, $default = null)
    {
        if (empty($this->packagesConfiguration[$package])) {
            return $default;
        }
        return Arr::get($this->packagesConfiguration[$package], $key, $default);
    }
103016
private function downloadPackage($package, $license = null)
    {
        $tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true);
        $this->tmp = $tmp_dir . '/Grav-' . uniqid();
        $filename = $package->slug . basename($package->zipball_url);
        $filename = preg_replace('/[\\\\\/:"*?&<>|]+/m', '-', $filename);
        $query = '';

        if (!empty($package->premium)) {
            $query = \json_encode(array_merge(
                $package->premium,
                [
                    'slug' => $package->slug,
                    'filename' => $package->premium['filename'],
                    'license_key' => $license
                ]
            ));

            $query = '?d=' . base64_encode($query);
        }

        try {
            $output = Response::get($package->zipball_url . $query, [], [$this, 'progress']);
        } catch (\Exception $e) {
            $error = str_replace("\n", "\n  |  '- ", $e->getMessage());
            $this->output->write("\x0D");
            // extra white spaces to clear out the buffer properly
            $this->output->writeln('  |- Downloading package...    <red>error</red>                             ');
            $this->output->writeln("  |  '- " . $error);

            return false;
        }

        Folder::create($this->tmp);

        $this->output->write("\x0D");
        $this->output->write('  |- Downloading package...   100%');
        $this->output->writeln('');

        file_put_contents($this->tmp . DS . $filename, $output);

        return $this->tmp . DS . $filename;
    }
156513
public function getDestinationFilenameRelativeToProjectRoot(Metadata\TableOfContents\File $file): string
    {
        return substr($this->getDestinationFilename($file), strlen($this->fileset->getProjectRoot()));
    }
15774
protected function requirePackage(Package $package)
    {
        $version = $this->chooseVersion($package);
        passthru(sprintf(
            'composer require %s:%s',
            $package->getName(),
            $version
        ));
        $this->comment('Package ' . $package->getName() . ' installed');
        $versions = $package->getVersions();
        $v = array_get($versions, $version);

        // Run post-process in separate command to load it with new autoloader
        passthru(sprintf(
            'php artisan package:process %s %s',
            $package->getName(),
            base64_encode(serialize($v))
        ));
    }
1053362
protected function getPackageOptionFile($option)
    {
        $option = $this->getPackageOption($option);

        if ($option && file_exists($this->getPackageDir().$option)) {
            return $option;
        }

        return '';
    }
1372162
public static function readFile($package)
    {
        $root = dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
        $path = implode(DIRECTORY_SEPARATOR, array($root, $package, 'composer.json'));
        Logger::trace("Reading composer file %s", $path);
        if (file_exists($path)) {
            $composer = json_decode(file_get_contents($path), true);
            if (array_key_exists('require', $composer) && !empty($composer['require'])) {
                $directories = array($package);
                Logger::trace("Checking dependencies for package %s", $package);
                foreach ($composer['require'] as $requirement => $version) {
                    $directories = array_merge(self::readFile($requirement), $directories);
                }
                return $directories;
            } else {
                Logger::trace("Package %s has no dependencies", $package);
                return array($package);
            }
        } else {
            return array();
        }
    }
1131737
private function extractPackage(
        string $vendorPath,
        SymbolInterface $symbol
    ): ?string {
        static $packagesPerSymbol = [];

        $name = $symbol->getName();

        if (!array_key_exists($name, $packagesPerSymbol)) {
            $reflection = $this->getClassReflection($name);
            $file       = str_replace('\\', '/', $reflection->getFileName());

            // This happens for symbols in the current package.
            if (strpos($file, $vendorPath) !== 0) {
                return null;
            }

            $structure = explode(
                '/',
                preg_replace(
                    sprintf(
                        '/^%s/',
                        preg_quote($vendorPath . '/', '/')
                    ),
                    '',
                    $file
                ),
                3
            );

            // This happens when other code extends Composer root code, like:
            // composer/ClassLoader.php
            if (count($structure) < 3) {
                $packagesPerSymbol[$name] = null;
            }

            [$vendor, $package] = $structure;

            $packagesPerSymbol[$name] = sprintf('%s/%s', $vendor, $package);
        }

        return $packagesPerSymbol[$name] ?? null;
    }
705588
public function bind(Package $package = null)
    {
        $package = $package ?: new Package();
        
        $navMap = $this->xml->navMap;
        
        $this->consumeNavMap($navMap, $package->navigation->chapters);
        
        return $package;
    }