• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IlyasDeckers / ody-core / 13532154862

25 Feb 2025 10:24PM UTC coverage: 30.374% (+1.7%) from 28.706%
13532154862

push

github

web-flow
Update php.yml

544 of 1791 relevant lines covered (30.37%)

9.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/helpers.php
1
<?php
2
declare(strict_types=1);
3

4
use DI\Container;
5
use DI\DependencyException;
6
use DI\NotFoundException;
7
use Ody\Core\Config\Config;
8
use Ody\Core\Http\Request;
9
use Ody\Swoole\ServerState;
10

11
if (! function_exists('app')) {
12
    /**
13
     * @throws DependencyException
14
     * @throws NotFoundException
15
     */
16
    function app($abstract = null, array $parameters = [])
17
    {
18
        if (is_null($abstract)) {
×
19
            return new Container();
×
20
        }
21

22
        return (new Container())->make($abstract, $parameters);
×
23
    }
24
}
25

26
if (! function_exists('resolve')) {
27
    function resolve(string $name = null, array $parameters = []) : mixed
28
    {
29
        return app($name, $parameters);
×
30
    }
31
}
32

33
if (! function_exists('app_path')) {
34
    function app_path(string $path = null): string
35
    {
36
        return base_path("App/$path");
×
37
    }
38
}
39

40

41
if (! function_exists('basePath')) {
42
    function base_path(string $path = null): string
43
    {
44
        /** @psalm-suppress UndefinedConstant */
45
        return realpath(PROJECT_PATH) . "/$path";
×
46
    }
47
}
48

49
if (! function_exists('configPath')) {
50
    function configPath(string $path = null): string
51
    {
52
        return base_path("config/$path");
×
53
    }
54
}
55

56
if (! function_exists('storagePath')) {
57
    function storagePath(string $path = null): string
58
    {
59
        return base_path("storage/$path");
×
60
    }
61
}
62

63
if (! function_exists('languagePath')) {
64
    function languagePath(string $path = null): string
65
    {
66
        return base_path("language/$path");
×
67
    }
68
}
69

70
if (! function_exists('databasePath')) {
71
    function databasePath(string $path = null): string
72
    {
73
        return base_path("database/$path");
×
74
    }
75
}
76

77
if (! function_exists('config')) {
78
    function config(string $key, mixed $default = null): mixed
79
    {
80
        return Config::getInstance()->get($key , $default);
×
81
    }
82
}
83

84
if (! function_exists('cpu_count')) {
85
    function cpu_count(): int
86
    {
87
        return swoole_cpu_num();
×
88
    }
89
}
90

91
if (! function_exists('setQueueProcessId')) {
92
    function setQueueProcessId(int $id): void
93
    {
94
        ServerState::getInstance()->setQueueProcessId($id);
×
95
    }
96
}
97

98
if (! function_exists('getMasterProcessId')) {
99
    function getMasterProcessId(): int|null
100
    {
101
        return ServerState::getInstance()->getMasterProcessId();
×
102
    }
103
}
104

105
if (! function_exists('getManagerProcessId')) {
106
    function getManagerProcessId(): int|null
107
    {
108
        return ServerState::getInstance()->getManagerProcessId();
×
109
    }
110
}
111

112
if (! function_exists('getWatcherProcessId')) {
113
    function getWatcherProcessId(): int|null
114
    {
115
        return ServerState::getInstance()->getWatcherProcessId();
×
116
    }
117
}
118

119
if (! function_exists('getFactoryProcessId')) {
120
    function getFactoryProcessId(): int|null
121
    {
122
        return ServerState::getInstance()->getFactoryProcessId();
×
123
    }
124
}
125

126
if (! function_exists('getQueueProcessId')) {
127
    function getQueueProcessId(): int|null
128
    {
129
        return ServerState::getInstance()->getQueueProcessId();
×
130
    }
131
}
132

133
if (! function_exists('getSchedulingProcessId')) {
134
    function getSchedulingProcessId(): int|null
135
    {
136
        return ServerState::getInstance()->getSchedulingProcessId();
×
137
    }
138
}
139

140
if (! function_exists('getWorkerProcessIds')) {
141
    function getWorkerProcessIds(): array
142
    {
143
        return ServerState::getInstance()->getWorkerProcessIds();
×
144
    }
145
}
146

147
if (! function_exists('httpServerIsRunning')) {
148
    function httpServerIsRunning(): bool
149
    {
150
        if (!is_null(getManagerProcessId()) && !is_null(getMasterProcessId())){
×
151
            /** @psalm-suppress PossiblyNullArgument */
152
            return posix_kill(getManagerProcessId(), SIG_DFL) && posix_kill(getMasterProcessId(), SIG_DFL);
×
153
        }
154
        return false;
×
155
    }
156
}
157

158
if (! function_exists('queueServerIsRunning')) {
159
    function queueServerIsRunning(): bool
160
    {
161
        if (!is_null(getQueueProcessId())){
×
162
            /** @psalm-suppress PossiblyNullArgument */
163
            return posix_kill(getQueueProcessId(), SIG_DFL);
×
164
        }
165
        return false;
×
166
    }
167
}
168

169
if (! function_exists('schedulingServerIsRunning')) {
170
    function schedulingServerIsRunning(): bool
171
    {
172
        if (!is_null(getSchedulingProcessId())){
×
173
            /** @psalm-suppress PossiblyNullArgument */
174
            return posix_kill(getSchedulingProcessId(), SIG_DFL);
×
175
        }
176
        return false;
×
177
    }
178
}
179

180
if (! function_exists('request')) {
181
    function request(): Request
182
    {
183
        return Request::getInstance();
×
184
    }
185
}
186

187
//if (! function_exists('response')) {
188
//    function response(): Response
189
//    {
190
//        return Response::getInstance();
191
//    }
192
//}
193
//
194
//if (! function_exists('auth')) {
195
//    function auth(): Auth
196
//    {
197
//        return Auth::getInstance();
198
//    }
199
//}
200
//
201
//if (! function_exists('elasticsearch')) {
202
//    function elasticsearch(): Client
203
//    {
204
//        return Elasticsearch::getInstance();
205
//    }
206
//}
207
//
208
//if (! function_exists('redis')) {
209
//    function redis(): \Redis
210
//    {
211
//        return Redis::getInstance();
212
//    }
213
//}
214
//
215
//if (! function_exists('mail')) {
216
//    function mail(): Mail
217
//    {
218
//        return Mail::getInstance();
219
//    }
220
//}
221
//
222
//if (! function_exists('cache')) {
223
//    function cache(): Cache
224
//    {
225
//        return Cache::getInstance();
226
//    }
227
//}
228
//
229
//if (! function_exists('validation')) {
230
//    function validation(): Validation
231
//    {
232
//        return Validation::getInstance();
233
//    }
234
//}
235

236
if (!function_exists('env')) {
237
    function env(string $key, mixed $default = null): string|bool|null
238
    {
239
        $value = getenv($key);
×
240

241
        if ($value === false) {
×
242
            return $default;
×
243
        }
244

245
        switch (strtolower($value)) {
×
246
            case 'true':
×
247
            case '(true)':
×
248
                return true;
×
249
            case 'false':
×
250
            case '(false)':
×
251
                return false;
×
252
            case 'empty':
×
253
            case '(empty)':
×
254
                return '';
×
255
            case 'null':
×
256
            case '(null)':
×
257
                return null;
×
258
        }
259

260
        if (($valueLength = strlen($value)) > 1 && $value[0] === '"' && $value[$valueLength - 1] === '"') {
×
261
            return substr($value, 1, -1);
×
262
        }
263

264
        return $value;
×
265
    }
266
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc