2024.8.23
Loading...
Searching...
No Matches
class.tool.ghostscript.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 ToolGhostscript
12 *
13 * This class represents the Ghostscript tool module in the Bearsampp application.
14 * It extends the Module class and provides functionalities specific to Ghostscript,
15 * such as loading configurations, setting versions, and retrieving executable paths.
16 */
18{
19 const ROOT_CFG_VERSION = 'ghostscriptVersion';
20 const LOCAL_CFG_EXE = 'ghostscriptExe';
21 const LOCAL_CFG_EXE_CONSOLE = 'ghostscriptExeConsole';
22
23 private $exe;
24 private $exeConsole;
25
26 /**
27 * Constructor for the ToolGhostscript class.
28 *
29 * @param string $id The ID of the module.
30 * @param string $type The type of the module.
31 */
32 public function __construct($id, $type) {
33 Util::logInitClass($this);
34 $this->reload($id, $type);
35 }
36
37 /**
38 * Reloads the Ghostscript module configuration based on the provided ID and type.
39 *
40 * @param string|null $id The ID of the module. If null, the current ID is used.
41 * @param string|null $type The type of the module. If null, the current type is used.
42 */
43 public function reload($id = null, $type = null) {
46
47 $this->name = $bearsamppLang->getValue(Lang::GHOSTSCRIPT);
48 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
49 parent::reload($id, $type);
50
51 if ($this->bearsamppConfRaw !== false) {
52 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
53 $this->exeConsole = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE_CONSOLE];
54 }
55
56 if (!$this->enable) {
57 Util::logInfo($this->name . ' is not enabled!');
58 return;
59 }
60 if (!is_dir($this->currentPath)) {
61 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
62 }
63 if (!is_dir($this->symlinkPath)) {
64 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
65 return;
66 }
67 if (!is_file($this->bearsamppConf)) {
68 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
69 }
70 if (!is_file($this->exe)) {
71 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
72 }
73 if (!is_file($this->exeConsole)) {
74 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exeConsole));
75 }
76 }
77
78 /**
79 * Sets the version of the Ghostscript module and reloads the configuration.
80 *
81 * @param string $version The version to set.
82 */
83 public function setVersion($version) {
84 global $bearsamppConfig;
85 $this->version = $version;
86 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
87 $this->reload();
88 }
89
90 /**
91 * Gets the path to the Ghostscript executable.
92 *
93 * @return string The path to the Ghostscript executable.
94 */
95 public function getExe() {
96 return $this->exe;
97 }
98
99 /**
100 * Gets the path to the Ghostscript console executable.
101 *
102 * @return string The path to the Ghostscript console executable.
103 */
104 public function getExeConsole() {
105 return $this->exeConsole;
106 }
107}
global $bearsamppLang
const ERROR_FILE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const ERROR_EXE_NOT_FOUND
const GHOSTSCRIPT
reload($id=null, $type=null)
static logReloadClass($classInstance)
static logError($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26