src/acdhOeaw/fedora/metadataQuery/SimpleQuery.php
public function getQuery(): string {
        $query  = $this->query;
        $values = $this->values;

        $matches = null;
        preg_match_all('/[?][#@][a-zA-Z]?[a-zA-Z0-9_]*/', $query, $matches);
        $matches = count($matches) > 0 ? $matches[0] : array();

        foreach ($matches as $i) {
            $varName = substr($i, 2);
            if ($varName != '') {
                if (!isset($this->values[$varName])) {
                    throw new RuntimeException('no value for variable ' . $varName);
                }
                $value = $values[$varName];
                unset($values[$varName]);
            } else {
                if (count($values) == 0) {
                    throw new RuntimeException('number of values lower then the number of variables in the query');
                }
                $value = array_shift($values);
            }
            $value = substr($i, 1, 1) == '#' ? QueryParameter::escapeLiteral($value) : QueryParameter::escapeUri($value);
            $value = str_replace(array('\\', '$'), array('\\\\', '\\$'), $value); // preg replace special chars escape
            $query = preg_replace('/[?][#@]' . $varName . '/', $value, $query, 1);
        }
        if (count($values) > 0) {
            throw new RuntimeException('number of values greater then the number of variables in the query');
        }

        return $query;
    }
public function getQuery(): string {
        $query  = $this->query;
        $values = $this->values;

        $matches = null;
        preg_match_all('/[?][#@][a-zA-Z]?[a-zA-Z0-9_]*/', $query, $matches);
        $matches = count($matches) > 0 ? $matches[0] : array();

        foreach ($matches as $i) {
            $varName = substr($i, 2);
            if ($varName != '') {
                if (!isset($this->values[$varName])) {
                    throw new RuntimeException('no value for variable ' . $varName);
                }
                $value = $values[$varName];
                unset($values[$varName]);
            } else {
                if (count($values) == 0) {
                    throw new RuntimeException('number of values lower then the number of variables in the query');
                }
                $value = array_shift($values);
            }
            $value = substr($i, 1, 1) == '#' ? QueryParameter::escapeLiteral($value) : QueryParameter::escapeUri($value);
            $value = str_replace(array('\\', '$'), array('\\\\', '\\$'), $value); // preg replace special chars escape
            $query = preg_replace('/[?][#@]' . $varName . '/', $value, $query, 1);
        }
        if (count($values) > 0) {
            throw new RuntimeException('number of values greater then the number of variables in the query');
        }

        return $query;
    }
public function getQuery ( ) : string { $ query = $ this -> query ; $ values = $ this -> values ; $ matches = null ; preg_match_all ( '/[?][#@][a-zA-Z]?[a-zA-Z0-9_]*/' , $ query , $ matches ) ; $ matches = count ( $ matches ) > 0 ? $ matches [ 0 ] : array ( ) ; foreach ( $ matches as $ i ) { $ varName = substr ( $ i , 2 ) ; if ( $ varName != '' ) { if ( ! isset ( $ this -> values [ $ varName ] ) ) { throw new RuntimeException ( 'no value for variable ' . $ varName ) ; } $ value = $ values [ $ varName ] ; unset ( $ values [ $ varName ] ) ; } else { if ( count ( $ values ) == 0 ) { throw new RuntimeException ( 'number of values lower then the number of variables in the query' ) ; } $ value = array_shift ( $ values ) ; } $ value = substr ( $ i , 1 , 1 ) == '#' ? QueryParameter :: escapeLiteral ( $ value ) : QueryParameter :: escapeUri ( $ value ) ; $ value = str_replace ( array ( '\\' , '$' ) , array ( '\\\\' , '\\$' ) , $ value ) ; // preg replace special chars escape $ query = preg_replace ( '/[?][#@]' . $ varName . '/' , $ value , $ query , 1 ) ; } if ( count ( $ values ) > 0 ) { throw new RuntimeException ( 'number of values greater then the number of variables in the query' ) ; } return $ query ; }
Returns query string ready to send to the SPRAQL endpoint
@return string
@throws RuntimeException
Returns query string ready to send to the SPRAQL endpoint