Create and assign a new Script if necessary

@api
@return Script
498512
public function createScript()
    {
        if ($this->script) {
            return $this->script;
        }
        $script = new Script();
        $this->setScript($script);
        return $this->script;
    }
832410
public function setScript(AbstractScript $script): self
    {
        if (!$this instanceof UpdateDocument) {
            throw new \BadMethodCallException('setScript() can only be used for UpdateDocument');
        }

        $this->_data = $script;

        $metadata = $this->_getMetadata($script);
        $this->setMetadata($metadata);

        return $this;
    }
1230427
public function setScripts(array $scripts): self
    {
        $this->_params = [];
        foreach ($scripts as $name => $script) {
            $this->addScript($name, $script);
        }

        return $this;
    }
1199697
public function getScript()
    {
        $this->createCallableObjects();

        $sPrefix = $this->getOption('core.prefix.class');

        $aJsClasses = [];
        $sCode = '';
        foreach(array_keys($this->aNamespaces) as $sNamespace)
        {
            $offset = 0;
            $sJsNamespace = str_replace('\\', '.', $sNamespace);
            $sJsNamespace .= '.Null'; // This is a sentinel. The last token is not processed in the while loop.
            while(($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false)
            {
                $sJsClass = substr($sJsNamespace, 0, $dotPosition);
                // Generate code for this object
                if(!key_exists($sJsClass, $aJsClasses))
                {
                    $sCode .= "$sPrefix$sJsClass = {};\n";
                    $aJsClasses[$sJsClass] = $sJsClass;
                }
                $offset = $dotPosition + 1;
            }
        }

        foreach($this->aCallableObjects as $sClassName => $xCallableObject)
        {
            $aConfig = $this->aCallableOptions[$sClassName];
            $aCommonConfig = key_exists('*', $aConfig) ? $aConfig['*'] : [];

            $aMethods = [];
            foreach($xCallableObject->getMethods() as $sMethodName)
            {
                // Specific options for this method
                $aMethodConfig = key_exists($sMethodName, $aConfig) ?
                    array_merge($aCommonConfig, $aConfig[$sMethodName]) : $aCommonConfig;
                $aMethods[] = [
                    'name' => $sMethodName,
                    'config' => $aMethodConfig,
                ];
            }

            $sCode .= $this->render('jaxon::support/object.js', [
                'sPrefix' => $sPrefix,
                'sClass' => $xCallableObject->getJsName(),
                'aMethods' => $aMethods,
            ]);
        }

        return $sCode;
    }
874269
protected function createNewObject()
    {
        $jwkset = new JWKSet();
        for ($i = 0; $i < $this->nb_keys; ++$i) {
            $key = $this->createJWK();
            $jwkset->addKey($key);
        }

        return $jwkset;
    }
863863
public function generate()
    {
        $options = $this->options;

        $arguments = array_merge([$this->binary], (array) $this->arguments);
        $script    = implode(' ', array_map([ProcessUtils::class, 'escapeArgument'], $arguments));
        $process   = new Process(
            $this->applyForceToBackground($script),
            $this->workingDirectory,
            $this->getEnvironmentVariables(),
            $this->input,
            $this->timeout,
            $options
        );

        if ($this->outputDisabled) {
            $process->disableOutput();
        }

        return $process;
    }
857983
public function script()
    {
        echo $this->view->make('Assely::script', [
            'slug' => $this->metabox->getModel()->getSlug(),
            'fingerprint' => $this->metabox->getModel()->getFingerprint(),
            'fields' => json_encode($this->metabox->getFields()->all()),
        ]);
    }
937222
protected function createScripts(stdClass $scripts = null)
    {
        if (null !== $scripts) {
            $scriptsData = new ObjectAccess($scripts);
            $scripts = new ScriptConfiguration(
                $this->arrayize($scriptsData->getDefault('pre-install-cmd')),
                $this->arrayize($scriptsData->getDefault('post-install-cmd')),
                $this->arrayize($scriptsData->getDefault('pre-update-cmd')),
                $this->arrayize($scriptsData->getDefault('post-update-cmd')),
                $this->arrayize($scriptsData->getDefault('pre-status-cmd')),
                $this->arrayize($scriptsData->getDefault('post-status-cmd')),
                $this->arrayize($scriptsData->getDefault('pre-package-install')),
                $this->arrayize($scriptsData->getDefault('post-package-install')),
                $this->arrayize($scriptsData->getDefault('pre-package-update')),
                $this->arrayize($scriptsData->getDefault('post-package-update')),
                $this->arrayize($scriptsData->getDefault('pre-package-uninstall')),
                $this->arrayize($scriptsData->getDefault('post-package-uninstall')),
                $this->arrayize($scriptsData->getDefault('pre-autoload-dump')),
                $this->arrayize($scriptsData->getDefault('post-autoload-dump')),
                $this->arrayize($scriptsData->getDefault('post-root-package-install')),
                $this->arrayize($scriptsData->getDefault('post-create-project-cmd')),
                $scriptsData->data()
            );
        }

        return $scripts;
    }
804664
public function getScript()
    {
        $this->useSingleQuotes();
        foreach($this->aArguments as $xArgument)
        {
            if($xArgument instanceof Element)
            {
                $this->addParameter(Jaxon::JS_VALUE, $xArgument->getScript());
            }
            else if($xArgument instanceof Parameter)
            {
                $this->addParameter($xArgument->getType(), $xArgument->getValue());
            }
            else if($xArgument instanceof Request)
            {
                $this->addParameter(Jaxon::JS_VALUE, 'function(){' . $xArgument->getScript() . ';}');
            }
            else if(is_numeric($xArgument))
            {
                $this->addParameter(Jaxon::NUMERIC_VALUE, $xArgument);
            }
            else if(is_string($xArgument))
            {
                $this->addParameter(Jaxon::QUOTED_VALUE, $xArgument);
            }
            else if(is_bool($xArgument))
            {
                $this->addParameter(Jaxon::BOOL_VALUE, $xArgument);
            }
            else if(is_array($xArgument) || is_object($xArgument))
            {
                $this->addParameter(Jaxon::JS_VALUE, $xArgument);
            }
        }
        return $this->sMethod . '(' . implode(', ', $this->aParameters) . ')';
    }
684612
def create
      @script_version = Script::Version.new(script_version_params)
      @script_version.user_id = current_user.id
      @script_version.org_id = current_user.org_id
      if @script_version.save
        redirect_to script_versions_url, notice: 'Version was successfully created.'
        else
          render :new
      end
    end
1303363
protected function getScript()
    {
        $apiUrl = trim($this->getTemplateVariable('api_url'));
        $apiKey = trim($this->getTemplateVariable('api_key'));

        $delivery = $this->getTemplateVariable('delivery');
        if (!$delivery) {
            $delivery = 'script';
        }
        $response = $this->getTemplateVariable('response');

        $failedValue = ($delivery === 'script' && $response === 'json') ?
            '{} /* sourcepoint failed */' : '<!--sourcepoint-failed-->';
        $cacheKey = sprintf('wblib:sourcepoint:script:%s:%s', $delivery, $response);

        if (empty($apiUrl) || empty($apiKey)) {
            return ['data' => ['script' => $failedValue]];
        }

        $cachedScript = $this->cacheStore->get($cacheKey);
        if (false !== $cachedScript) {
            return ['data' => ['script' => $cachedScript]];
        }

        $scriptEndpoint = sprintf('%sscript/detection?delivery=%s', $apiUrl, $delivery);
        $script = null;

        try {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $scriptEndpoint);
            curl_setopt($curl, CURLOPT_HTTPHEADER, [sprintf('Authorization: Token %s', $apiKey)]);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1);
            curl_setopt($curl, CURLOPT_TIMEOUT, 1);

            $script = trim(curl_exec($curl));
            $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

            curl_close($curl);

            if ((200 <= $httpCode) && ($httpCode < 400)) {
                if ($delivery === 'script' && $response === 'json') {
                    $el = new SimpleXmlElement($script);
                    $attributes = (array) $el->attributes();
                    $attributesArr = $attributes['@attributes'];
                    $script = json_encode($attributesArr);
                    $this->cacheStore->put($cacheKey, $script, $this->cacheTtl);
                } else {
                    // This can be a number of different formats
                    // URL: https://analytics.sourcepoint.com/doc/index#get-script-as-tag-on-page
                    // e.g.: <script async="async" data-client-id="YOUR_CLIENT_ID" type="text/javascript" src="//d3ujids68p6xmq.cloudfront.net/abw.js"></script>
                    // e.g.: <script data-client-id="YOUR_CLIENT_ID" type="text/javascript">function detect() {};</script>
                    // e.g.: function detect() {};
                    $this->cacheStore->put($cacheKey, $script, $this->cacheTtl);
                }
            } else {
                $this->Logger->error(sprintf('Received an HTTP error code: %s', $httpCode));
                $script = $failedValue;
                $this->cacheStore->put($cacheKey, $failedValue, $this->failedCacheTtl);
            }
        } catch (\Exception $e) {
            $this->Logger->error(sprintf('CURL to [%s] failed with: %s', $scriptEndpoint, $e->getMessage()));
            $this->cacheStore->put($cacheKey, $failedValue, $this->failedCacheTtl);
        }

        return ['data' => ['script' => $script]];
    }
323628
def script(self):
        """"""
        # The script object is cached, since constructing it may involve
        # a number of string-manipulation operations.
        if getattr(self, '_script', None) is None:
            self._script = self._script__getter()
        return self._script
343029
protected function load_script($script_name = null)
    {
        // Get list of scripts
        $list = $this->list_scripts();

        if ($script_name === null || $script_name === '') {
            // get (first) active script
            if (!empty($this->active)) {
               $script_name = $this->active[0];
            }
            else if ($list) {
                $script_name = $list[0];
            }
            // create a new (initial) script
            else {
                // if script not exists build default script contents
                $script_file = $this->rc->config->get('managesieve_default');
                $script_name = $this->rc->config->get('managesieve_script_name');

                if (empty($script_name)) {
                    $script_name = 'roundcube';
                }

                if ($script_file && is_readable($script_file)) {
                    $content = file_get_contents($script_file);
                }

                // add script and set it active
                if ($this->sieve->save_script($script_name, $content)) {
                    $this->activate_script($script_name);
                    $this->list[] = $script_name;
                }
            }
        }

        if ($script_name) {
            $this->sieve->load($script_name);
        }

        return $this->sieve->error();
    }
513122
public static function js($scripts = array(), $attr = array(), $group = NULL, $raw = false)
	{
		return static::instance()->js($scripts, $attr, $group, $raw);
	}
322937
public function scripts($script = null, array $attributes = ['type' => 'text/javascript'])
    {
        $script = $script ?: $this->generateScripts();
        $attributes = $this->html->attributes($attributes);

        return new HtmlString("<script{$attributes}>{$script}</script>\n");
    }
580241
public function prepare(Script $script)
    {
        $script->addCustomScriptLabel(ScriptLabel::MouseClick, $this->getScriptMouseClick());
        $script->addCustomScriptLabel(ScriptLabel::OnInit, $this->getScriptInit());
        $script->addCustomScriptLabel(ScriptLabel::Loop, $this->getScriptLoop());
    }
1098402
public static function create($name, $script)
    {
        $object = get_class(self::$driver);
        //
        return $object::create($name, $script);
    }