Extract metadata value of a given $source

Extract metadata values by calling each extractors

@param $source
@return array
177503
public function extract($source)
    {
        $metadata = [[]];
        foreach ($this->getExtractors() as $extractor) {
            $metadata[] = $extractor->extract($source);
        }
        $metadata = array_merge_recursive(...$metadata);
        \common_Logger::d(__('%s metadata values found in source by extractor(s).', count($metadata)));

        return $metadata;
    }
6245
public function relGlob($source)
    {
        $list = (array)$this->glob($source);
        foreach ($list as $key => $item) {
            $list[$key] = FS::getRelative($item, $this->root, '/');
        }

        return $list;
    }
593960
protected function getDropdownValuesFromSource($source)
    {
        if (is_a($source, Enum::class, true)) {
            /** @var Enum $source */
            return array_map(
                function ($value) { return (string) $value; },
                $source::values()
            );
        }

        if (is_a($source, DropdownStrategyInterface::class, true)) {
            /** @var DropdownStrategyInterface $source */
            $source = app($source);
            return $source->values();
        }

        return false;
    }
358524
public function getAttributes($source): array
    {
        return [
            self::CLIENT_MIME_TYPE => $source->getClientMimeType(),
            self::CLIENT_NAME => $source->getClientOriginalName(),
            self::TMP_PATH => $source->getPathname(),
        ];
    }
266695
protected function getListMap($source)
    {
        // Extract source as an array
        if ($source instanceof SS_List) {
            $source = $source->map();
        }
        if ($source instanceof Map) {
            $source = $source->toArray();
        }
        if (!is_array($source) && !($source instanceof ArrayAccess)) {
            user_error('$source passed in as invalid type', E_USER_ERROR);
        }

        return $source;
    }
851260
private function getFileContents($source)
    {
        $this->assertSourceExists($source);
        $this->assertSourceIsNotFolder($source);
        $content = file_get_contents($source, true);

        $this->assertContentIsProperLoaded($source, $content);
        $this->assertContentIsNotEmpty($source, $content);

        return $content;
    }
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;
    }
701851
public function extract( $object )
    {
        $values = array();

        foreach ( $object->settings as $key => $value )
        {
            switch ( true )
            {
                case $value instanceof StructureAbstract:
                    $values[$key] = $this->extract( $value );
                    break;

                case method_exists( $object, $method = 'extract' . ucfirst( $key ) ):
                    $values[$key] = $object->$method( $value );
                    break;

                default:
                    $values[$key] = $value;
            }
        }

        return $values;
    }
741437
public function parse($source)
		{
		// Reset
		$this->source = "";
		$this->tokens = array();
		// Create a global and plugin lookup table for trigger chars; set array of plugins as local variable and create 
		// several helper variables for plugin handling
		$globalTriggerChars		= "";
		$plugins				= $this->plugins;
		$pluginCount			= count($plugins);
		$pluginIndex			= array();
		$pluginTriggerStates	= array();
		$pluginTriggerChars		= array();
		for ($i = 0, $l = count($plugins); $i < $l; $i++)
			{
			$tPluginClassName				= get_class($plugins[$i]);
			$pluginTriggerChars[$i]			= implode("", $plugins[$i]->getTriggerChars());
			$tPluginTriggerStates			= $plugins[$i]->getTriggerStates();
			$pluginTriggerStates[$i]		= $tPluginTriggerStates === false ? false : "|" . implode("|", $tPluginTriggerStates) . "|";
			$pluginIndex[$tPluginClassName]	= $i;
			for ($ii = 0, $ll = strlen($pluginTriggerChars[$i]); $ii < $ll; $ii++)
				{
				$c = substr($pluginTriggerChars[$i], $ii, 1);
				if (strpos($globalTriggerChars, $c) === false)
					{
					$globalTriggerChars .= $c;
					}
				}
			}
		// Normalise line endings
		$source			= str_replace("\r\n", "\n", $source);	// Windows to Unix line endings
		$source			= str_replace("\r", "\n", $source);		// Mac to Unix line endings
		$this->source	= $source;
		// Variables
		$buffer			= &$this->buffer;
		$exclusive		= &$this->stateExclusive;
		$state			= &$this->state;
		$c = $p 		= null;
		// --
		for ($i = 0, $l = strlen($source); $i < $l; $i++)
			{
			// Set the current Char
			$c = $source[$i]; // Is faster than: $c = substr($source, $i, 1);
			// Normalize and filter double whitespace characters
			if ($exclusive === false)
				{
				if ($c === "\n" || $c === "\t")
					{
					$c = " ";
					}
				if ($c === " " && $p === " ")
					{
					continue;
					}
				}
			$buffer .= $c;
			// Extended processing only if the current char is a global trigger char
			if (strpos($globalTriggerChars, $c) !== false)
				{
				// Exclusive state is set; process with the exclusive plugin 
				if ($exclusive)
					{
					$tPluginIndex = $pluginIndex[$exclusive];
					if (strpos($pluginTriggerChars[$tPluginIndex], $c) !== false && ($pluginTriggerStates[$tPluginIndex] === false || strpos($pluginTriggerStates[$tPluginIndex], $state) !== false))
						{
						$r = $plugins[$tPluginIndex]->parse($i, $c, $p, $state);
						// Return value is TRUE => continue with next char
						if ($r === true)
							{
							continue;
							}
						// Return value is numeric => set new index and continue with next char
						elseif ($r !== false && $r != $i)
							{
							$i = $r;
							continue;
							}
						}
					}
				// Else iterate through the plugins
				else
					{
					$triggerState = "|" . $state . "|";
					for ($ii = 0, $ll = $pluginCount; $ii < $ll; $ii++)
						{
						// Only process if the current char is one of the plugin trigger chars
						if (strpos($pluginTriggerChars[$ii], $c) !== false && ($pluginTriggerStates[$ii] === false || strpos($pluginTriggerStates[$ii], $triggerState) !== false))
							{
							// Process with the plugin
							$r = $plugins[$ii]->parse($i, $c, $p, $state);
							// Return value is TRUE => break the plugin loop and and continue with next char
							if ($r === true)
								{
								break;
								}
							// Return value is numeric => set new index, break the plugin loop and and continue with next char
							elseif ($r !== false && $r != $i)
								{
								$i = $r;
								break;
								}
							}
						}
					}
				}
			$p = $c; // Set the parent char
			}
		return $this->tokens;
		}
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;
    }
344033
public final static function decode(string $source): array {
		if (is_null($source = json_decode($source, true)) && json_last_error() !== JSON_ERROR_NONE){
			throw new \Exception('Invalid json format!');
		}

		return $source;
	}
530962
public static function get_last_name($source) {
		$name = explode(' ', self::parse_source_path('info.name', $source));
		array_shift($name);
		return join(' ', $name);
	}
681127
public function extract($source, $target)
    {
        if (!$sourceRes = gzopen($source, 'r')) {
            throw new \RuntimeException(sprintf('Unable to read archive file "%s".', $source));
        }
        if (!$targetRes = fopen($target, 'w')) {
            throw new \RuntimeException(sprintf('Unable to write target file "%s".', $target));
        }
        while (!gzeof($sourceRes)) {
            fwrite($targetRes, gzread($sourceRes, $this->bufferSize));
        }
        if (!gzclose($sourceRes)) {
            throw new \RuntimeException(sprintf('Unable to close archive file "%s".', $source));
        }
        if (!fclose($targetRes)) {
            throw new \RuntimeException(sprintf('Unable to close target file "%s".', $target));
        }
    }
786270
private function getDeletedFields(Source $source)
    {
        $fields = array();
        $fields += array(
            'undelete' => array(
                'type' => 'button',
                'value' => $this->t('undelete'),
                'ajax' => array(
                    'service' => 'entry_deletestatus_set',
                    'parent_type' => $this->source->getType(),
                    'parent_source' => $this->source->getId(),
                    'type' => $source->getType(),
                    'source' => $source->getId(),
                    'value' => API::Entry_Delete,
                ),
            ),
            'send' => array(
                'type' => 'button',
                'value' => $this->t('send_again'),
                'ajax' => array(
                    'service' => 'invoice_add',
                    'parent_type' => $this->source->getType(),
                    'parent_source' => $this->source->getId(),
                    'type' => $source->getType(),
                    'source' => $source->getId(),
                    'value' => 1,
                ),
            ),
        );
        return $fields;
    }
803009
protected function parseSource(
        $source,
        DocumentFactoryInterface $documentFactory,
        ElementProcessorInterface $elementProcessor,
        ContextInterface $context
    ) {
        try {
            $parser = new Parser($documentFactory, $elementProcessor, $context);
            $things = $parser->parse($source);
            $gateway = new ThingGateway($this->iri);
            return (object)['items' => $gateway->export($things)];
        } catch (\OutOfBoundsException $e) {
            throw new OutOfBoundsException($e->getMessage(), $e->getCode());
        } catch (\RuntimeException $e) {
            throw new RuntimeException($e->getMessage(), $e->getCode());
        }
    }
661450
protected function unserialize($source)
    {
        $source = base64_decode($source);
        $result = @unserialize($source);
        if ($result === false && $source !== serialize(false)) {
            throw new \UnexpectedValueException();
        }
        return $result;
    }
378891
public function getExtractorsForTable(string $tableName): array
    {
        if (!isset($this->tableExtractors[$tableName])) {
            return [];
        }
        $extractors = [];
        foreach ($this->tableExtractors[$tableName] as $tableExtractor) {
            if (!$this->extractorContainer->has($tableExtractor)) {
                throw new \RuntimeException('Could not get extractor ' . $tableExtractor);
            }
            $extractors[] = $extractor = $this->extractorContainer->get($tableExtractor);
            $this->logger->debug('Adding extractor ' . $extractor->name());
        }

        return $extractors;
    }