Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ClassFilesSniff.php

function ClassFilesSniff::drupalParseInfoFormat

Parses a Drupal info file. Copied from Drupal core drupal_parse_info_format().

Parameters

string $data The contents of the info file to parse:

Return value

array<mixed> The info array.

4 calls to ClassFilesSniff::drupalParseInfoFormat()
AutoAddedKeysSniff::process in vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php
Processes this test, when one of its tokens is encountered.
ClassFilesSniff::process in vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php
Processes this test, when one of its tokens is encountered.
Project::getCoreVersion in vendor/drupal/coder/coder_sniffer/DrupalPractice/Project.php
Determines the Drupal core version a file might be associated with.
RequiredSniff::process in vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php
Processes this test, when one of its tokens is encountered.

File

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php, line 123

Class

ClassFilesSniff
Checks files[] entries in info files. Only files containing classes/interfaces should be listed.

Namespace

Drupal\Sniffs\InfoFiles

Code

public static function drupalParseInfoFormat($data) {
    $info = [];
    $constants = get_defined_constants();
    if (preg_match_all('
          @^\\s*                           # Start at the beginning of a line, ignoring leading whitespace
          ((?:
            [^=;\\[\\]]|                    # Key names cannot contain equal signs, semi-colons or square brackets,
            \\[[^\\[\\]]*\\]                  # unless they are balanced and not nested
          )+?)
          \\s*=\\s*                         # Key/value pairs are separated by equal signs (ignoring white-space)
          (?:
            ("(?:[^"]|(?<=\\\\)")*")|     # Double-quoted string, which may contain slash-escaped quotes/slashes
            (\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes
            ([^\\r\\n]*?)                   # Non-quoted string
          )\\s*$                           # Stop at the next end of a line, ignoring trailing whitespace
          @msx', $data, $matches, PREG_SET_ORDER) !== false) {
        foreach ($matches as $match) {
            // Fetch the key and value string.
            $i = 0;
            foreach ([
                'key',
                'value1',
                'value2',
                'value3',
            ] as $var) {
                if (isset($match[++$i]) === true) {
                    ${$var} = $match[$i];
                }
                else {
                    ${$var} = '';
                }
            }
            $value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;
            // Parse array syntax.
            $keys = preg_split('/\\]?\\[/', rtrim($key, ']'));
            $last = array_pop($keys);
            $parent =& $info;
            // Create nested arrays.
            foreach ($keys as $key) {
                if ($key === '') {
                    $key = count($parent);
                }
                if (isset($parent[$key]) === false || is_array($parent[$key]) === false) {
                    $parent[$key] = [];
                }
                $parent =& $parent[$key];
            }
            // Handle PHP constants.
            if (isset($constants[$value]) === true) {
                $value = $constants[$value];
            }
            // Insert actual value.
            if ($last === '') {
                $last = count($parent);
            }
            $parent[$last] = $value;
        }
        
        //end foreach
    }
    
    //end if
    return $info;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal