get() public static method

Get all options currently set as default.
public static get ( ) : array
return array An array of options. Note that only explicitly set options are returned. {@link QueryPath} defines default options which are not stored in this object.
 public function testQPMerge()
 {
     $options = array('test1' => 'val1', 'test2' => 'val2');
     $options2 = array('test1' => 'val3', 'test4' => 'val4');
     Options::set($options);
     Options::merge($options2);
     $results = Options::get();
     $this->assertTrue(Options::has('test4'));
     $this->assertEquals('val3', $results['test1']);
 }
示例#2
0
 /**
  * Constructor.
  *
  * Typically, a new DOMQuery is created by QueryPath::with(), QueryPath::withHTML(),
  * qp(), or htmlqp().
  *
  * @param mixed $document
  *   A document-like object.
  * @param string $string
  *   A CSS 3 Selector
  * @param array $options
  *   An associative array of options.
  * @see qp()
  */
 public function __construct($document = NULL, $string = NULL, $options = array())
 {
     $string = trim($string);
     $this->options = $options + Options::get() + $this->options;
     $parser_flags = isset($options['parser_flags']) ? $options['parser_flags'] : self::DEFAULT_PARSER_FLAGS;
     if (!empty($this->options['ignore_parser_warnings'])) {
         // Don't convert parser warnings into exceptions.
         $this->errTypes = 257;
         //E_ERROR | E_USER_ERROR;
     } elseif (isset($this->options['exception_level'])) {
         // Set the error level at which exceptions will be thrown. By default,
         // QueryPath will throw exceptions for
         // E_ERROR | E_USER_ERROR | E_WARNING | E_USER_WARNING.
         $this->errTypes = $this->options['exception_level'];
     }
     // Empty: Just create an empty QP.
     if (empty($document)) {
         $this->document = isset($this->options['encoding']) ? new \DOMDocument('1.0', $this->options['encoding']) : new \DOMDocument();
         $this->setMatches(new \SplObjectStorage());
     } elseif (is_object($document)) {
         // This is the most frequent object type.
         if ($document instanceof \SplObjectStorage) {
             $this->matches = $document;
             if ($document->count() != 0) {
                 $first = $this->getFirstMatch();
                 if (!empty($first->ownerDocument)) {
                     $this->document = $first->ownerDocument;
                 }
             }
         } elseif ($document instanceof DOMQuery) {
             //$this->matches = $document->get(NULL, TRUE);
             $this->setMatches($document->get(NULL, TRUE));
             if ($this->matches->count() > 0) {
                 $this->document = $this->getFirstMatch()->ownerDocument;
             }
         } elseif ($document instanceof \DOMDocument) {
             $this->document = $document;
             //$this->matches = $this->matches($document->documentElement);
             $this->setMatches($document->documentElement);
         } elseif ($document instanceof \DOMNode) {
             $this->document = $document->ownerDocument;
             //$this->matches = array($document);
             $this->setMatches($document);
         } elseif ($document instanceof \SimpleXMLElement) {
             $import = dom_import_simplexml($document);
             $this->document = $import->ownerDocument;
             //$this->matches = array($import);
             $this->setMatches($import);
         } else {
             throw new \QueryPath\Exception('Unsupported class type: ' . get_class($document));
         }
     } elseif (is_array($document)) {
         //trigger_error('Detected deprecated array support', E_USER_NOTICE);
         if (!empty($document) && $document[0] instanceof \DOMNode) {
             $found = new \SplObjectStorage();
             foreach ($document as $item) {
                 $found->attach($item);
             }
             //$this->matches = $found;
             $this->setMatches($found);
             $this->document = $this->getFirstMatch()->ownerDocument;
         }
     } elseif ($this->isXMLish($document)) {
         // $document is a string with XML
         $this->document = $this->parseXMLString($document);
         $this->setMatches($this->document->documentElement);
     } else {
         // $document is a filename
         $context = empty($options['context']) ? NULL : $options['context'];
         $this->document = $this->parseXMLFile($document, $parser_flags, $context);
         $this->setMatches($this->document->documentElement);
     }
     // Globally set the output option.
     if (isset($this->options['format_output']) && $this->options['format_output'] == FALSE) {
         $this->document->formatOutput = FALSE;
     } else {
         $this->document->formatOutput = TRUE;
     }
     // Do a find if the second param was set.
     if (isset($string) && strlen($string) > 0) {
         // We don't issue a find because that creates a new DOMQuery.
         //$this->find($string);
         $query = new \QueryPath\CSS\DOMTraverser($this->matches);
         $query->find($string);
         $this->setMatches($query->matches());
     }
 }