11<?php
22namespace DreamFactory \Core \Script \Components ;
33
4+ use Cache ;
5+ use Config ;
46use DreamFactory \Core \Components \ExceptionResponse ;
57use DreamFactory \Core \Script \Contracts \ScriptingEngineInterface ;
68use DreamFactory \Core \Enums \DataFormats ;
7- use DreamFactory \Core \Enums \ServiceRequestorTypes ;
89use DreamFactory \Core \Script \Exceptions \ScriptException ;
910use DreamFactory \Core \Exceptions \RestException ;
1011use DreamFactory \Core \Exceptions \ServiceUnavailableException ;
1112use DreamFactory \Core \Utility \ResponseFactory ;
1213use DreamFactory \Core \Utility \Session ;
1314use DreamFactory \Core \Utility \Curl ;
1415use DreamFactory \Core \Enums \Verbs ;
15- use Cache ;
16- use Config ;
1716use Illuminate \Support \Arr ;
1817use 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 {
@@ -367,7 +369,14 @@ protected static function externalRequest($method, $url, $payload = [], $curlOpt
367369 throw new RestException ($ status , $ result , $ status );
368370 }
369371
370- return ResponseFactory::create ($ result , $ contentType , $ status );
372+ $ resultHeaders = Curl::getLastResponseHeaders ();
373+ if ('chunked ' === array_get (array_change_key_case ($ resultHeaders , CASE_LOWER ), 'transfer-encoding ' )) {
374+ // don't relay this header through to client as it isn't handled well in some cases
375+ unset($ resultHeaders ['Transfer-Encoding ' ]); // normal header case
376+ unset($ resultHeaders ['transfer-encoding ' ]); // Restlet has all lower for this header
377+ }
378+
379+ return ResponseFactory::create ($ result , $ contentType , $ status , $ resultHeaders );
371380 }
372381
373382 /**
@@ -377,6 +386,7 @@ protected static function externalRequest($method, $url, $payload = [], $curlOpt
377386 * @param array $curlOptions Additional CURL options for external requests
378387 *
379388 * @return array
389+ * @throws \DreamFactory\Core\Exceptions\BadRequestException
380390 */
381391 public static function inlineRequest ($ method , $ path , $ payload = null , $ curlOptions = [])
382392 {
@@ -433,14 +443,11 @@ public static function inlineRequest($method, $path, $payload = null, $curlOptio
433443 $ format = DataFormats::TEXT ;
434444 }
435445
436- Session::checkServicePermission ($ method , $ serviceName , $ resource , ServiceRequestorTypes::SCRIPT );
437-
438446 $ request = new ScriptServiceRequest ($ method , $ params , $ headers );
439447 $ request ->setContent ($ payload , $ format );
440448
441449 // Now set the request object and go...
442- $ service = ServiceManager::getService ($ serviceName );
443- $ result = $ service ->handleRequest ($ request , $ resource );
450+ $ result = ServiceManager::handleServiceRequest ($ request , $ serviceName , $ resource );
444451 }
445452 } catch (\Exception $ ex ) {
446453 $ result = static ::exceptionToServiceResponse ($ ex );
0 commit comments