Skip to content

Commit d98b3b3

Browse files
author
Lee Hicks
committed
Cleanup use of checkServicePermission
1 parent 39c0d87 commit d98b3b3

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/Components/BaseEngineAdapter.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
<?php
22
namespace DreamFactory\Core\Script\Components;
33

4+
use Cache;
5+
use Config;
46
use DreamFactory\Core\Components\ExceptionResponse;
57
use DreamFactory\Core\Script\Contracts\ScriptingEngineInterface;
68
use DreamFactory\Core\Enums\DataFormats;
7-
use DreamFactory\Core\Enums\ServiceRequestorTypes;
89
use DreamFactory\Core\Script\Exceptions\ScriptException;
910
use DreamFactory\Core\Exceptions\RestException;
1011
use DreamFactory\Core\Exceptions\ServiceUnavailableException;
1112
use DreamFactory\Core\Utility\ResponseFactory;
1213
use DreamFactory\Core\Utility\Session;
1314
use DreamFactory\Core\Utility\Curl;
1415
use DreamFactory\Core\Enums\Verbs;
15-
use Cache;
16-
use Config;
1716
use Illuminate\Support\Arr;
1817
use ServiceManager;
1918

@@ -53,7 +52,6 @@ abstract class BaseEngineAdapter implements ScriptingEngineInterface
5352
/**
5453
* @param array $settings
5554
*
56-
* @throws ServiceUnavailableException
5755
*/
5856
public function __construct(array $settings = [])
5957
{
@@ -65,6 +63,7 @@ public function __construct(array $settings = [])
6563
* @param array $options
6664
*
6765
* @return void
66+
* @throws ServiceUnavailableException
6867
*/
6968
public static function startup($options = null)
7069
{
@@ -115,7 +114,6 @@ abstract public function executeString($path, $identifier, array &$data = [], ar
115114
*
116115
* @return array
117116
* @throws ScriptException
118-
* @throws ServiceUnavailableException
119117
*/
120118
public function runScript(
121119
$script,
@@ -167,9 +165,6 @@ public function runScript(
167165
*/
168166
public static function loadScript($name, $path = null, $returnContents = true)
169167
{
170-
if ($path) {
171-
// no longer support file paths for scripts?
172-
}
173168
// Already read, return script
174169
if (null !== ($script = array_get(static::$libraries, $name))) {
175170
return $returnContents ? file_get_contents($script) : $script;
@@ -178,8 +173,8 @@ public static function loadScript($name, $path = null, $returnContents = true)
178173
$script = ltrim($script, ' /');
179174

180175
// Spin through paths and look for the script
181-
foreach (static::$libraryPaths as $path) {
182-
$check = $path . '/' . $script;
176+
foreach (static::$libraryPaths as $libPath) {
177+
$check = $libPath . '/' . $script;
183178

184179
if (is_file($check) && is_readable($check)) {
185180
array_set(static::$libraries, $name, $check);
@@ -188,13 +183,20 @@ public static function loadScript($name, $path = null, $returnContents = true)
188183
}
189184
}
190185

186+
if ($path) {
187+
if (is_file($path) && is_readable($path)) {
188+
array_set(static::$libraries, $name, $path);
189+
190+
return $returnContents ? file_get_contents($path) : $path;
191+
}
192+
}
193+
191194
return false;
192195
}
193196

194197
/**
195198
* @param array $libraryPaths
196199
*
197-
* @throws ServiceUnavailableException
198200
*/
199201
protected static function initializeLibraryPaths($libraryPaths = null)
200202
{
@@ -384,6 +386,7 @@ protected static function externalRequest($method, $url, $payload = [], $curlOpt
384386
* @param array $curlOptions Additional CURL options for external requests
385387
*
386388
* @return array
389+
* @throws \DreamFactory\Core\Exceptions\BadRequestException
387390
*/
388391
public static function inlineRequest($method, $path, $payload = null, $curlOptions = [])
389392
{
@@ -440,14 +443,11 @@ public static function inlineRequest($method, $path, $payload = null, $curlOptio
440443
$format = DataFormats::TEXT;
441444
}
442445

443-
Session::checkServicePermission($method, $serviceName, $resource, ServiceRequestorTypes::SCRIPT);
444-
445446
$request = new ScriptServiceRequest($method, $params, $headers);
446447
$request->setContent($payload, $format);
447448

448449
// Now set the request object and go...
449-
$service = ServiceManager::getService($serviceName);
450-
$result = $service->handleRequest($request, $resource);
450+
$result = ServiceManager::handleServiceRequest($request, $serviceName, $resource);
451451
}
452452
} catch (\Exception $ex) {
453453
$result = static::exceptionToServiceResponse($ex);

src/Engines/ExecutedEngine.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function executeString($script, $identifier, array &$data = [], array $en
9292
* @param array $engineArguments An array of arguments to pass when executing the string
9393
*
9494
* @return mixed
95+
* @throws InternalServerErrorException
9596
*/
9697
public function executeScript($path, $identifier, array &$data = [], array $engineArguments = [])
9798
{

0 commit comments

Comments
 (0)