Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
_parse_propfind.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * helper class for parsing PROPFIND request bodies
8  *
9  * @package FDL
10  * @author Hartmut Holzgraefe <hholzgra@php.net>
11  * @version @package-version@
12  */
13 /**
14  */
15 //
16 // +----------------------------------------------------------------------+
17 // | PHP Version 4 |
18 // +----------------------------------------------------------------------+
19 // | Copyright (c) 1997-2003 The PHP Group |
20 // +----------------------------------------------------------------------+
21 // | This source file is subject to version 2.02 of the PHP license, |
22 // | that is bundled with this package in the file LICENSE, and is |
23 // | available at through the world-wide-web at |
24 // | http://www.php.net/license/2_02.txt. |
25 // | If you did not receive a copy of the PHP license and are unable to |
26 // | obtain it through the world-wide-web, please send a note to |
27 // | license@php.net so we can mail you a copy immediately. |
28 // +----------------------------------------------------------------------+
29 // | Authors: Hartmut Holzgraefe <hholzgra@php.net> |
30 // | Christian Stocker <chregu@bitflux.ch> |
31 // +----------------------------------------------------------------------+
32 //
33 // $Id: _parse_propfind.php,v 1.1 2006/11/22 10:33:59 eric Exp $
34 //
36 {
37  /**
38  * success state flag
39  *
40  * @var bool
41  * @access public
42  */
43  var $success = false;
44  /**
45  * found properties are collected here
46  *
47  * @var array
48  * @access public
49  */
50  var $props = false;
51  /**
52  * internal tag nesting depth counter
53  *
54  * @var int
55  * @access private
56  */
57  var $depth = 0;
58  /**
59  * constructor
60  *
61  * @access public
62  */
64  {
65  // success state flag
66  $this->success = true;
67  // property storage array
68  $this->props = array();
69  // internal tag depth counter
70  $this->depth = 0;
71  // remember if any input was parsed
72  $had_input = false;
73  // open input stream
74  $f_in = fopen($path, "r");
75  if (!$f_in) {
76  $this->success = false;
77  return;
78  }
79  // create XML parser
80  $xml_parser = xml_parser_create_ns("UTF-8", " ");
81  // set tag and data handlers
82  xml_set_element_handler($xml_parser, array(&$this,
83  "_startElement"
84  ) , array(&$this,
85  "_endElement"
86  ));
87  // we want a case sensitive parser
88  xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
89  // parse input
90  while ($this->success && !feof($f_in)) {
91  $line = fgets($f_in);
92  if (is_string($line)) {
93  $had_input = true;
94  $this->success&= xml_parse($xml_parser, $line, false);
95  }
96  }
97  // finish parsing
98  if ($had_input) {
99  $this->success&= xml_parse($xml_parser, "", true);
100  }
101  // free parser
102  xml_parser_free($xml_parser);
103  // close input stream
104  fclose($f_in);
105  // if no input was parsed it was a request
106  if (!count($this->props)) $this->props = "all"; // default
107 
108  }
109  /**
110  * start tag handler
111  *
112  * @access private
113  * @param resource parser
114  * @param string tag name
115  * @param array tag attributes
116  */
117  function _startElement($parser, $name, $attrs)
118  {
119  // name space handling
120  if (strstr($name, " ")) {
121  list($ns, $tag) = explode(" ", $name);
122  if ($ns == "") $this->success = false;
123  } else {
124  $ns = "";
125  $tag = $name;
126  }
127  // special tags at level 1: <allprop> and <propname>
128  if ($this->depth == 1) {
129  if ($tag == "allprop") $this->props = "all";
130 
131  if ($tag == "propname") $this->props = "names";
132  }
133  // requested properties are found at level 2
134  if ($this->depth == 2) {
135  $prop = array(
136  "name" => $tag
137  );
138  if ($ns) $prop["xmlns"] = $ns;
139  $this->props[] = $prop;
140  }
141  // increment depth count
142  $this->depth++;
143  }
144  /**
145  * end tag handler
146  *
147  * @access private
148  * @param resource parser
149  * @param string tag name
150  */
151  function _endElement($parser, $name)
152  {
153  // here we only need to decrement the depth count
154  $this->depth--;
155  }
156 }
157 ?>
_endElement($parser, $name)
$path
Definition: dav.php:39
_startElement($parser, $name, $attrs)
← centre documentaire © anakeen