Skip to content

Commit 8e902d2

Browse files
author
Lee Hicks
committed
Merge branch 'release/0.8.0'
2 parents 22bb840 + 770c908 commit 8e902d2

13 files changed

Lines changed: 67 additions & 97 deletions

.dreamfactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* DreamFactory(tm) Core <http://github.com/dreamfactorysoftware/df-core>
4-
* Copyright 2012-2015 DreamFactory Software, Inc. <support@dreamfactory.com>
4+
* Copyright 2012-2018 DreamFactory Software, Inc. <dspsupport@dreamfactory.com>
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased]
6+
## [0.8.0] - 2017-12-28
7+
### Added
8+
- DF-1254 Allowed setting response headers in all cases
9+
- Added package discovery
10+
### Changed
11+
- DF-1226 Removed deprecated v8js extension methods
12+
- Used new df-system repository
13+
- DF-1150 Updated copyright and support email
14+
- Reworked service request types
15+
- Cleanup use of checkServicePermission
16+
617
## [0.7.0] - 2017-11-03
718
### Changed
819
- DF-1222 Removing write to database from script caching so that lookups are not processed prematurely
@@ -64,7 +75,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
6475
## 0.1.0 - 2016-11-30
6576
First official release working with the new [dreamfactory](https://github.com/dreamfactorysoftware/dreamfactory) project.
6677

67-
[Unreleased]: https://github.com/dreamfactorysoftware/df-script/compare/0.7.0...HEAD
78+
[Unreleased]: https://github.com/dreamfactorysoftware/df-script/compare/0.8.0...HEAD
79+
[0.8.0]: https://github.com/dreamfactorysoftware/df-script/compare/0.7.0...0.8.0
6880
[0.7.0]: https://github.com/dreamfactorysoftware/df-script/compare/0.6.2...0.7.0
6981
[0.6.2]: https://github.com/dreamfactorysoftware/df-script/compare/0.6.1...0.6.2
7082
[0.6.1]: https://github.com/dreamfactorysoftware/df-script/compare/0.6.0...0.6.1

composer.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@
2424
"email": "leehicks@dreamfactory.com"
2525
}
2626
],
27+
"support": {
28+
"email": "dspsupport@dreamfactory.com",
29+
"source": "https://github.com/dreamfactorysoftware/df-script",
30+
"issues": "https://github.com/dreamfactorysoftware/df-script/issues",
31+
"wiki": "https://wiki.dreamfactory.com"
32+
},
2733
"require": {
28-
"dreamfactory/df-core": "~0.13.0"
34+
"dreamfactory/df-core": "~0.14.0",
35+
"dreamfactory/df-system": "~0.1.0"
2936
},
3037
"autoload": {
3138
"psr-4": {
@@ -34,7 +41,12 @@
3441
},
3542
"extra": {
3643
"branch-alias": {
37-
"dev-develop": "0.7.x-dev"
44+
"dev-develop": "0.8.x-dev"
45+
},
46+
"laravel": {
47+
"providers": [
48+
"DreamFactory\\Core\\Script\\ServiceProvider"
49+
]
3850
}
3951
}
4052
}

src/Components/BaseEngineAdapter.php

Lines changed: 23 additions & 16 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
{
@@ -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);

src/Components/ScriptServiceRequest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,14 @@
1010
* Class ScriptServiceRequest
1111
*
1212
*/
13-
class ScriptServiceRequest implements ServiceRequestInterface
13+
class ScriptServiceRequest extends InternalServiceRequest implements ServiceRequestInterface
1414
{
15-
use InternalServiceRequest;
15+
protected $requestorType = ServiceRequestorTypes::SCRIPT;
1616

1717
public function __construct($method = Verbs::GET, $parameters = [], $headers = [])
1818
{
1919
$this->setMethod($method);
2020
$this->setParameters($parameters);
2121
$this->setHeaders($headers);
2222
}
23-
24-
/**
25-
* {@inheritdoc}
26-
*/
27-
public function getRequestorType()
28-
{
29-
return ServiceRequestorTypes::SCRIPT;
30-
}
3123
}

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
{

src/Engines/V8Js.php

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,20 @@ public function __construct(array $settings = [])
5959
parent::__construct($settings);
6060

6161
if (!extension_loaded('v8js')) {
62-
throw new ServiceUnavailableException("This instance cannot run server-side javascript scripts. The 'v8js' is not available.");
62+
throw new ServiceUnavailableException("This instance cannot run server-side javascript scripts. The 'v8js' extension is not available.");
6363
}
6464

6565
$name = array_get($settings, 'name', self::EXPOSED_OBJECT_NAME);
6666
$variables = array_get($settings, 'variables', []);
6767
$extensions = array_get($settings, 'extensions', []);
6868
// accept comma-delimited string
6969
$extensions = (is_string($extensions)) ? array_map('trim', explode(',', trim($extensions, ','))) : $extensions;
70-
$reportUncaughtExceptions = array_get_bool($settings, 'report_uncaught_exceptions');
71-
$logMemoryUsage = array_get_bool($settings, 'log_memory_usage');
7270

7371
static::startup($settings);
7472

7573
// Set up our script mappings for module loading
7674
/** @noinspection PhpUndefinedClassInspection */
77-
$this->engine = new \V8Js($name, $variables, $extensions, $reportUncaughtExceptions);
75+
$this->engine = new \V8Js($name, $variables, $extensions);
7876

7977
/**
8078
* This is the callback for the exposed "require()" function in the sandbox
@@ -90,16 +88,6 @@ function ($module){
9088
/** @noinspection PhpUndefinedClassInspection */
9189
Log::debug(' * no "require()" support in V8 library v' . \V8Js::V8_VERSION);
9290
}
93-
94-
if ($logMemoryUsage) {
95-
/** @noinspection PhpUndefinedMethodInspection */
96-
$loadedExtensions = $this->engine->getExtensions();
97-
98-
Log::debug(
99-
' * engine created with the following extensions: ' .
100-
(!empty($loadedExtensions) ? implode(', ', array_keys($loadedExtensions)) : '**NONE**')
101-
);
102-
}
10391
}
10492

10593
/**
@@ -117,16 +105,7 @@ public static function startup($options = null)
117105
$mirror = new \ReflectionClass('\\V8Js');
118106

119107
/** @noinspection PhpUndefinedMethodInspection */
120-
if (false !== (static::$moduleLoaderAvailable = $mirror->hasMethod('setModuleLoader'))) {
121-
}
122-
123-
// Register any extensions
124-
if (null !== $extensions = array_get($options, 'extensions', [])) {
125-
// accept comma-delimited string
126-
$extensions =
127-
(is_string($extensions)) ? array_map('trim', explode(',', trim($extensions, ','))) : $extensions;
128-
static::registerExtensions($extensions);
129-
}
108+
static::$moduleLoaderAvailable = $mirror->hasMethod('setModuleLoader');
130109
}
131110

132111
public static function buildPlatformAccess($identifier)
@@ -294,41 +273,6 @@ public static function loadScriptingModule($module)
294273
return $content;
295274
}
296275

297-
/**
298-
* Registers all distribution library modules as extensions.
299-
* These can be accessed from scripts like this:
300-
*
301-
* require("lodash");
302-
*
303-
* var a = [ 'one', 'two', 'three' ];
304-
*
305-
* _.each( a, function( element ) {
306-
* print( "Found " + element + " in array\n" );
307-
* });
308-
*
309-
* Please note that this requires a version of the V8 library equal to or above 0.2.0.
310-
*
311-
* @param array $extensions
312-
*
313-
* @return array
314-
* @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
315-
*/
316-
protected static function registerExtensions(array $extensions = [])
317-
{
318-
/** @noinspection PhpUndefinedClassInspection */
319-
$existing = \V8Js::getExtensions();
320-
$registered = array_diff($extensions, $existing);
321-
322-
foreach ($registered as $module) {
323-
/** @noinspection PhpUndefinedClassInspection */
324-
if (false === \V8Js::registerExtension($module, static::loadScriptingModule($module), [], false)) {
325-
throw new InternalServerErrorException('Failed to register V8Js extension script: ' . $module);
326-
}
327-
}
328-
329-
return $registered;
330-
}
331-
332276
/**
333277
* @param string $script
334278
* @param array $data

src/Handlers/Events/ScriptableEventHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
use DreamFactory\Core\Events\PostProcessApiEvent;
1111
use DreamFactory\Core\Events\PreProcessApiEvent;
1212
use DreamFactory\Core\Events\ServiceEvent;
13-
use DreamFactory\Core\Resources\System\Cache;
1413
use DreamFactory\Core\Script\Components\ScriptHandler;
1514
use DreamFactory\Core\Script\Events\BaseEventScriptEvent;
1615
use DreamFactory\Core\Script\Events\EventScriptDeletedEvent;
1716
use DreamFactory\Core\Script\Events\EventScriptModifiedEvent;
1817
use DreamFactory\Core\Script\Jobs\ServiceEventScriptJob;
1918
use DreamFactory\Core\Script\Models\EventScript;
19+
use DreamFactory\Core\System\Resources\Cache;
2020
use DreamFactory\Core\Utility\ResponseFactory;
2121
use Illuminate\Contracts\Events\Dispatcher;
2222
use Illuminate\Foundation\Bus\DispatchesJobs;
@@ -83,8 +83,9 @@ public function handleApiEvent($event)
8383
$content = array_get($response, 'content');
8484
$contentType = array_get($response, 'content_type');
8585
$status = array_get($response, 'status_code', HttpStatusCodeInterface::HTTP_OK);
86+
$headers = (array)array_get($response, 'headers');
8687

87-
$event->response = ResponseFactory::create($content, $contentType, $status);
88+
$event->response = ResponseFactory::create($content, $contentType, $status, $headers);
8889
} else {
8990
// otherwise assume raw content
9091
$event->response = ResponseFactory::create($response);

src/Jobs/ServiceEventScriptJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Crypt;
66
use DreamFactory\Core\Events\ServiceEvent;
7-
use DreamFactory\Core\Resources\System\Cache;
87
use DreamFactory\Core\Script\Models\EventScript;
8+
use DreamFactory\Core\System\Resources\Cache;
99
use Log;
1010
use Session;
1111

src/Resources/System/EventScript.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use DreamFactory\Core\Exceptions\BadRequestException;
88
use DreamFactory\Core\Exceptions\BatchException;
99
use DreamFactory\Core\Exceptions\InternalServerErrorException;
10-
use DreamFactory\Core\Resources\System\BaseSystemResource;
10+
use DreamFactory\Core\System\Resources\BaseSystemResource;
1111
use DreamFactory\Core\Script\Models\EventScript as EventScriptModel;
1212
use DreamFactory\Core\Utility\ResourcesWrapper;
1313
use DreamFactory\Core\Utility\ResponseFactory;

0 commit comments

Comments
 (0)