Skip to content

Commit d034961

Browse files
committed
DP-460 Upgrade to PHP 8.1 / Laravel 9
- Get rid of global helper functions
1 parent 95f9240 commit d034961

File tree

16 files changed

+93
-79
lines changed

16 files changed

+93
-79
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"minimum-stability": "dev",
3030
"prefer-stable": true,
3131
"require": {
32-
"dreamfactory/df-core": "~0.25",
32+
"php": "^8.0",
33+
"dreamfactory/df-core": "~1.0",
3334
"dreamfactory/df-system": "~0.5"
3435
},
3536
"autoload": {

src/Components/BaseEngineAdapter.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __construct(array $settings = [])
6767
*/
6868
public static function startup($options = null)
6969
{
70-
static::initializeLibraryPaths(array_get($options, 'library_paths', []));
70+
static::initializeLibraryPaths(Arr::get($options, 'library_paths', []));
7171
}
7272

7373
/**
@@ -128,7 +128,7 @@ public function runScript(
128128
// Don't show output
129129
ob_start();
130130

131-
if (strpos($script, "\n") === false && is_file($script)) {
131+
if (!str_contains($script, "\n") && is_file($script)) {
132132
$result = $this->executeScript($script, $identifier, $data, $config);
133133
} else {
134134
$result = $this->executeString($script, $identifier, $data, $config);
@@ -166,7 +166,7 @@ public function runScript(
166166
public static function loadScript($name, $path = null, $returnContents = true)
167167
{
168168
// Already read, return script
169-
if (null !== ($script = array_get(static::$libraries, $name))) {
169+
if (null !== ($script = Arr::get(static::$libraries, $name))) {
170170
return $returnContents ? file_get_contents($script) : $script;
171171
}
172172

@@ -177,15 +177,15 @@ public static function loadScript($name, $path = null, $returnContents = true)
177177
$check = $libPath . '/' . $script;
178178

179179
if (is_file($check) && is_readable($check)) {
180-
array_set(static::$libraries, $name, $check);
180+
Arr::set(static::$libraries, $name, $check);
181181

182182
return $returnContents ? file_get_contents($check) : $check;
183183
}
184184
}
185185

186186
if ($path) {
187187
if (is_file($path) && is_readable($path)) {
188-
array_set(static::$libraries, $name, $path);
188+
Arr::set(static::$libraries, $name, $path);
189189

190190
return $returnContents ? file_get_contents($path) : $path;
191191
}
@@ -313,7 +313,7 @@ protected static function getLibrary($id, $file = null)
313313
*/
314314
protected static function externalRequest($method, $url, $payload = [], $curlOptions = [])
315315
{
316-
if (!empty($parameters = (array)array_get($curlOptions, 'parameters'))) {
316+
if (!empty($parameters = (array)Arr::get($curlOptions, 'parameters'))) {
317317
unset($curlOptions['parameters']);
318318
$paramStr = '';
319319
foreach ($parameters as $key => $value) {
@@ -325,7 +325,7 @@ protected static function externalRequest($method, $url, $payload = [], $curlOpt
325325
$url .= (strpos($url, '?') ? '&' : '?') . $paramStr;
326326
}
327327

328-
if (!empty($headers = (array)array_get($curlOptions, 'headers'))) {
328+
if (!empty($headers = (array)Arr::get($curlOptions, 'headers'))) {
329329
unset($curlOptions['headers']);
330330
$curlHeaders = [];
331331
if (!Arr::isAssoc($headers)) {
@@ -336,7 +336,7 @@ protected static function externalRequest($method, $url, $payload = [], $curlOpt
336336
}
337337
}
338338

339-
$existing = (array)array_get($curlOptions, CURLOPT_HTTPHEADER);
339+
$existing = (array)Arr::get($curlOptions, CURLOPT_HTTPHEADER);
340340
if (array_key_exists('CURLOPT_HTTPHEADER', $curlOptions)) {
341341
$existing = array_merge($existing, (array)$curlOptions['CURLOPT_HTTPHEADER']);
342342
unset($curlOptions['CURLOPT_HTTPHEADER']);
@@ -354,7 +354,7 @@ protected static function externalRequest($method, $url, $payload = [], $curlOpt
354354
}
355355
}
356356
}
357-
$curlOptions = array_except($curlOptions, $badKeys);
357+
$curlOptions = Arr::except($curlOptions, $badKeys);
358358
}
359359

360360
Curl::setDecodeToArray(true);
@@ -370,7 +370,7 @@ protected static function externalRequest($method, $url, $payload = [], $curlOpt
370370
}
371371

372372
$resultHeaders = Curl::getLastResponseHeaders();
373-
if ('chunked' === array_get(array_change_key_case($resultHeaders, CASE_LOWER), 'transfer-encoding')) {
373+
if ('chunked' === Arr::get(array_change_key_case($resultHeaders, CASE_LOWER), 'transfer-encoding')) {
374374
// don't relay this header through to client as it isn't handled well in some cases
375375
unset($resultHeaders['Transfer-Encoding']); // normal header case
376376
unset($resultHeaders['transfer-encoding']); // Restlet has all lower for this header
@@ -399,17 +399,17 @@ public static function inlineRequest($method, $path, $payload = null, $curlOptio
399399
$result = static::externalRequest($method, $path, $payload, $curlOptions);
400400
} else {
401401
$result = null;
402-
$params = (array)array_get($curlOptions, 'parameters');
403-
$headers = (array)array_get($curlOptions, 'headers');
402+
$params = (array)Arr::get($curlOptions, 'parameters');
403+
$headers = (array)Arr::get($curlOptions, 'headers');
404404
if (false !== $pos = strpos($path, '?')) {
405405
$paramString = substr($path, $pos + 1);
406406
if (!empty($paramString)) {
407407
$pArray = explode('&', $paramString);
408408
foreach ($pArray as $k => $p) {
409409
if (!empty($p)) {
410410
$tmp = explode('=', $p);
411-
$name = array_get($tmp, 0, $k);
412-
$value = array_get($tmp, 1);
411+
$name = Arr::get($tmp, 0, $k);
412+
$value = Arr::get($tmp, 1);
413413
$params[$name] = urldecode($value);
414414
}
415415
}

src/Components/ScriptEngineManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use DreamFactory\Core\Script\Engines\Python;
99
use DreamFactory\Core\Script\Engines\Python3;
1010
use InvalidArgumentException;
11+
use Illuminate\Support\Arr;
1112

1213
/**
1314
* Scripting engine
@@ -127,7 +128,7 @@ protected function getConfig($name)
127128

128129
$engines = $this->app['config']['df.script'];
129130

130-
return array_get($engines, $name, []);
131+
return Arr::get($engines, $name, []);
131132
}
132133

133134
/**

src/Components/ScriptEngineType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use DreamFactory\Core\Script\Contracts\ScriptEngineTypeInterface;
55
use DreamFactory\Core\Script\Contracts\ScriptingEngineInterface;
6+
use Illuminate\Support\Str;
67

78
/**
89
* Interface ScriptEngineType
@@ -48,7 +49,7 @@ public function __construct($settings = [])
4849
foreach ($settings as $key => $value) {
4950
if (!property_exists($this, $key)) {
5051
// try camel cased
51-
$camel = camel_case($key);
52+
$camel = Str::camel($key);
5253
if (property_exists($this, $camel)) {
5354
$this->{$camel} = $value;
5455
continue;

src/Components/ScriptHandler.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DreamFactory\Core\Utility\Session;
88
use ScriptEngineManager;
99
use Log;
10+
use Illuminate\Support\Arr;
1011

1112
trait ScriptHandler
1213
{
@@ -48,23 +49,23 @@ public function handleScript($identifier, $script, $type, $config, &$data, $log_
4849
throw new InternalServerErrorException($message);
4950
}
5051

51-
if (!empty($ex = array_get($result, 'exception'))) {
52+
if (!empty($ex = Arr::get($result, 'exception'))) {
5253
if ($ex instanceof \Exception) {
5354
throw $ex;
5455
} elseif (is_array($ex)) {
55-
$code = array_get($ex, 'code', null);
56-
$message = array_get($ex, 'message', 'Unknown scripting error.');
57-
$status = array_get($ex, 'status_code', HttpStatusCodeInterface::HTTP_INTERNAL_SERVER_ERROR);
56+
$code = Arr::get($ex, 'code', null);
57+
$message = Arr::get($ex, 'message', 'Unknown scripting error.');
58+
$status = Arr::get($ex, 'status_code', HttpStatusCodeInterface::HTTP_INTERNAL_SERVER_ERROR);
5859
throw new RestException($status, $message, $code);
5960
}
6061
throw new InternalServerErrorException(strval($ex));
6162
}
6263

6364
// check for directly returned results, otherwise check for "response"
64-
if (!empty($response = array_get($result, 'script_result'))) {
65+
if (!empty($response = Arr::get($result, 'script_result'))) {
6566
if (isset($response, $response['error'])) {
6667
if (is_array($response['error'])) {
67-
$msg = array_get($response, 'error.message');
68+
$msg = Arr::get($response, 'error.message');
6869
} else {
6970
$msg = $response['error'];
7071
}

src/Components/ScriptSession.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace DreamFactory\Core\Script\Components;
33

4+
use Illuminate\Support\Arr;
5+
46
/**
57
* Scripting session object
68
*/
@@ -68,6 +70,6 @@ public function set($key, $value)
6870
*/
6971
public function get($key, $defaultValue = null)
7072
{
71-
return array_get($this->data, $key, $defaultValue);
73+
return Arr::get($this->data, $key, $defaultValue);
7274
}
7375
}

src/Engines/ExecutedEngine.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DreamFactory\Core\Exceptions\ServiceUnavailableException;
88
use DreamFactory\Core\Script\Components\BaseEngineAdapter;
99
use \Log;
10+
use Illuminate\Support\Arr;
1011

1112
/**
1213
* Abstract class for command executed engines, i.e. those outside of PHP control
@@ -31,7 +32,7 @@ public function __construct(array $settings = [])
3132
} catch (\Exception $ex) {
3233
throw new ServiceUnavailableException($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
3334
}
34-
if (empty($this->commandName = array_get($settings, 'command_name'))) {
35+
if (empty($this->commandName = Arr::get($settings, 'command_name'))) {
3536
throw new ServiceUnavailableException("Invalid configuration: missing command name.");
3637
}
3738

@@ -113,7 +114,7 @@ public static function loadScriptingModule($module)
113114
$module = trim(str_replace(["'", '"'], null, $module), ' /');
114115

115116
// Check the configured script paths
116-
if (null === ($script = array_get(static::$libraries, $module))) {
117+
if (null === ($script = Arr::get(static::$libraries, $module))) {
117118
$script = $module;
118119
}
119120

src/Engines/NodeJs.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace DreamFactory\Core\Script\Engines;
33

44
use Cache;
5+
use Illuminate\Support\Arr;
56

67
/**
78
* Plugin for the Node Javascript engine
@@ -42,7 +43,7 @@ public function __construct(array $settings = [])
4243

4344
parent::__construct($settings);
4445

45-
$extensions = array_get($settings, 'extensions', []);
46+
$extensions = Arr::get($settings, 'extensions', []);
4647
// accept comma-delimited string
4748
$this->extensions =
4849
(is_string($extensions)) ? array_map('trim', explode(',', trim($extensions, ','))) : $extensions;
@@ -62,16 +63,16 @@ protected function enrobeScript($script, array &$data = [], array $platform = []
6263
$jsonEvent = $this->safeJsonEncode($data, false);
6364
$jsonPlatform = json_encode($platform, JSON_UNESCAPED_SLASHES);
6465
$protocol = config('df.scripting.default_protocol', 'http');
65-
$https = array_get($_SERVER, 'HTTPS');
66-
if ((!empty($https) && ('off' != $https)) || (443 == array_get($_SERVER, 'SERVER_PORT'))) {
66+
$https = Arr::get($_SERVER, 'HTTPS');
67+
if ((!empty($https) && ('off' != $https)) || (443 == Arr::get($_SERVER, 'SERVER_PORT'))) {
6768
$protocol = "https";
6869
}
6970
$token = uniqid();
70-
$apiKey = array_get($platform, 'session.api_key');
71-
$sessionToken = array_get($platform, 'session.session_token');
71+
$apiKey = Arr::get($platform, 'session.api_key');
72+
$sessionToken = Arr::get($platform, 'session.session_token');
7273
$tokenCache = [
73-
'app_id' => array_get($platform, 'session.app.id'),
74-
'user_id' => array_get($platform, 'session.user.id')
74+
'app_id' => Arr::get($platform, 'session.app.id'),
75+
'user_id' => Arr::get($platform, 'session.user.id')
7576
];
7677
Cache::add('script-token:' . $token, $tokenCache, 300); // script should not take longer than 300 seconds to run
7778

src/Engines/Python.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace DreamFactory\Core\Script\Engines;
44

55
use Cache;
6+
use Illuminate\Support\Arr;
67

78
class Python extends ExecutedEngine
89
{
@@ -67,16 +68,16 @@ protected function enrobeScript($script, array &$data = [], array $platform = []
6768
);
6869

6970
$protocol = config('df.scripting.default_protocol', 'http');
70-
$https = array_get($_SERVER, 'HTTPS');
71-
if ((!empty($https) && ('off' != $https)) || (443 == array_get($_SERVER, 'SERVER_PORT'))) {
71+
$https = Arr::get($_SERVER, 'HTTPS');
72+
if ((!empty($https) && ('off' != $https)) || (443 == Arr::get($_SERVER, 'SERVER_PORT'))) {
7273
$protocol = 'https';
7374
}
7475
$token = uniqid();
75-
$apiKey = array_get($platform, 'session.api_key');
76-
$sessionToken = array_get($platform, 'session.session_token');
76+
$apiKey = Arr::get($platform, 'session.api_key');
77+
$sessionToken = Arr::get($platform, 'session.session_token');
7778
$tokenCache = [
78-
'app_id' => array_get($platform, 'session.app.id'),
79-
'user_id' => array_get($platform, 'session.user.id')
79+
'app_id' => Arr::get($platform, 'session.app.id'),
80+
'user_id' => Arr::get($platform, 'session.user.id')
8081
];
8182
Cache::add('script-token:'.$token, $tokenCache, 300); // script should not take longer than 300 seconds to run
8283

src/Engines/Python3.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace DreamFactory\Core\Script\Engines;
44

55
use Cache;
6+
use Illuminate\Support\Arr;
67

78
class Python3 extends ExecutedEngine
89
{
@@ -68,14 +69,14 @@ protected function enrobeScript($script, array &$data = [], array $platform = []
6869
);
6970

7071
$protocol = config('df.scripting.default_protocol', 'http');
71-
$https = array_get($_SERVER, 'HTTPS');
72-
if ((!empty($https) && ('off' != $https)) || (443 == array_get($_SERVER, 'SERVER_PORT'))) {
72+
$https = Arr::get($_SERVER, 'HTTPS');
73+
if ((!empty($https) && ('off' != $https)) || (443 == Arr::get($_SERVER, 'SERVER_PORT'))) {
7374
$protocol = 'https';
7475
}
7576
$token = uniqid();
7677
$tokenCache = [
77-
'app_id' => array_get($platform, 'session.app.id'),
78-
'user_id' => array_get($platform, 'session.user.id')
78+
'app_id' => Arr::get($platform, 'session.app.id'),
79+
'user_id' => Arr::get($platform, 'session.user.id')
7980
];
8081
Cache::add('script-token:'.$token, $tokenCache, 300); // script should not take longer than 300 seconds to run
8182

@@ -220,6 +221,6 @@ class Api:
220221
/** @inheritdoc */
221222
protected function checkOutputStringForData($output)
222223
{
223-
return ((strlen($output) > 10) && (false !== strpos($output, 'request')));
224+
return ((strlen($output) > 10) && (str_contains($output, 'request')));
224225
}
225226
}

0 commit comments

Comments
 (0)