@param $source

@return array
354030
protected function getKeyValue($source)
    {
        $values = [];
        foreach ($source as $i => $j) {
            $key = is_int($i) ? $j : $i;
            $getter = $j;

            $type = null;
            if (strpos($getter, '+') === 0) {
                $type = 'plus'; // add if existent
                $getter = substr($getter, 1);
            } else if (strpos($getter, '-') === 0) {
                continue;
            }

            if (strpos($key, '+') === 0) {
                $type = 'plus'; // add if existent
                $key = substr($key, 1);
            } else if (strpos($key, '-') === 0) {
                continue;
            }

            if ($this->hasKey($getter)) {
                /**
                 * Key exist in original or extended tables.
                 */
                if ($type && !$this->keyExists($getter)) {
                    continue;
                }
                $values[$key] = $this->{$getter};
            } elseif ($this->hasRelation($getter)) {
                /**
                 * Relation exists in entity definition.
                 */
                if ($type && !$this->relationExists($getter)) {
                    continue;
                }
                $values[$key] = $this->getRelationIfSet($getter);
            } elseif (!$type && method_exists($this, 'get' . Convention::toPascal($getter) . 'Attribute')) {
                /**
                 * Getter exists in record definition.
                 */
                $values[$key] = $this->{'get' . Convention::toPascal($getter) . 'Attribute'}();
            }
        }

        return $values;
    }
666078
protected function _findWebRoot($source)
    {
        $webRootDir = Configure::read('App.webroot');
        $webRoot    = APP_ROOT . DS . $webRootDir . DS;

        list ($plugin, $source) = $this->_View->pluginSplit($source);
        if ($plugin !== null && Plugin::loaded($plugin)) {
            $webRoot = Plugin::path($plugin) . $webRootDir . DS;
        }

        return [FS::clean($webRoot, '/'), $source];
    }
1346999
public function getMetadata($source)
    {
        $parts = explode('.', $source);

        if (count($parts) === 1) {
            $fields = $this->query("exec sp_pkeys '$parts[0]'");
        } else {
            $fields = $this->query("exec sp_pkeys @table_name ='$parts[1]', @table_owner ='$parts[0]'");
        }

        $primaryKeys = count($fields) === 1 ? [$fields[0]['COLUMN_NAME']] : [];

        if (count($parts) === 1) {
            $fields = $this->query("exec sp_columns '$parts[0]'");
        } else {
            $fields = $this->query("exec sp_columns @table_name ='$parts[1]', @table_owner ='$parts[0]'");
        }

        $attributes = [];
        $autoIncrementAttribute = null;

        foreach ($fields as $field) {
            $fieldName = $field['COLUMN_NAME'];

            $attributes[] = $fieldName;

            if (!in_array($fieldName, $primaryKeys, true)) {
                $nonPrimaryKeys[] = $fieldName;
            }

            if ($field['TYPE_NAME'] === 'int identity') {
                $autoIncrementAttribute = $fieldName;
            }
        }

        $r = [
            Db::METADATA_ATTRIBUTES => $attributes,
            Db::METADATA_PRIMARY_KEY => $primaryKeys,
            Db::METADATA_AUTO_INCREMENT_KEY => $autoIncrementAttribute
        ];

        return $r;
    }
548134
protected function findDataSource($source)
    {
        foreach ($this->dataSources as $dataSource) {
            if ($dataSource->supports($source)) {
                return $dataSource;
            }
        }

        throw new \RuntimeException('Unknown source type');
    }
1056127
public static final function prepend(array $Source, array $Prepend): array {
		return array_merge($Prepend, self::only($Source, array_filter(array_keys($Source), function($value) use ($Prepend){
			return is_int($value) || !array_key_exists($value, $Prepend); })));
	}
1049556
public function parse(string $source): array
    {
        //Cleaning list of already parsed tokens
        $this->tokens = [];

        if ($this->isolatePHP) {
            $source = $this->isolator->isolatePHP($source);
        }

        $quotas = '';
        $buffer = '';

        $length = strlen($source);
        $position = self::POSITION_PLAIN_TEXT;
        for ($pointer = 0; $pointer < $length; $pointer++) {
            $char = $source[$pointer];
            switch ($char) {
                case '<':
                    if ($position == self::POSITION_IN_QUOTAS) {
                        $buffer .= $char;
                        break;
                    }

                    if ($position == self::POSITION_IN_TAG) {
                        $buffer = '<' . $buffer;
                    }

                    //Handling previous token
                    $this->handleToken(self::PLAIN_TEXT, $buffer);

                    //We are in tag now
                    $position = self::POSITION_IN_TAG;
                    $buffer = '';
                    break;
                case '>':
                    if ($position != self::POSITION_IN_TAG) {
                        $buffer .= $char;
                        break;
                    }

                    //Token ended
                    $this->handleToken(null, $buffer);

                    //We are in a plain text now
                    $position = self::POSITION_PLAIN_TEXT;
                    $buffer = '';
                    break;
                case '"':
                    //no break
                case "'":
                    if ($position == self::POSITION_IN_TAG) {
                        //Jumping into argument
                        $position = self::POSITION_IN_QUOTAS;
                        $quotas = $char;
                    } elseif ($position == self::POSITION_IN_QUOTAS && $char == $quotas) {
                        //Jumping from argument
                        $position = self::POSITION_IN_TAG;
                        $quotas = '';
                    }
                default:
                    //Checking for invalid characters in tag name or arguments
                    if ($position == self::POSITION_IN_TAG) {
                        if (!preg_match('/[a-z0-9 \._\-="\':\/\r\n\t]/i', $char)) {
                            $buffer = '<' . $buffer;
                            $position = self::POSITION_PLAIN_TEXT;
                        }
                    }
                    $buffer .= $char;
            }
        }

        $this->handleToken(self::PLAIN_TEXT, $buffer);

        return $this->tokens;
    }
1220837
public function getPaths($source)
    {
        $source = $this->cleanSource($source);
        list(, $paths) = $this->parse($source);

        return $paths;
    }
236081
protected function findByFilterComponentsSourceSetup( $source )
    {

        // Set source defaults
        if( !( $source & ( self::PERSISTED | self::UNPERSISTED ) ) ) {
            $source += self::PERSISTED + self::UNPERSISTED;
        }

        if( !( $source & ( self::CHANGED | self::UNCHANGED ) ) ) {
            $source += self::CHANGED + self::UNCHANGED;
        }

        if( !( $source & ( self::WITH_CHILDREN | self::NO_CHILDREN ) ) ) {
            $source += self::WITH_CHILDREN;
        }

        if( !( $source & ( Base::DATA | Base::INITIAL ) ) ) {
            $source += Base::DATA;
        }

        return $source;

    }
599582
private function setValuesFromDatafields(array $source): array
    {
        $values = [];
        foreach ($this->datafields as $fieldname => $field) {
            $values[$fieldname] = $this->castValueWithCommonType(
                array_key_exists($fieldname, $source) ? $source[$fieldname] : null,
                $field['commontype']
            );
        }
        return $values;
    }
687068
private function queryToArray(SS_Query $source) {
        $result=array();
        
        foreach($source as $row) {
            $result[]=$row;
        }
        
        return $result;
    }
780874
private function extract($source) {
		try {
			$task = new Task\Extract($source);
			$dest = $task->run($this->verbosity());
		} catch (\Exception $e) {
			if (false === strpos($e->getMessage(), "checksum mismatch")) {
				throw $e;
			}
			$dest = (new Task\PaxFixup($source))->run($this->verbosity());
		}
		
		$this->cleanup[] = new Task\Cleanup($dest);
		return $dest;
	}
751714
public function exportCookies( $source )
  {
    $cookies = array();

    if ( preg_match_all( '#Set-Cookie:\s*([^=]+)=([^;]+)#i', $source, $matches ) )
    {
      for ( $i = 0, $cnt = count( $matches[ 1 ] ); $i < $cnt; ++$i )
      {
        $cookies[ trim( $matches[ 1 ][ $i ] ) ] = trim( $matches[ 2 ][ $i ] );
      }
    }

    return $cookies;
  }
1156788
public static function getBlueprints($source)
    {
        $blueprint_file = $source . 'blueprints.yaml';
        if (!file_exists($blueprint_file)) {
            return false;
        }

        $file = YamlFile::instance($blueprint_file);
        $blueprint = (array)$file->content();
        $file->free();

        return $blueprint;
    }
530962
public static function get_last_name($source) {
		$name = explode(' ', self::parse_source_path('info.name', $source));
		array_shift($name);
		return join(' ', $name);
	}
988180
public static function fromSource(string $source): array
    {
        $constructs = [];

        try {
            $sequence = \token_get_all(
                $source,
                \TOKEN_PARSE
            );
        } catch (\ParseError $exception) {
            throw Exception\ParseError::fromParseError($exception);
        }

        $count = \count($sequence);
        $namespacePrefix = '';

        for ($index = 0; $index < $count; ++$index) {
            $token = $sequence[$index];

            // collect namespace name
            if (\is_array($token) && \T_NAMESPACE === $token[0]) {
                $namespaceSegments = [];

                // collect namespace segments
                for ($index = self::significantAfter($index, $sequence, $count); $index < $count; ++$index) {
                    $token = $sequence[$index];

                    if (\is_array($token) && \T_STRING !== $token[0]) {
                        continue;
                    }

                    $content = self::content($token);

                    if (\in_array($content, ['{', ';'], true)) {
                        break;
                    }

                    $namespaceSegments[] = $content;
                }

                $namespace = \implode('\\', $namespaceSegments);
                $namespacePrefix = $namespace . '\\';
            }

            // skip non-classy tokens
            if (!\is_array($token) || !\in_array($token[0], [\T_CLASS, \T_INTERFACE, \T_TRAIT], true)) {
                continue;
            }

            // skip anonymous classes
            if (\T_CLASS === $token[0]) {
                $current = self::significantBefore($index, $sequence);
                $token = $sequence[$current];

                // if significant token before T_CLASS is T_NEW, it's an instantiation of an anonymous class
                if (\is_array($token) && \T_NEW === $token[0]) {
                    continue;
                }
            }

            $index = self::significantAfter($index, $sequence, $count);
            $token = $sequence[$index];

            $constructs[] = Construct::fromName($namespacePrefix . self::content($token));
        }

        \usort($constructs, static function (Construct $a, Construct $b) {
            return \strcmp(
                $a->name(),
                $b->name()
            );
        });

        return $constructs;
    }
534128
public function getSourceChildPropertiesToBeConverted($source)
    {
        $sourceChildPropertiesToBeConverted = [
            'resource' => $source->getResource()
        ];

        if ($source instanceof AssetVariantInterface) {
            $sourceChildPropertiesToBeConverted['originalAsset'] = $source->getOriginalAsset();
        }
        if ($source instanceof ImageVariant) {
            $sourceChildPropertiesToBeConverted['adjustments'] = $source->getAdjustments();
        }

        return $sourceChildPropertiesToBeConverted;
    }
1021477
protected function getRequestParams(&$source, $key = null, $default = null)
    {
        // If $key is NULL, it means that the whole $source is requested
        if (!isset($key) || $key == null) {
            $key = array_keys($source);
        }

        if (is_array($key)) {
            $output = [];
            foreach ($key as $k) {
                $output[$k] = $this->getRequestParams($source, $k);
            }

            return $output;
        }

        if (isset($source[$key])) {
            $value = $source[$key];
        } else {
            return $default;
        }

        return $value;
    }