Pagekit\Installer\Package\PackageManager::getVersion PHP Method

getVersion() protected method

Tries to obtain package version from 'composer.json' or installation log.
protected getVersion ( $package ) : string
$package
return string
    protected function getVersion($package)
    {
        if (!($path = $package->get('path'))) {
            throw new \RuntimeException(__('Package path is missing.'));
        }
        if (!file_exists($file = $path . '/composer.json')) {
            throw new \RuntimeException(__('\'composer.json\' is missing.'));
        }
        $package = json_decode(file_get_contents($file), true);
        if (isset($package['version'])) {
            return $package['version'];
        }
        if (file_exists(App::get('path.packages') . '/composer/installed.json')) {
            $installed = json_decode(file_get_contents($file), true);
            foreach ($installed as $package) {
                if ($package['name'] === $package->getName()) {
                    return $package['version'];
                }
            }
        }
        return '0.0.0';
    }