src/SiteConfig/ConfigBuilder.php
public function parseLines(array $lines)
    {
        $config = new SiteConfig();

        foreach ($lines as $line) {
            $line = trim($line);

            // skip comments, empty lines
            if ('' === $line || '#' === $line[0]) {
                continue;
            }

            // get command
            $command = explode(':', $line, 2);
            // if there's no colon ':', skip this line
            if (2 !== \count($command)) {
                continue;
            }

            $val = trim($command[1]);
            $command = trim($command[0]);
            if ('' === $command || '' === $val) {
                continue;
            }

            // check for commands where we accept multiple statements
            if (\in_array($command, ['title', 'body', 'strip', 'strip_id_or_class', 'strip_image_src', 'single_page_link', 'next_page_link', 'test_url', 'find_string', 'replace_string', 'login_extra_fields', 'native_ad_clue', 'date', 'author', 'strip_attr'], true)) {
                array_push($config->$command, $val);
            // check for single statement commands that evaluate to true or false
            } elseif (\in_array($command, ['tidy', 'prune', 'autodetect_on_failure', 'requires_login', 'skip_json_ld'], true)) {
                $config->$command = ('yes' === $val || 'true' === $val);
            // check for single statement commands stored as strings
            } elseif (\in_array($command, ['parser', 'login_username_field', 'login_password_field', 'not_logged_in_xpath', 'login_uri', 'src_lazy_load_attr'], true)) {
                $config->$command = $val;
            // check for replace_string(find): replace
            } elseif ((')' === substr($command, -1)) && preg_match('!^([a-z0-9_]+)\((.*?)\)$!i', $command, $match) && 'replace_string' === $match[1]) {
                array_push($config->find_string, $match[2]);
                array_push($config->replace_string, $val);
            } elseif ((')' === substr($command, -1)) && preg_match('!^([a-z0-9_]+)\(([a-z0-9_-]+)\)$!i', $command, $match) && 'http_header' === $match[1] && \in_array(strtolower($match[2]), ['user-agent', 'referer', 'cookie', 'accept'], true)) {
                $config->http_header[strtolower(trim($match[2]))] = $val;
            // special treatment for if_page_contains
            } elseif (\in_array($command, ['if_page_contains'], true)) {
                $this->handleIfPageContainsCondition($config, $val);
            }
        }

        return $config;
    }
public function parseLines(array $lines)
    {
        $config = new SiteConfig();

        foreach ($lines as $line) {
            $line = trim($line);

            // skip comments, empty lines
            if ('' === $line || '#' === $line[0]) {
                continue;
            }

            // get command
            $command = explode(':', $line, 2);
            // if there's no colon ':', skip this line
            if (2 !== \count($command)) {
                continue;
            }

            $val = trim($command[1]);
            $command = trim($command[0]);
            if ('' === $command || '' === $val) {
                continue;
            }

            // check for commands where we accept multiple statements
            if (\in_array($command, ['title', 'body', 'strip', 'strip_id_or_class', 'strip_image_src', 'single_page_link', 'next_page_link', 'test_url', 'find_string', 'replace_string', 'login_extra_fields', 'native_ad_clue', 'date', 'author', 'strip_attr'], true)) {
                array_push($config->$command, $val);
            // check for single statement commands that evaluate to true or false
            } elseif (\in_array($command, ['tidy', 'prune', 'autodetect_on_failure', 'requires_login', 'skip_json_ld'], true)) {
                $config->$command = ('yes' === $val || 'true' === $val);
            // check for single statement commands stored as strings
            } elseif (\in_array($command, ['parser', 'login_username_field', 'login_password_field', 'not_logged_in_xpath', 'login_uri', 'src_lazy_load_attr'], true)) {
                $config->$command = $val;
            // check for replace_string(find): replace
            } elseif ((')' === substr($command, -1)) && preg_match('!^([a-z0-9_]+)\((.*?)\)$!i', $command, $match) && 'replace_string' === $match[1]) {
                array_push($config->find_string, $match[2]);
                array_push($config->replace_string, $val);
            } elseif ((')' === substr($command, -1)) && preg_match('!^([a-z0-9_]+)\(([a-z0-9_-]+)\)$!i', $command, $match) && 'http_header' === $match[1] && \in_array(strtolower($match[2]), ['user-agent', 'referer', 'cookie', 'accept'], true)) {
                $config->http_header[strtolower(trim($match[2]))] = $val;
            // special treatment for if_page_contains
            } elseif (\in_array($command, ['if_page_contains'], true)) {
                $this->handleIfPageContainsCondition($config, $val);
            }
        }

        return $config;
    }
public function parseLines ( array $ lines ) { $ config = new SiteConfig ( ) ; foreach ( $ lines as $ line ) { $ line = trim ( $ line ) ; // skip comments, empty lines if ( '' === $ line || '#' === $ line [ 0 ] ) { continue ; } // get command $ command = explode ( ':' , $ line , 2 ) ; // if there's no colon ':', skip this line if ( 2 !== \ count ( $ command ) ) { continue ; } $ val = trim ( $ command [ 1 ] ) ; $ command = trim ( $ command [ 0 ] ) ; if ( '' === $ command || '' === $ val ) { continue ; } // check for commands where we accept multiple statements if ( \ in_array ( $ command , [ 'title' , 'body' , 'strip' , 'strip_id_or_class' , 'strip_image_src' , 'single_page_link' , 'next_page_link' , 'test_url' , 'find_string' , 'replace_string' , 'login_extra_fields' , 'native_ad_clue' , 'date' , 'author' , 'strip_attr' ] , true ) ) { array_push ( $ config -> $ command , $ val ) ; // check for single statement commands that evaluate to true or false } elseif ( \ in_array ( $ command , [ 'tidy' , 'prune' , 'autodetect_on_failure' , 'requires_login' , 'skip_json_ld' ] , true ) ) { $ config -> $ command = ( 'yes' === $ val || 'true' === $ val ) ; // check for single statement commands stored as strings } elseif ( \ in_array ( $ command , [ 'parser' , 'login_username_field' , 'login_password_field' , 'not_logged_in_xpath' , 'login_uri' , 'src_lazy_load_attr' ] , true ) ) { $ config -> $ command = $ val ; // check for replace_string(find): replace } elseif ( ( ')' === substr ( $ command , - 1 ) ) && preg_match ( '!^([a-z0-9_]+)\((.*?)\)$!i' , $ command , $ match ) && 'replace_string' === $ match [ 1 ] ) { array_push ( $ config -> find_string , $ match [ 2 ] ) ; array_push ( $ config -> replace_string , $ val ) ; } elseif ( ( ')' === substr ( $ command , - 1 ) ) && preg_match ( '!^([a-z0-9_]+)\(([a-z0-9_-]+)\)$!i' , $ command , $ match ) && 'http_header' === $ match [ 1 ] && \ in_array ( strtolower ( $ match [ 2 ] ) , [ 'user-agent' , 'referer' , 'cookie' , 'accept' ] , true ) ) { $ config -> http_header [ strtolower ( trim ( $ match [ 2 ] ) ) ] = $ val ; // special treatment for if_page_contains } elseif ( \ in_array ( $ command , [ 'if_page_contains' ] , true ) ) { $ this -> handleIfPageContainsCondition ( $ config , $ val ) ; } } return $ config ; }
Parse line from the config file to build the config.

@param array $lines

@return SiteConfig
Parse line from the config file to build the config .