2024.8.23
Loading...
Searching...
No Matches
class.action.quit.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 * Class ActionQuit
12 * Handles the quitting process of the Bearsampp application.
13 * Displays a splash screen and stops all services and processes.
14 */
16{
17 /**
18 * @var Splash The splash screen instance.
19 */
20 private $splash;
21
22 /**
23 * Gauge values for progress bar increments.
24 */
25 const GAUGE_PROCESSES = 1;
26 const GAUGE_OTHERS = 1;
27
28 /**
29 * ActionQuit constructor.
30 * Initializes the quitting process, displays the splash screen, and sets up the main loop.
31 *
32 * @param array $args Command line arguments.
33 */
34 public function __construct($args)
35 {
36 global $bearsamppCore, $bearsamppLang, $bearsamppBins, $bearsamppWinbinder, $arrayOfCurrents;
37
38 // Start splash screen
39 $this->splash = new Splash();
40 $this->splash->init(
41 $bearsamppLang->getValue( Lang::QUIT ),
42 self::GAUGE_PROCESSES * count( $bearsamppBins->getServices() ) + self::GAUGE_OTHERS,
43 sprintf( $bearsamppLang->getValue( Lang::EXIT_LEAVING_TEXT ), APP_TITLE . ' ' . $bearsamppCore->getAppVersion() )
44 );
45
46 // Set handler for the splash screen window
47 $bearsamppWinbinder->setHandler( $this->splash->getWbWindow(), $this, 'processWindow', 2000 );
48 $bearsamppWinbinder->mainLoop();
49 $bearsamppWinbinder->reset();
50 }
51
52 /**
53 * Processes the splash screen window events.
54 * Stops all services, deletes symlinks, and kills remaining processes.
55 *
56 * @param resource $window The window resource.
57 * @param int $id The event ID.
58 * @param int $ctrl The control ID.
59 * @param mixed $param1 Additional parameter 1.
60 * @param mixed $param2 Additional parameter 2.
61 */
62 public function processWindow($window, $id, $ctrl, $param1, $param2)
63 {
64 global $bearsamppBins, $bearsamppLang, $bearsamppWinbinder;
65
66 // Stop all services
67 foreach ( $bearsamppBins->getServices() as $sName => $service ) {
68 $name = $bearsamppBins->getApache()->getName() . ' ' . $bearsamppBins->getApache()->getVersion();
69 if ( $sName == BinMysql::SERVICE_NAME ) {
70 $name = $bearsamppBins->getMysql()->getName() . ' ' . $bearsamppBins->getMysql()->getVersion();
71 }
72 elseif ( $sName == BinMailhog::SERVICE_NAME ) {
73 $name = $bearsamppBins->getMailhog()->getName() . ' ' . $bearsamppBins->getMailhog()->getVersion();
74 }
75 elseif ( $sName == BinMailpit::SERVICE_NAME ) {
76 $name = $bearsamppBins->getMailpit()->getName() . ' ' . $bearsamppBins->getMailpit()->getVersion();
77 }
78 elseif ( $sName == BinMariadb::SERVICE_NAME ) {
79 $name = $bearsamppBins->getMariadb()->getName() . ' ' . $bearsamppBins->getMariadb()->getVersion();
80 }
81 elseif ( $sName == BinPostgresql::SERVICE_NAME ) {
82 $name = $bearsamppBins->getPostgresql()->getName() . ' ' . $bearsamppBins->getPostgresql()->getVersion();
83 }
84 elseif ( $sName == BinMailhog::SERVICE_NAME ) {
85 $name = $bearsamppBins->getPostgresql()->getName() . ' ' . $bearsamppBins->getPostgresql()->getVersion();
86 }
87 elseif ( $sName == BinMemcached::SERVICE_NAME ) {
88 $name = $bearsamppBins->getMemcached()->getName() . ' ' . $bearsamppBins->getMemcached()->getVersion();
89 }
90 elseif ( $sName == BinFilezilla::SERVICE_NAME ) {
91 $name = $bearsamppBins->getFilezilla()->getName() . ' ' . $bearsamppBins->getFilezilla()->getVersion();
92 } elseif ($sName == BinXlight::SERVICE_NAME) {
93 $name = $bearsamppBins->getXlight()->getName() . ' ' . $bearsamppBins->getXlight()->getVersion();
94 }
95 elseif ( $sName == BinXlight::SERVICE_NAME ) {
96 $name = $bearsamppBins->getXlight()->getName() . ' ' . $bearsamppBins->getXlight()->getVersion();
97 }
98 $name .= ' (' . $service->getName() . ')';
99
100 $this->splash->incrProgressBar();
101 $this->splash->setTextLoading( sprintf( $bearsamppLang->getValue( Lang::EXIT_REMOVE_SERVICE_TEXT ), $name ) );
102 $service->delete();
103 }
104
105 // Purge "current" symlinks
107
108 // Stop other processes
109 $this->splash->incrProgressBar();
110 $this->splash->setTextLoading( $bearsamppLang->getValue( Lang::EXIT_STOP_OTHER_PROCESS_TEXT ) );
111 Win32Ps::killBins( true );
112
113 // Destroy the splash screen window
114 $bearsamppWinbinder->destroyWindow( $window );
115 }
116}
global $bearsamppBins
global $bearsamppLang
global $bearsamppCore
processWindow($window, $id, $ctrl, $param1, $param2)
const SERVICE_NAME
const EXIT_REMOVE_SERVICE_TEXT
const QUIT
const EXIT_LEAVING_TEXT
const EXIT_STOP_OTHER_PROCESS_TEXT
static killBins($refreshProcs=false)
const APP_TITLE
Definition root.php:12