|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * This file is part of Win32Service Library package. |
| 6 | + * |
| 7 | + * @copy Win32Service (c) 2018-2019 |
| 8 | + * |
| 9 | + * @author "MacintoshPlus" <macintoshplus@mactronique.fr> |
| 10 | + */ |
| 11 | +if (\PHP_VERSION_ID < 80000) { |
| 12 | + return; |
| 13 | +} |
| 14 | +/* |
| 15 | + * There constants are added in v0.4.0 of extension. |
| 16 | + */ |
| 17 | +if (!\defined('WIN32_INFO_SERVICE')) { |
| 18 | + /* Win32 Recovery Constants */ |
| 19 | + \define('WIN32_SC_ACTION_NONE', 0x00000000); /* 0x00000000 No Action */ |
| 20 | + \define('WIN32_SC_ACTION_REBOOT', 0x00000001); /* 0x00000001 Reboot the computer */ |
| 21 | + \define('WIN32_SC_ACTION_RESTART', 0x00000002); /* 0x00000002 Restart the service */ |
| 22 | + \define('WIN32_SC_ACTION_RUN_COMMAND', 0x00000003); /* 0x00000003 Run the command */ |
| 23 | + |
| 24 | + /* Win32 Service information */ |
| 25 | + \define('WIN32_INFO_SERVICE', 'service'); |
| 26 | + \define('WIN32_INFO_DISPLAY', 'display'); |
| 27 | + \define('WIN32_INFO_USER', 'user'); |
| 28 | + \define('WIN32_INFO_PASSWORD', 'password'); |
| 29 | + \define('WIN32_INFO_PATH', 'path'); |
| 30 | + \define('WIN32_INFO_PARAMS', 'params'); |
| 31 | + \define('WIN32_INFO_DESCRIPTION', 'description'); |
| 32 | + \define('WIN32_INFO_START_TYPE', 'start_type'); |
| 33 | + \define('WIN32_INFO_LOAD_ORDER', 'load_order'); |
| 34 | + \define('WIN32_INFO_SVC_TYPE', 'svc_type'); |
| 35 | + \define('WIN32_INFO_ERROR_CONTROL', 'error_control'); |
| 36 | + \define('WIN32_INFO_DELAYED_START', 'delayed_start'); |
| 37 | + \define('WIN32_INFO_BASE_PRIORITY', 'base_priority'); |
| 38 | + \define('WIN32_INFO_DEPENDENCIES', 'dependencies'); |
| 39 | + \define('WIN32_INFO_RECOVERY_DELAY', 'recovery_delay'); |
| 40 | + \define('WIN32_INFO_RECOVERY_ACTION_1', 'recovery_action_1'); |
| 41 | + \define('WIN32_INFO_RECOVERY_ACTION_2', 'recovery_action_2'); |
| 42 | + \define('WIN32_INFO_RECOVERY_ACTION_3', 'recovery_action_3'); |
| 43 | + \define('WIN32_INFO_RECOVERY_RESET_PERIOD', 'recovery_reset_period'); |
| 44 | + \define('WIN32_INFO_RECOVERY_ENABLED', 'recovery_enabled'); |
| 45 | + \define('WIN32_INFO_RECOVERY_REBOOT_MSG', 'recovery_reboot_msg'); |
| 46 | + \define('WIN32_INFO_RECOVERY_COMMAND', 'recovery_command'); |
| 47 | +} |
| 48 | + |
| 49 | +if (!\defined('WIN32_SERVICE_CONTROL_INTERROGATE')) { |
| 50 | + \define('WIN32_SERVICE_CONTROL_CONTINUE', 0x00000003); |
| 51 | + \define('WIN32_SERVICE_CONTROL_INTERROGATE', 0x00000004); |
| 52 | + \define('WIN32_SERVICE_CONTROL_PAUSE', 0x00000002); |
| 53 | + \define('WIN32_SERVICE_CONTROL_STOP', 0x00000001); |
| 54 | + \define('WIN32_SERVICE_STOPPED', 0x0000001); |
| 55 | + \define('WIN32_SERVICE_START_PENDING', 0x0000002); |
| 56 | + \define('WIN32_SERVICE_STOP_PENDING', 0x0000003); |
| 57 | + \define('WIN32_SERVICE_RUNNING', 0x0000004); |
| 58 | + \define('WIN32_SERVICE_CONTINUE_PENDING', 0x0000005); |
| 59 | + \define('WIN32_SERVICE_PAUSE_PENDING', 0x0000006); |
| 60 | + \define('WIN32_SERVICE_PAUSED', 0x0000007); |
| 61 | + |
| 62 | + \define('WIN32_ERROR_ACCESS_DENIED', 0x00000005); |
| 63 | + \define('WIN32_ERROR_CIRCULAR_DEPENDENCY', 0x00000423); |
| 64 | + \define('WIN32_ERROR_DATABASE_DOES_NOT_EXIST', 0x00000429); |
| 65 | + \define('WIN32_ERROR_DEPENDENT_SERVICES_RUNNING', 0x0000041B); |
| 66 | + \define('WIN32_ERROR_DUPLICATE_SERVICE_NAME', 0x00000436); |
| 67 | + \define('WIN32_ERROR_FAILED_SERVICE_CONTROLLER_CONNECT', 0x00000427); |
| 68 | + \define('WIN32_ERROR_INSUFFICIENT_BUFFER', 0x0000007A); |
| 69 | + \define('WIN32_ERROR_INVALID_DATA', 0x0000000D); |
| 70 | + \define('WIN32_ERROR_INVALID_HANDLE', 0x00000006); |
| 71 | + \define('WIN32_ERROR_INVALID_LEVEL', 0x0000007C); |
| 72 | + \define('WIN32_ERROR_INVALID_NAME', 0x0000007B); |
| 73 | + \define('WIN32_ERROR_INVALID_PARAMETER', 0x00000057); |
| 74 | + \define('WIN32_ERROR_INVALID_SERVICE_ACCOUNT', 0x00000421); |
| 75 | + \define('WIN32_ERROR_INVALID_SERVICE_CONTROL', 0x0000041C); |
| 76 | + \define('WIN32_ERROR_PATH_NOT_FOUND', 0x00000003); |
| 77 | + \define('WIN32_ERROR_SERVICE_ALREADY_RUNNING', 0x00000420); |
| 78 | + \define('WIN32_ERROR_SERVICE_CANNOT_ACCEPT_CTRL', 0x00000425); |
| 79 | + \define('WIN32_ERROR_SERVICE_DATABASE_LOCKED', 0x0000041F); |
| 80 | + \define('WIN32_ERROR_SERVICE_DEPENDENCY_DELETED', 0x00000433); |
| 81 | + \define('WIN32_ERROR_SERVICE_DEPENDENCY_FAIL', 0x0000042C); |
| 82 | + \define('WIN32_ERROR_SERVICE_DISABLED', 0x00000422); |
| 83 | + \define('WIN32_ERROR_SERVICE_DOES_NOT_EXIST', 0x00000424); |
| 84 | + \define('WIN32_ERROR_SERVICE_EXISTS', 0x00000431); |
| 85 | + \define('WIN32_ERROR_SERVICE_LOGON_FAILED', 0x0000042D); |
| 86 | + \define('WIN32_ERROR_SERVICE_MARKED_FOR_DELETE', 0x00000430); |
| 87 | + \define('WIN32_ERROR_SERVICE_NO_THREAD', 0x0000041E); |
| 88 | + \define('WIN32_ERROR_SERVICE_NOT_ACTIVE', 0x00000426); |
| 89 | + \define('WIN32_ERROR_SERVICE_REQUEST_TIMEOUT', 0x0000041D); |
| 90 | + \define('WIN32_ERROR_SHUTDOWN_IN_PROGRESS', 0x0000045B); |
| 91 | + \define('WIN32_ERROR_SERVICE_SPECIFIC_ERROR', 0x0000042A); |
| 92 | + |
| 93 | + \define('WIN32_NO_ERROR', 0x00000000); |
| 94 | +} |
| 95 | + |
| 96 | +if (!\function_exists('win32_start_service_ctrl_dispatcher')) { |
| 97 | + /** |
| 98 | + * @throws ValueError on invalid parameter |
| 99 | + * @throws Win32ServiceException when current SAPI is not 'cli' |
| 100 | + */ |
| 101 | + function win32_start_service_ctrl_dispatcher(string $name, bool $gracefulMode = true): void |
| 102 | + { |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +if (!\function_exists('win32_get_last_control_message')) { |
| 107 | + /** |
| 108 | + * @throws Win32ServiceException when current SAPI is not 'cli' |
| 109 | + */ |
| 110 | + function win32_get_last_control_message(): int |
| 111 | + { |
| 112 | + return WIN32_SERVICE_CONTROL_INTERROGATE; |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +if (!\function_exists('win32_set_service_status')) { |
| 117 | + \define('WIN32_FAKE_SERVICE_STATUS', '__serviceStatus'); |
| 118 | + $GLOBALS[WIN32_FAKE_SERVICE_STATUS] = WIN32_SERVICE_START_PENDING; |
| 119 | + /** |
| 120 | + * @throws ValueError on invalid parameter |
| 121 | + * @throws Win32ServiceException when current SAPI is not 'cli' |
| 122 | + */ |
| 123 | + function win32_set_service_status(int $status, int $checkpoint = 0): void |
| 124 | + { |
| 125 | + $GLOBALS[WIN32_FAKE_SERVICE_STATUS] = $status; |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * @throws ValueError when $serviceName is empty |
| 130 | + * @throws Win32ServiceException on error |
| 131 | + */ |
| 132 | + function win32_query_service_status(string $serviceName, ?string $machine = null): array |
| 133 | + { |
| 134 | + return ['CurrentState' => $GLOBALS[WIN32_FAKE_SERVICE_STATUS]]; |
| 135 | + } |
| 136 | +} |
| 137 | +if (!\function_exists('win32_set_service_exit_mode')) { |
| 138 | + /** |
| 139 | + * Empty function beacause, it not work on non WINNT operating System. |
| 140 | + * Declared only for method exists. |
| 141 | + * |
| 142 | + * @throws Win32ServiceException when current SAPI is not 'cli' |
| 143 | + */ |
| 144 | + function win32_set_service_exit_mode(bool $gracefulMode = true): bool |
| 145 | + { |
| 146 | + return $gracefulMode; |
| 147 | + } |
| 148 | +} |
| 149 | +if (!\function_exists('win32_set_service_exit_code')) { |
| 150 | + /** |
| 151 | + * Empty function beacause, it not work on non WINNT operating System. |
| 152 | + * Declared only for method exists. |
| 153 | + * |
| 154 | + * @throws Win32ServiceException when current SAPI is not 'cli' |
| 155 | + */ |
| 156 | + function win32_set_service_exit_code(int $exitCode = 1): int |
| 157 | + { |
| 158 | + return $exitCode; |
| 159 | + } |
| 160 | +} |
| 161 | +if (!\function_exists('win32_send_custom_control')) { |
| 162 | + /** |
| 163 | + * Empty function beacause, it not work on non WINNT operating System. |
| 164 | + * Declared only for method exists. |
| 165 | + * |
| 166 | + * @throws ValueError when $serviceName is empty string |
| 167 | + * @throws ValueError when $control is not beetween 128 and 255 |
| 168 | + * @throws Win32ServiceException on error |
| 169 | + */ |
| 170 | + function win32_send_custom_control(string $serviceName, int $control, ?string $machine = null): void |
| 171 | + { |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +if (!class_exists(\Win32ServiceException::class)) { |
| 176 | + class Win32ServiceException extends \Exception |
| 177 | + { |
| 178 | + } |
| 179 | +} |
0 commit comments