Builds an array that can be used as a basis for top level JSON encoding.

This nests reserved values under the 'context' key, where required.

@param array $context
@return array
544272
protected function buildTopLevelArrayNestedForContext(array $context)
    {
        // Context becomes the main level, so anything in context (with some caveats)
        // is moved up to the top level -- by making %context% the main 'message'
        // output in the log line.

        // Rename to prefix context variables with 'reserved' names
        $nested = [];

        foreach ($this->reservedTopLevelKeys as $key) {

            if (array_key_exists($key, $context)) {
                $nested[ $key ] = $context[ $key ];
                unset ($context[ $key ]);
            }
        }

        // The 'context' key is a special case: its value should be merged
        // into the nested context at that level.
        // (So context.context.key becomes context.key)

        if (array_key_exists('context', $context)) {

            if ( ! is_array($context['context'])) {
                $context['context'] = (array) $context['context'];
            }

            $context['context'] = array_merge($context['context'], $nested);

        } else {
            // if it does not exist yet, just make a nested context
            $context['context'] = $nested;
        }

        return $context;
    }
1280011
private function resolveContext(array $context)
    {
        $defaultOptions = [
            self::OPTION_EXCEPTION_ON_INVALID_TYPE => $this->exceptionOnInvalidType,
            self::OPTION_OBJECT                    => $this->object,
            self::OPTION_OBJECT_FOR_MAP            => $this->objectForMap,
            self::OPTION_DATE_TIME                 => $this->dateTime,
        ];

        return array_merge($defaultOptions, $context);
    }
92046
protected function printContext(array $context)
    {
        $res = '';
        foreach ($context as $name => $val) {
            // bypass internal context
            if (substr($name, 0, 2) === '__') {
                continue;
            }

            // concat contexts
            $res .= " $name: " . strval($val);
        }
        return $res ?: '';
    }
383447
public static function stringifyAssetDeliveryPolicyConfigurationKey(array $array)
    {
        $jsonArray = [];
        foreach ($array as $key => $value) {
            $jsonArray[] = ['Key' => $key, 'Value' => $value];
        }

        return json_encode($jsonArray);
    }
1074762
protected function formatContext(array $vars, array $context)
    {
        // Set top-level data in the 'context', merging to get those keys in front
        $context = array_merge([
            'timestamp' => $this->stringify($vars['datetime']),
            'channel'   => $this->stringify($vars['channel']),
            'severity'  => $this->stringify($vars['level_name']),
            'level'     => $vars['level'],
            'message'   => $vars['message'],
        ], $context);

        return $this->stringify($context) . "\n";
    }
936549
protected function assimilateContext(array $context = [])
    {
        $this->_context_ = $context;
        foreach ($context as $key => $value) {
            $this->$key = $value;
        }
    }
142471
protected function buildEntityCreatePayload(EntityInterface $entity, array $context = []): string
    {
        return $this->getEntitySerializer()->serialize($entity, 'json', $context);
    }
948437
public static function buildArray($object) {
        $array = array();

        foreach ($object as $key => $value) {
            if (is_object($value) || is_array($value)) {
                $array[$key] = static::buildArray($value);
            } else {
                $array[$key] = static::autobox($value);
            }
        }

        return $array;
    }
948047
protected function serializeArray(array $array) {
        $data = [];

        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $data[$key] = $this->serializeArray($value);
            } else {
                $data[$key] = $this->serializeItem($value);
            }
        }

        return $data;
    }
1270502
public function loadFromJson($context=null)
  {
    if($context==null)
      $context = getenv('ERDIKO_CONTEXT');

    return \erdiko\core\Helper::getConfig("authorize",$context);
  }
1181049
public function buildAttrFromArray(array $array)
    {
        $attributes = [];

        foreach ($array as $attribute => $data) {
            if (is_array($data)) {
                $data = implode(' ', $data);
            }

            $attributes[] = $attribute . '="' . htmlspecialchars($data) . '"';
        }

        return $attributes ? ' ' . implode(' ', $attributes) : '';
    }
135682
public static function constants($context) {
        if ($context['flags']['standalone'] == 0) {
            return 'array()';
        }

        $class = new \ReflectionClass($context['runtime']);
        $constants = $class->getConstants();
        $ret = " array(\n";
        foreach($constants as $name => $value) {
            $ret .= "            '$name' => ".  (is_string($value) ? "'$value'" : $value ) . ",\n";
        }
        $ret .= "        )";
        return $ret;
    }
776127
public function getInitRollbarCode(array $context)
    {
        $accessToken = $this->notifierOptions['access_token'];

        $config = array(
            'accessToken' => $accessToken,
            'captureUncaught' => true,
            'payload' => array(
                'environment' => $this->environmentOptions['environment'],
            ),
        );

        $user = $context['app']->getUser();
        if (isset($user)) {
            $config['payload']['person'] = $this->userHelper->buildUserData($user);
        }

        if ($this->notifierOptions['source_map_enabled']) {
            $config['payload']['client'] = array(
                'javascript' => array(
                    'source_map_enabled' => $this->notifierOptions['source_map_enabled'],
                    'code_version' => $this->notifierOptions['code_version'],
                    'guess_uncaught_frames' => $this->notifierOptions['guess_uncaught_frames'],
                ),
            );
        }

        $rollbarJsVersion = $this->notifierOptions['rollbarjs_version'];

        $config = json_encode($config);

        $checkIgnoreConfig = $this->getCheckIgnoreConfig();

        $transform = $this->transformPayloadFunctionProvider->getTransformFunctionCode();

        return <<<END_HTML
<script>
var _rollbarConfig = {$config};
_rollbarConfig.transform = {$transform};
// Rollbar Snippet
!function(r){function o(e){if(t[e])return t[e].exports;var n=t[e]={exports:{},id:e,loaded:!1};return r[e].call(n.exports,n,n.exports,o),n.loaded=!0,n.exports}var t={};return o.m=r,o.c=t,o.p="",o(0)}([function(r,o,t){"use strict";var e=t(1).Rollbar,n=t(2);_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||"https://d37gvrvc0wt4s1.cloudfront.net/js/{$rollbarJsVersion}/rollbar.min.js";var a=e.init(window,_rollbarConfig),i=n(a,_rollbarConfig);a.loadFull(window,document,!_rollbarConfig.async,_rollbarConfig,i)},function(r,o){"use strict";function t(r){return function(){try{return r.apply(this,arguments)}catch(o){try{console.error("[Rollbar]: Internal error",o)}catch(t){}}}}function e(r,o,t){window._rollbarWrappedError&&(t[4]||(t[4]=window._rollbarWrappedError),t[5]||(t[5]=window._rollbarWrappedError._rollbarContext),window._rollbarWrappedError=null),r.uncaughtError.apply(r,t),o&&o.apply(window,t)}function n(r){var o=function(){var o=Array.prototype.slice.call(arguments,0);e(r,r._rollbarOldOnError,o)};return o.belongsToShim=!0,o}function a(r){this.shimId=++s,this.notifier=null,this.parentShim=r,this._rollbarOldOnError=null}function i(r){var o=a;return t(function(){if(this.notifier)return this.notifier[r].apply(this.notifier,arguments);var t=this,e="scope"===r;e&&(t=new o(this));var n=Array.prototype.slice.call(arguments,0),a={shim:t,method:r,args:n,ts:new Date};return window._rollbarShimQueue.push(a),e?t:void 0})}function l(r,o){if(o.hasOwnProperty&&o.hasOwnProperty("addEventListener")){var t=o.addEventListener;o.addEventListener=function(o,e,n){t.call(this,o,r.wrap(e),n)};var e=o.removeEventListener;o.removeEventListener=function(r,o,t){e.call(this,r,o&&o._wrapped?o._wrapped:o,t)}}}var s=0;a.init=function(r,o){var e=o.globalAlias||"Rollbar";if("object"==typeof r[e])return r[e];r._rollbarShimQueue=[],r._rollbarWrappedError=null,o=o||{};var i=new a;return t(function(){if(i.configure(o),o.captureUncaught){i._rollbarOldOnError=r.onerror,r.onerror=n(i);var t,a,s="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(t=0;t<s.length;++t)a=s[t],r[a]&&r[a].prototype&&l(i,r[a].prototype)}return r[e]=i,i})()},a.prototype.loadFull=function(r,o,e,n,a){var i=function(){var o;if(void 0===r._rollbarPayloadQueue){var t,e,n,i;for(o=new Error("rollbar.js did not load");t=r._rollbarShimQueue.shift();)for(n=t.args,i=0;i<n.length;++i)if(e=n[i],"function"==typeof e){e(o);break}}"function"==typeof a&&a(o)},l=!1,s=o.createElement("script"),u=o.getElementsByTagName("script")[0],p=u.parentNode;s.crossOrigin="",s.src=n.rollbarJsUrl,s.async=!e,s.onload=s.onreadystatechange=t(function(){if(!(l||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)){s.onload=s.onreadystatechange=null;try{p.removeChild(s)}catch(r){}l=!0,i()}}),p.insertBefore(s,u)},a.prototype.wrap=function(r,o){try{var t;if(t="function"==typeof o?o:function(){return o||{}},"function"!=typeof r)return r;if(r._isWrap)return r;if(!r._wrapped){r._wrapped=function(){try{return r.apply(this,arguments)}catch(o){throw o._rollbarContext=t()||{},o._rollbarContext._wrappedSource=r.toString(),window._rollbarWrappedError=o,o}},r._wrapped._isWrap=!0;for(var e in r)r.hasOwnProperty(e)&&(r._wrapped[e]=r[e])}return r._wrapped}catch(n){return r}};for(var u="log,debug,info,warn,warning,error,critical,global,configure,scope,uncaughtError".split(","),p=0;p<u.length;++p)a.prototype[u[p]]=i(u[p]);r.exports={Rollbar:a,_rollbarWindowOnError:e}},function(r,o){"use strict";r.exports=function(r,o){return function(t){if(!t&&!window._rollbarInitialized){var e=window.RollbarNotifier,n=o||{},a=n.globalAlias||"Rollbar",i=window.Rollbar.init(n,r);i._processShimQueue(window._rollbarShimQueue||[]),window[a]=i,window._rollbarInitialized=!0,e.processPayloads()}}}}]);
// End Rollbar Snippet
{$checkIgnoreConfig}
</script>
END_HTML;
    }
275594
public function extract(array $context)
    {
        $params = [];

        foreach ($this->fields as $field) {
            if (isset($context[$field])) {
                $params[$field] = $context[$field];
                unset($context[$field]);
            }
        }

        if (!empty($context)) {
            $params['context'] = $context;
        }

        return $params;
    }
119751
final public function getCanonicalizedLocaleForMoment(array $context)
    {
        $locale = strtolower(str_replace('_', '-', $context['app']->getRequest()->getLocale()));

        // "en" language doesn't require localization.
        if (('en' === $lang = substr($locale, 0, 2)) && !\in_array($locale, ['en-au', 'en-ca', 'en-gb', 'en-ie', 'en-nz'], true)) {
            return null;
        }

        foreach (self::MOMENT_UNSUPPORTED_LOCALES as $language => $locales) {
            if ($language === $lang && !\in_array($locale, $locales, true)) {
                $locale = $language;
            }
        }

        return $locale;
    }
222221
protected function buildJsonAttributes(array $map): array
    {
        $result = [];

        foreach ($map as $jsonKey => $value) {
            if ($value !== null) {
                $result[$jsonKey] = $value;
            }
        }

        return $result;
    }
511719
protected function getExpectedIdentifiers($context = null)
    {
        if ($context === null) {
            throw new Exception\RuntimeException(
                'Expected context to be an array but is null'
            );
        }

        $className = $this->objectRepository->getClassName();

        if ($context instanceof $className) {
            return $this->objectManager
                        ->getClassMetadata($this->objectRepository->getClassName())
                        ->getIdentifierValues($context);
        }

        $result = [];
        foreach ($this->getIdentifiers() as $identifierField) {
            if (! array_key_exists($identifierField, $context)) {
                throw new Exception\RuntimeException(\sprintf('Expected context to contain %s', $identifierField));
            }

            $result[$identifierField] = $context[$identifierField];
        }
        return $result;
    }