/** * @param array $settings * * @throws ServiceUnavailableException */ public function __construct(array $settings = []) { parent::__construct($settings); if (!extension_loaded('v8js')) { throw new ServiceUnavailableException("This instance cannot run server-side javascript scripts. The 'v8js' is not available."); } $name = ArrayUtils::get($settings, 'name', self::EXPOSED_OBJECT_NAME, true); $variables = ArrayUtils::get($settings, 'variables', [], true); $extensions = ArrayUtils::get($settings, 'extensions', [], true); // accept comma-delimited string $extensions = is_string($extensions) ? array_map('trim', explode(',', trim($extensions, ','))) : $extensions; $reportUncaughtExceptions = ArrayUtils::getBool($settings, 'report_uncaught_exceptions', false); $logMemoryUsage = ArrayUtils::getBool($settings, 'log_memory_usage', false); static::startup($settings); // Set up our script mappings for module loading /** @noinspection PhpUndefinedClassInspection */ $this->engine = new \V8Js($name, $variables, $extensions, $reportUncaughtExceptions); /** * This is the callback for the exposed "require()" function in the sandbox */ if (static::$moduleLoaderAvailable) { /** @noinspection PhpUndefinedMethodInspection */ $this->engine->setModuleLoader(function ($module) { return static::loadScriptingModule($module); }); } else { /** @noinspection PhpUndefinedClassInspection */ Log::debug(' * no "require()" support in V8 library v' . \V8Js::V8_VERSION); } if ($logMemoryUsage) { /** @noinspection PhpUndefinedMethodInspection */ $loadedExtensions = $this->engine->getExtensions(); Log::debug(' * engine created with the following extensions: ' . (!empty($loadedExtensions) ? implode(', ', array_keys($loadedExtensions)) : '**NONE**')); } }
/** * @param array $settings * * @throws ServiceUnavailableException */ public function __construct(array $settings = []) { parent::__construct($settings); if (empty($this->commandPath)) { $this->commandPath = static::findCommandPath(); if (empty($this->commandPath)) { throw new ServiceUnavailableException("Failed to find a valid path to NodeJs."); } } $extensions = ArrayUtils::get($settings, 'extensions', [], true); // accept comma-delimited string $this->extensions = is_string($extensions) ? array_map('trim', explode(',', trim($extensions, ','))) : $extensions; static::startup($settings); }