ListObject::ParseConstraintsString PHP Method

ParseConstraintsString() public static method

Parses the constraints string and returns an array of words
public static ParseConstraintsString ( string $p_constraintsString ) : array
$p_constraintsString string
return array
    public static function ParseConstraintsString($p_constraintsString)
    {
        if (empty($p_constraintsString)) {
            return array();
        }
        $words = array();
        $escaped = false;
        $lastWord = '';
        foreach (str_split($p_constraintsString) as $char) {
            if (preg_match('/[\\s]/', $char) && !$escaped) {
                if (strlen($lastWord) > 0) {
                    if ($lastWord == "''") {
                        $lastWord = '';
                    }
                    $words[] = $lastWord;
                    $lastWord = '';
                }
            } elseif ($char == "\\" && !$escaped) {
                $escaped = true;
            } else {
                $lastWord .= $char;
                $escaped = false;
            }
        }
        if (strlen($lastWord) > 0) {
            if ($lastWord == "''") {
                $lastWord = '';
            }
            $words[] = $lastWord;
        }
        return $words;
    }

Usage Example

Exemplo n.º 1
0
	/**
	 * constructor
	 * For blank lists the start element index ($p_start) is smaller
	 * than 0.
	 *
	 * @param int $p_start
	 * @param string $p_parameters
	 */
	public function __construct($p_start = 0, $p_parameters = array())
	{
		/**
		 * For blank lists the start element index ($p_start) is smaller
		 * than 0.
		 */
		if ($p_start < 0) {
			$this->m_start = -1;
			$this->m_limit = -1;
			$this->m_columns = 0;
			$this->m_objects = new MyArrayObject(array());
			return;
		}

		$this->m_id = null;

		/**
		 * Processes the input parameters passed in an array; drops the invalid
		 * parameters and parameters with invalid values. Returns an array of
		 * valid parameters.
		 */
		$parameters = $this->ProcessParameters($p_parameters);

		/**
		 * Set common parameters:
		 * - start element index (m_start)
		 * - maximum list length (m_limit)
		 * - list columns (m_columns)
		 * - constraints string (m_constraintsStr)
		 * - order string (m_orderStr)
		 * - list name (m_name)
		 */
		$this->m_start = is_numeric($p_start) ? (int)$p_start : 0;
		$this->m_limit = isset($parameters['length']) ? (int)$parameters['length'] : 0;
		$this->m_columns = isset($parameters['columns']) ? (int)$parameters['columns'] : 0;
		$this->m_constraintsStr = isset($parameters['constraints']) ? $parameters['constraints'] : '';
		$this->m_orderStr = isset($parameters['order']) ? $parameters['order'] : '';
		$name = isset($parameters['name']) ? $parameters['name'] : '';
		$this->m_name = is_string($name) && trim($name) != '' ? $name : $this->defaultName();

		/**
		 * Process the list constraints.
		 */
		$constraints = $this->ProcessConstraints(self::ParseConstraintsString($this->m_constraintsStr));
        if ($constraints === false || $parameters === false) {
            $this->m_totalCount = 0;
            $this->m_objects = new MyArrayObject(array());
            $this->m_hasNextElements = false;
            return;
        }
        $this->m_parameters = $parameters;
        $this->m_constraints = array_merge($this->m_constraints, $constraints);

		/**
		 * Process order constraints.
		 */
		$this->m_order = $this->ProcessOrder(ListObject::ParseConstraintsString($this->m_orderStr));

        $list = $this->fetchFromCache();
        if (!is_null($list)) {
        	$this->duplicateObject($list);
        	return;
        }

		$objects = $this->CreateList($this->m_start, $this->m_limit, $parameters, $this->m_totalCount);
		if (!is_array($objects)) {
		    $objects = array();
		}
  		$this->m_objects = new MyArrayObject($objects);
  		$this->m_hasNextElements = $this->m_totalCount > ($this->m_start + $this->getLength());
  		$this->storeInCache();
	}
All Usage Examples Of ListObject::ParseConstraintsString