|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright © 2024 ExacTI Technology Solutions. All rights reserved.
|
|
|
|
* GPLv3 General License.
|
|
|
|
* https://exacti.com.br
|
|
|
|
* Phacil PHP Framework - https://github.com/exacti/phacil-framework
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Phacil\Framework;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 2.0.0
|
|
|
|
* @package Phacil\Framework
|
|
|
|
*/
|
|
|
|
class Version {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $framework;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var \Composer\InstalledVersions
|
|
|
|
*/
|
|
|
|
private $composerInstalled;
|
|
|
|
|
|
|
|
public function __construct($framework, $composerInstalled, $teste) {
|
|
|
|
$this->framework = $framework;
|
|
|
|
$this->composerInstalled = $composerInstalled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return Phacil Framework version or composer package version
|
|
|
|
*
|
|
|
|
* @param string $package (Optional) If empty, return the current framework version
|
|
|
|
*
|
|
|
|
* @return string|false
|
|
|
|
*/
|
|
|
|
public function get($package = null)
|
|
|
|
{
|
|
|
|
return (!$package) ? $this->framework : $this->getPackageVersion($package);
|
|
|
|
//return file_get_contents(\Phacil\Framework\Config::DIR_SYSTEM() . "engine/VERSION");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Alias for get method
|
|
|
|
* @return string|false
|
|
|
|
*/
|
|
|
|
public function getFrameworkVersion() {
|
|
|
|
return $this->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Alias for get method
|
|
|
|
* @return string|false
|
|
|
|
*/
|
|
|
|
public function getPhacilVersion() {
|
|
|
|
return $this->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string|false
|
|
|
|
*/
|
|
|
|
public function getPHPVersion() {
|
|
|
|
return phpversion();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return string[] */
|
|
|
|
public function getComposerPackages() {
|
|
|
|
//return call_user_func(array($this->composerInstalled, 'getInstalledPackages'));
|
|
|
|
$composerInstalled = $this->composerInstalled;
|
|
|
|
return $composerInstalled::getInstalledPackages();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $package
|
|
|
|
* @return string|null
|
|
|
|
* @throws \Phacil\Framework\Exception\OutOfBoundsException
|
|
|
|
*/
|
|
|
|
public function getPackageVersion($package) {
|
|
|
|
//return call_user_func(array($this->composerInstalled, 'getVersion'), $package);
|
|
|
|
$composerInstalled = $this->composerInstalled;
|
|
|
|
try {
|
|
|
|
return $composerInstalled::getVersion($package);
|
|
|
|
} catch (\OutOfBoundsException $ob) {
|
|
|
|
$notFind = new \Phacil\Framework\Exception\OutOfBoundsException($ob->getMessage(), $ob->getCode(), $ob);
|
|
|
|
$notFind->setObject($ob);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|