/** * {@inheritDoc} * * Gets package's version from composer's "installed.json". By default CakePHP * and QuickAppCMS package versions are handled by their internal version * getters: * * - \Cake\Core\Configure\version() for CakePHP * - quickapps('version') for QuickAppsCMS * * @return string Package's version, for instance `1.2.x-dev` */ public function version() { if (parent::version() !== null) { return parent::version(); } $packages = $this->_packages(); $this->_version = isset($packages[$this->_packageName]) ? $packages[$this->_packageName] : ''; return $this->_version; }
/** * {@inheritDoc} * * It will look for plugin's version in the following places: * * - Plugin's "composer.json" file. * - Plugin's "VERSION.txt" file (or any file matching "/version?(\.\w+)/i"). * - Composer's "installed.json" file. * * If not found `dev-master` is returned by default. If plugin is not registered * on QuickAppsCMS (not installed) an empty string will be returned instead. * * @return string Plugin's version, for instance `1.2.x-dev` */ public function version() { if (parent::version() !== null) { return parent::version(); } if (!Plugin::exists($this->name())) { $this->_version = ''; return $this->_version; } // from composer.json if (!empty($this->composer['version'])) { $this->_version = $this->composer['version']; return $this->_version; } // from version.txt $files = glob($this->path . '/*', GLOB_NOSORT); foreach ($files as $file) { $fileName = basename(strtolower($file)); if (preg_match('/version?(\\.\\w+)/i', $fileName)) { $versionFile = file($file); $version = trim(array_pop($versionFile)); $this->_version = $version; return $this->_version; } } // from installed.json $installedJson = normalizePath(VENDOR_INCLUDE_PATH . "composer/installed.json"); if (is_readable($installedJson)) { $json = (array) json_decode(file_get_contents($installedJson), true); foreach ($json as $pkg) { if (isset($pkg['version']) && strtolower($pkg['name']) === strtolower($this->_packageName)) { $this->_version = $pkg['version']; return $this->_version; } } } $this->_version = 'dev-master'; return $this->_version; }