Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.symlinks.php
Go to the documentation of this file.
1<?php
2/*
3 *
4 * * Copyright (c) 2021-2024 Bearsampp
5 * * License: GNU General Public License version 3 or later; see LICENSE.txt
6 * * Website: https://bearsampp.com
7 * * Github: https://github.com/Bearsampp
8 *
9 */
10
15{
16 const PHPMYADMIN_SYMLINK = 'phpmyadmin';
17 const PHPPGADMIN_SYMLINK = 'phppgadmin';
18 const APACHE_SYMLINK = 'apache';
19 const MARIADB_SYMLINK = 'mariadb';
20 const MEMCACHED_SYMLINK = 'memcached';
21 const MYSQL_SYMLINK = 'mysql';
22 const NODEJS_SYMLINK = 'nodejs';
23 const PHP_SYMLINK = 'php';
24 const POSTGRESQL_SYMLINK = 'postgresql';
25 const COMPOSER_SYMLINK = 'composer';
26 const CONSOLEZ_SYMLINK = 'consolez';
27 const GHOSTSCRIPT_SYMLINK = 'ghostscript';
28 const GIT_SYMLINK = 'git';
29 const NGROK_SYMLINK = 'ngrok';
30 const PERL_SYMLINK = 'perl';
31 const PYTHON_SYMLINK = 'python';
32 const RUBY_SYMLINK = 'ruby';
33 const XLIGHT_SYMLINK = 'xlight';
34 const MAILPIT_SYMLINK = 'mailpit';
35 const BRUNO_SYMLINK = 'bruno';
36
40 private $root;
41
47 public function __construct($root)
48 {
49 $this->root = $root;
50 $this->initializePaths();
51 }
52
63 public static function deleteCurrentSymlinks()
64 {
66
67 // Check to see if purging is necessary
68 $appsPath = $bearsamppRoot->getAppsPath();
69 $binPath = $bearsamppRoot->getBinPath();
70 $toolsPath = $bearsamppRoot->getToolsPath();
71
72 $array = [
73 self::PHPMYADMIN_SYMLINK => $appsPath . '/phpmyadmin/current',
74 self::PHPPGADMIN_SYMLINK => $appsPath . '/phppgadmin/current',
75 self::APACHE_SYMLINK => $binPath . '/apache/current',
76 self::MARIADB_SYMLINK => $binPath . '/mariadb/current',
77 self::MEMCACHED_SYMLINK => $binPath . '/memcached/current',
78 self::MYSQL_SYMLINK => $binPath . '/mysql/current',
79 self::NODEJS_SYMLINK => $binPath . '/nodejs/current',
80 self::PHP_SYMLINK => $binPath . '/php/current',
81 self::POSTGRESQL_SYMLINK => $binPath . '/postgresql/current',
82 self::COMPOSER_SYMLINK => $toolsPath . '/composer/current',
83 self::CONSOLEZ_SYMLINK => $toolsPath . '/consolez/current',
84 self::GHOSTSCRIPT_SYMLINK => $toolsPath . '/ghostscript/current',
85 self::GIT_SYMLINK => $toolsPath . '/git/current',
86 self::NGROK_SYMLINK => $toolsPath . '/ngrok/current',
87 self::PERL_SYMLINK => $toolsPath . '/perl/current',
88 self::PYTHON_SYMLINK => $toolsPath . '/python/current',
89 self::RUBY_SYMLINK => $toolsPath . '/ruby/current',
90 self::XLIGHT_SYMLINK => $binPath . '/xlight/current',
91 self::MAILPIT_SYMLINK => $binPath . '/mailpit/current',
92 self::BRUNO_SYMLINK => $toolsPath . '/bruno/current'
93 ];
94
95 // Fix for PHP 8.2: Add null checks before accessing array elements
96 if (!is_array($array) || empty($array)) {
97 Util::logError('Current symlinks array is not initialized or empty.');
98 return;
99 }
100
101 // Purge "current" symlinks
102 foreach ($array as $name => $path) {
103 // Skip if path is null
104 if (empty($path)) {
105 continue;
106 }
107
108 if (!file_exists($path)) {
109 // Skip if the symlink doesn't exist - no need to log an error
110 continue;
111 }
112
113 // Simple approach: use rmdir for directories and unlink for files
114 if (is_dir($path)) {
115 if (@rmdir($path)) {
116 Util::logDebug('Deleted directory symlink: ' . $path);
117 }
118 } else {
119 if (@unlink($path)) {
120 Util::logDebug('Deleted file symlink: ' . $path);
121 }
122 }
123 }
124 }
125}
global $bearsamppRoot
global $bearsamppCore
static logError($data, $file=null)
static logDebug($data, $file=null)