6292f2b2cdd8e5ec2beceea90dd776227a00299a
8 * Get the CiviCRM version
10 public static function findVersion() {
11 $verFile = implode(DIRECTORY_SEPARATOR
, [dirname(__FILE__
), 'xml', 'version.xml']);
12 if (file_exists($verFile)) {
13 $str = file_get_contents($verFile);
14 $xmlObj = simplexml_load_string($str);
15 return (string) $xmlObj->version_no
;
18 trigger_error("Unknown version", E_USER_ERROR
);
25 public static function findCMS() {
26 if (defined('CIVICRM_UF')) {
29 elseif (function_exists('drupal_bootstrap') && version_compare(VERSION
, '6.0', '>=') && version_compare(VERSION
, '7.0', '<')) {
32 elseif (function_exists('drupal_bootstrap') && version_compare(VERSION
, '7.0', '>=') && version_compare(VERSION
, '8.0', '<')) {
36 // guess CMS name from the current path
37 list($cmsType,) = self
::findCMSRootPath();
39 if (!empty($cmsType)) {
46 * Get the CMS root path and CMS name
48 public static function findCMSRootPath() {
51 'wp-includes/version.php',
52 // Future? 'vendor/civicrm/wordpress/civicrm.php' => 'wp',
55 'administrator/components/com_civicrm/civicrm/civicrm-version.php',
58 'modules/system/system.module', // D7
61 'core/core.services.yml', // D8
64 'core/modules/layout/layout.module',
68 $parts = explode('/', str_replace('\\', '/', self
::getSearchDir()));
69 while (!empty($parts)) {
70 $basePath = implode('/', $parts);
72 foreach ($cmsPatterns as $cmsType => $relPaths) {
73 foreach ($relPaths as $relPath) {
74 $matches = glob("$basePath/$relPath");
75 if (!empty($matches)) {
76 return [$cmsType, $basePath];
86 * Get the current path
88 public static function getSearchDir() {
89 if ($_SERVER['SCRIPT_FILENAME']) {
90 return dirname($_SERVER['SCRIPT_FILENAME']);
92 // getenv('PWD') works better with symlinked source trees, but it's
93 // not portable to Windows.
94 if (strtoupper(substr(PHP_OS
, 0, 3)) === 'WIN') {
107 * Get the CiviCRM version.
108 * TODO : For now this function is not included in \Civi\Version class so not to break any code
109 * which directly call civicrmVersion(). So those call need to replaced with \Civi\Version::civicrmVersion()
110 * when included in the class
112 function civicrmVersion() {
114 'version' => \Civi\Version
::findVersion(),
115 'cms' => \Civi\Version
::findCMS(),