Neos\Eel\Utility::getDefaultContextVariables PHP Method

getDefaultContextVariables() public static method

For example Eel helpers are made available by this.
public static getDefaultContextVariables ( array $configuration ) : array
$configuration array An one dimensional associative array of context variable paths mapping to object names
return array Array with default context variable objects.
    public static function getDefaultContextVariables(array $configuration)
    {
        $defaultContextVariables = [];
        foreach ($configuration as $variableName => $objectType) {
            $currentPathBase =& $defaultContextVariables;
            $variablePathNames = explode('.', $variableName);
            foreach ($variablePathNames as $pathName) {
                if (!isset($currentPathBase[$pathName])) {
                    $currentPathBase[$pathName] = [];
                }
                $currentPathBase =& $currentPathBase[$pathName];
            }
            $currentPathBase = new $objectType();
        }
        return $defaultContextVariables;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Get variables from configuration that should be set in the context by default.
  * For example Eel helpers are made available by this.
  *
  * @return array Array with default context variable objects.
  */
 protected function getDefaultContextVariables()
 {
     if ($this->defaultContextVariables === null) {
         $this->defaultContextVariables = array();
         if (isset($this->settings['defaultContext']) && is_array($this->settings['defaultContext'])) {
             $this->defaultContextVariables = EelUtility::getDefaultContextVariables($this->settings['defaultContext']);
         }
         $this->defaultContextVariables['request'] = $this->controllerContext->getRequest();
     }
     return $this->defaultContextVariables;
 }