Extraction of complex values

@param array $valueConfig Value configuration
@return string                    Value
178515
protected function _getValue(array $valueConfig)
    {
        $returnValue = null;

        if (array_key_exists('_typoScriptNodeValue', $valueConfig)) {
            $valueType = strtolower($valueConfig['_typoScriptNodeValue']);

            switch ($valueType) {

                // Value extraction based on a GET / POST variable
                case 'gp':
                    unset($valueConfig['_typoScriptNodeValue']);

                    // Detect if a database lookup is required
                    if (array_key_exists('lookup', $valueConfig)) {
                        $lookup = trim($valueConfig['lookup']);
                        unset($valueConfig['lookup']);
                    } else {
                        $lookup = null;
                    }

                    // Extraction of the requested GET / POST variable
                    $gpVariables = array();
                    $gpValues = array();
                    foreach ($valueConfig as $key => $value) {
                        if (strval(intval($key)) == strval($key)) {
                            list($value, $default) = array_pad(explode('|', $value, 2), 2, null);
                            $gpVariables[intval($key)] = preg_split("%[\]\[]+%", trim($value, ']'));
                            if ($default != null) {
                                $gpValues[intval($key)] = trim($default);
                            }
                        }
                    }

                    // If there exists a key 1 ...
                    if (array_key_exists(1, $gpVariables)) {

                        foreach ($gpVariables as $index => $steps) {
                            $stack = null;
                            foreach ($steps as $step) {
                                $stack = ($stack == null) ? \TYPO3\CMS\Core\Utility\GeneralUtility::_GP($step) : (array_key_exists($step,
                                    $stack) ? $stack[$step] : null);
                                if (!is_array($stack) && !strlen($stack)) {
                                    continue 2;
                                }
                            }
                            if (is_scalar($stack)) {
                                $gpValues[$index] = $stack;
                            }
                        }

                        // If all of the required values could be found ...
                        if (count($gpValues) == count($gpVariables)) {

                            // If a database lookup has been requested ...
                            if (strlen($lookup)) {
                                foreach ($gpValues as $key => $value) {
                                    $lookupTable = $gpVariables[$key][0] ?: 'pages';
                                    $lookup = str_replace('$'.$key,
                                        $GLOBALS['TYPO3_DB']->quoteStr($value, $lookupTable), $lookup);
                                }

                                $result = $GLOBALS['TYPO3_DB']->sql_query($lookup);
                                if ($result && $GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
                                    $result = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
                                    if (is_array($result) && count($result)) {
                                        $returnValue = array_shift($result);
                                    }
                                }

                                // ... else return the first variabe value
                            } else {
                                $returnValue = $gpValues[1];
                            }
                        }
                    }
                    break;

                // Treat this as a TypoScript content object
                default:
                    $returnValue = $this->_getTypoScriptValue($valueConfig);
            }
        }

        return $returnValue;
    }
732615
public function setFieldFormatting(&$config)
    {
        $fieldFormatting = array();
        // Parse the column information
        foreach ($this->columns() as $source => $info) {
            if (isset($info['link']) && $info['link']) {
                $fieldFormatting[$source] = '<a href=\"$ObjectRecordLink\">$value</a>';
            }
            if (isset($info['text']) && $info['text']) {
                $fieldFormatting[$source] = $info['text'];
            }
        }
        return $fieldFormatting;
    }
458436
protected function extractBasePath(\Composer\Config $config) {
        $reflectionClass = new \ReflectionClass($config);
        $reflectionProperty = $reflectionClass->getProperty('baseDir');
        $reflectionProperty->setAccessible(true);
        return $reflectionProperty->getValue($config);
    }
820615
protected function getAttributesConfig(array $siteConfig)
	{
		$attrNames = $this->getAttributeNamesFromRegexps($siteConfig['extract']);
		foreach ($siteConfig['scrape'] as $scrapeConfig)
		{
			$attrNames += $this->getAttributeNamesFromRegexps($scrapeConfig['extract']);
		}

		$attributes = $siteConfig['attributes'] + array_fill_keys(array_keys($attrNames), []);
		foreach ($attributes as &$attrConfig)
		{
			$attrConfig += ['required' => false];
		}
		unset($attrConfig);

		return $attributes;
	}
685869
public function parseFuelConfig(array $config)
	{
		$params = array();

		$params['driver'] = $config['type'];

		if ($params['driver'] === 'pdo')
		{
			list($type, $dsn) = explode(':', $config['connection']['dsn'], 2);

			$params['driver'] .= '_' . $type;

			$dsn = explode(';', $dsn);

			foreach ($dsn as $d)
			{
				list($k, $v) = explode('=', $d);

				$params[$k] = $v;
			}
		}
		else
		{
			$params['dbname'] = $config['connection']['database'];
			$params['host'] = $config['connection']['hostname'];
			$params['port'] = Arr::get($config, 'connection.port');
		}

		$params['user'] = Arr::get($config, 'connection.username');
		$params['password'] = Arr::get($config, 'connection.password');
		$params['charset'] = Arr::get($config, 'charset');

		return $params;
	}
6153
public static function generateNameValueList( $config = [] ) {

		$modelClass	= static::$modelClass;
		$modelTable = $modelClass::tableName();

		$site	= Yii::$app->core->site;
		$theme	= $site->theme;

		$config[ 'ignoreSite' ] = true;

		$config[ 'conditions' ][] = isset( $theme ) ? "$modelTable.themeId={$theme->id} OR $modelTable.siteId={$site->id} OR ($modelTable.themeId IS NULL AND $modelTable.siteId IS NULL)" : "$modelTable.siteId={$site->id} OR ($modelTable.themeId IS NULL AND $modelTable.siteId IS NULL)";

		return parent::generateNameValueList( $config );
	}
41237
public static function generateNameValueList( $config = [] ) {

		$config = static::applySiteFilters( $config );

		$modelClass	= static::$modelClass;
		$modelTable = $modelClass::tableName();

		// map columns
		$nameColumn		= $config[ 'nameColumn' ] ?? 'name';
		$valueColumn	= $config[ 'valueColumn' ] ?? 'value';

		// column alias
		$nameAlias		= $config[ 'nameAlias' ] ?? 'name';
		$valueAlias		= $config[ 'valueAlias' ] ?? 'value';

		// limit
		$limit			= $config[ 'limit' ] ?? 0;

		// Query
		$query = $config[ 'query' ] ?? new Query();

		// Conditions, Filters and Sorting
		$conditions	= $config[ 'conditions' ] ?? null;
		$filters	= $config[ 'filters' ] ?? null;
		$order		= $config[ 'order' ] ?? null;

		// additional data
		$prepend		= $config[ 'prepend' ] ?? [];
		$append			= $config[ 'append' ] ?? [];

		// Conditions ----------

		$query->select( [ "$nameColumn as $nameAlias", "$valueColumn as $valueAlias" ] )
			  ->from( $modelTable );

		if( isset( $conditions ) ) {

			foreach( $conditions as $ckey => $condition ) {

				if( is_numeric( $ckey ) ) {

					$query->andWhere( $condition );

					unset( $conditions[ $ckey ] );
				}
			}

			$query->andWhere( $conditions );
		}

		$interfaces = class_implements( static::class );

		if( isset( $interfaces[ 'cmsgears\core\common\services\interfaces\base\IApproval' ] ) ) {

			$statusFilter = $modelClass::STATUS_TERMINATED;

			$query->andWhere( "$modelTable.status<$statusFilter" );
		}

		// Filters -------------

		if( isset( $filters ) ) {

			foreach( $filters as $filter ) {

				$query = $query->andFilterWhere( $filter );
			}
		}

		// Sorting -------------

		if( isset( $order ) ) {

			$query->orderBy( $order );
		}

		// Limit ---------------

		if( $limit > 0 ) {

			$query->limit( $limit );
		}

		// Quering -------------

		// Create command
		$command = $query->createCommand();

		// Execute the command
		$arrayList = $command->queryAll();

		// Result --------------

		// Prepend given list
		if( count( $prepend ) > 0 ) {

			$arrayList = ArrayHelper::merge( $prepend, $arrayList );
		}

		// Append given list
		if( count( $append ) > 0 ) {

			$arrayList = ArrayHelper::merge( $arrayList, $append );
		}

		return $arrayList;
	}
143490
private function inputStringGenerator($config)
    {
        $config = $this->prepareObjectValue($config);
        $population = $this->inputCalibrator->getPopulation($config);
        $checkType = $this->inputCalibrator->checkType($config, $this->inputGroups['checkbox']);
        $selected = $this->inputCalibrator->isSelected($config, $checkType);
        $custom = $this->inputCalibrator->getField($config, 'custom');
        $method = $this->getGeneratorMethod($config['inputType']);

        if (in_array($method, $this->standardMethods)) {
            $inputString = $this->htmlGenerator->$method($config, $population, $custom);
        } elseif (in_array($method, $this->selectedMethods)) {
            // add extra class

            $inputString = $this->htmlGenerator->$method($config, $selected, $custom);
        } elseif ($method === 'makeRelationship') {
            $inputString = $this->htmlGenerator->makeRelationship(
                $config,
                $this->inputCalibrator->getField($config, 'label', 'name'),
                $this->inputCalibrator->getField($config, 'value', 'id'),
                $custom
            );
        } else {
            $config = $this->prepareType($config);
            $inputString = $this->htmlGenerator->makeHTMLInputString($config);
        }

        return $inputString;
    }
74096
protected function unwrap(array &$valueMap)
    {
        $id = spl_object_hash($this);

        if (array_key_exists($id, $valueMap)) {
            return $valueMap[$id];
        }

        $valueMap[$id] = array();
        foreach ($this->value as $key => $subValue) {
            $valueMap[$id][$key] = $subValue->unwrap($valueMap);
        }

        return $valueMap[$id];
    }
763097
public static function parseCurlConfig($config)
    {
        $curlOptions = array();
        foreach ($config as $key => $value) {
            if (is_string($key) && defined($key)) {
                // Convert constants represented as string to constant int values
                $key = constant($key);
            }
            if (is_string($value) && defined($value)) {
                $value = constant($value);
            }
            $curlOptions[$key] = $value;
        }

        return $curlOptions;
    }
357244
public function parseString($config)
    {
        try {
            $data = YamlParser::parse($config, YamlParser::PARSE_CONSTANT);
        } catch (Exception $exception) {
            throw new ParseException(
                [
                    'message'   => 'Error parsing YAML string',
                    'exception' => $exception,
                ]
            );
        }

        return (array)$this->parse($data);
    }
891453
public function transform($config)
    {
        array_walk($config, function(&$value, $key) {
            if (in_array($key, $this->getKeys(), true)) {
                $value = $this->transformValue($value);
            } else {
                if ($this->shouldRecurse($value, $key)) {
                    $value = $this->transform($value);
                }
            }
        });

        return $config;
    }
1372941
private function _belongsToMany(array $config): ResultSet
    {
        //配置信息
        $targetClass = $config['table'];  //对方表
        $middleClass = $config['middle'];  //中间表
        $selfPrimaryKey = $config['selfPrimaryKey'];//本表主键
        $targetPrimaryKey = $config['targetPrimaryKey'];//对方 表主键
        $selfForeignKey = $config['selfForeignKey'];//中间表中与本表关联的键
        $targetForeignKey = $config['targetForeignKey'];//中间表中与对方 表关联的键

        //取本表主键的值
        $primaryValue = $this->$selfPrimaryKey;
        $config['selfPrimaryValue'] = $primaryValue;

        /**
         * 中间对象表
         * @var $middleInstance Table
         */
        $middleInstance = $middleClass::instance();

        //取中间表里,对方表外键的值
        $foreignValues = $middleInstance->col($targetForeignKey, [$selfForeignKey => $primaryValue]);

        /**
         * 对方表对象
         * @var $targetInstance Table
         */
        $targetInstance = $targetClass::instance();

        //在对方对象表中查询关联记录
        return ResultSet::instance($targetInstance->select('*', [$targetPrimaryKey => $foreignValues]))
            ->_setType('belongsToMany', $config);
    }
516644
public function transform(string $config = ''): array
    {
        $config = \preg_replace('/^(<\?xml\ version="[^"]+"\ encoding="[^"]+"\?>)?(\n)?/i', '', $config);
        $parsed = [];
        if (!empty($config)) {
            $node = new \SimpleXMLElement($config);
            if ($node->count() > 0) {
                $parsed = $this->processNode($node->children());
            }
        }
        return $parsed;
    }
1060790
protected function getDomain(array $config): string
    {
        $result = '';
        $parts = explode(',', $config['baseDn']);
        foreach ($parts as $part) {
            list($key, $value) = explode('=', $part);
            if ('dc' !== strtolower($key)) {
                continue;
            }

            $result .= '.' . $value;
        }

        $result = trim(trim($result, '.'));

        // fallback value
        if (empty($result)) {
            $result = $config['domain'] . '.com';
        }

        return $result;
    }
897469
public static function getConfig(array $appConfig = []) : array
  {
    $configs = DEPConfig::$appdir . 'config' . DIRECTORY_SEPARATOR . '*.php';

    foreach (\glob($configs) as $config) {
      $service = require $config;

      if (is_array($service)) {
        $path = basename($config);
        $name = \substr($path, 0, strlen($path) - 4);
        $appConfig = array_merge($appConfig, [$name => $service]);
      }
    }

    return $appConfig;
  }
915688
private function extractGuzzleConfig($config)
    {
        foreach (ConfigUtils::$GUZZLE_CONFIG_KEYS as $guzzleOption) {
            if (array_key_exists($guzzleOption, $config)) {
                $this->guzzleConfig[$guzzleOption] = $config[$guzzleOption];
                unset($config[$guzzleOption]);
            }
        }

        return $config;
    }