2024.8.23
Loading...
Searching...
No Matches
class.symlinks.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Manages the creation and deletion of symbolic links for various components within the Bearsampp environment.
12 */
14{
15 /**
16 * @var Root The root object providing access to system paths.
17 */
18 private $root;
19
20 /**
21 * Constructs a Symlinks object and initializes paths to current directories.
22 *
23 * @param Root $root The root object associated with the Bearsampp environment.
24 */
25 public function __construct($root)
26 {
27 $this->root = $root;
28 $this->initializePaths();
29 }
30
31 /**
32 * Deletes all symbolic links listed in the arrayOfCurrents.
33 * Logs each operation's success or failure.
34 *
35 * This method iterates over a predefined list of symbolic link paths and attempts to delete each one.
36 * If a symbolic link does not exist, an error is logged. If the deletion is successful, a debug message is logged.
37 *
38 * @global Root $bearsamppRoot The root object providing access to system paths.
39 * @global Core $bearsamppCore The core object providing core functionalities.
40 */
41 public static function deleteCurrentSymlinks()
42 {
44
45 // Check to see if purging is necessary
46 $appsPath = $bearsamppRoot->getAppsPath();
47 $binPath = $bearsamppRoot->getBinPath();
48 $toolsPath = $bearsamppRoot->getToolsPath();
49
50 $array = [
51 '1' => Util::formatWindowsPath($appsPath . '/adminer/current'),
52 '2' => Util::formatWindowsPath($appsPath . '/phpmyadmin/current'),
53 '3' => Util::formatWindowsPath($appsPath . '/phppgadmin/current'),
54 '4' => Util::formatWindowsPath($appsPath . '/webgrind/current'),
55 '5' => Util::formatWindowsPath($binPath . '/apache/current'),
56 '6' => Util::formatWindowsPath($binPath . '/filezilla/current'),
57 '7' => Util::formatWindowsPath($binPath . '/mailhog/current'),
58 '8' => Util::formatWindowsPath($binPath . '/mariadb/current'),
59 '9' => Util::formatWindowsPath($binPath . '/memcached/current'),
60 '10' => Util::formatWindowsPath($binPath . '/mysql/current'),
61 '11' => Util::formatWindowsPath($binPath . '/nodejs/current'),
62 '12' => Util::formatWindowsPath($binPath . '/php/current'),
63 '13' => Util::formatWindowsPath($binPath . '/postgresql/current'),
64 '14' => Util::formatWindowsPath($toolsPath . '/composer/current'),
65 '15' => Util::formatWindowsPath($toolsPath . '/consolez/current'),
66 '16' => Util::formatWindowsPath($toolsPath . '/ghostscript/current'),
67 '17' => Util::formatWindowsPath($toolsPath . '/git/current'),
68 '18' => Util::formatWindowsPath($toolsPath . '/ngrok/current'),
69 '19' => Util::formatWindowsPath($toolsPath . '/perl/current'),
70 '20' => Util::formatWindowsPath($toolsPath . '/python/current'),
71 '21' => Util::formatWindowsPath($toolsPath . '/ruby/current'),
72 '22' => Util::formatWindowsPath($toolsPath . '/xdc/current'),
73 '23' => Util::formatWindowsPath($toolsPath . '/yarn/current'),
74 '24' => Util::formatWindowsPath($binPath . '/xlight/current'),
75 '25' => Util::formatWindowsPath($binPath . '/mailpit/current')
76 ];
77
78 if (!is_array($array) || empty($array)) {
79 Util::logError('Current symlinks array is not initialized or empty.');
80 return;
81 }
82
83 // Purge "current" symlinks
84 foreach ($array as $startPath) {
85 if (!file_exists($startPath)) {
86 Util::logError('Symlink does not exist: ' . $startPath);
87 continue;
88 } else {
89 if (@Batch::removeSymlink($startPath)) {
90 Util::logDebug('Deleted: ' . $startPath);
91 }
92 }
93 }
94 }
95}
global $bearsamppRoot
global $bearsamppCore
static removeSymlink($link)
static logError($data, $file=null)
static logDebug($data, $file=null)
static formatWindowsPath($path)