コード例 #1
0
ファイル: V8Js.php プロジェクト: df-arif/df-core
 /**
  * Registers all distribution library modules as extensions.
  * These can be accessed from scripts like this:
  *
  * require("lodash");
  *
  * var a = [ 'one', 'two', 'three' ];
  *
  * _.each( a, function( element ) {
  *      print( "Found " + element + " in array\n" );
  * });
  *
  * Please note that this requires a version of the V8 library above any that are currently
  * distributed with popular distributions. As such, if this feature is not available
  * (module loading), the "lodash" library will be automatically registered and injected
  * into all script contexts.
  *
  * @param array $extensions
  *
  * @return array
  * @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
  */
 protected static function registerExtensions(array $extensions = [])
 {
     /** @noinspection PhpUndefinedClassInspection */
     $existing = \V8Js::getExtensions();
     $registered = array_diff($extensions, $existing);
     foreach ($registered as $module) {
         /** @noinspection PhpUndefinedClassInspection */
         if (false === \V8Js::registerExtension($module, static::loadScriptingModule($module), [], false)) {
             throw new InternalServerErrorException('Failed to register V8Js extension script: ' . $module);
         }
     }
     return $registered;
 }