Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
_parse_proppatch.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * helper class for parsing PROPPATCH 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_proppatch.php,v 1.1 2006/11/22 10:33:59 eric Exp $
34 //
36 {
37  /**
38  *
39  *
40  * @var
41  * @access
42  */
43  var $success;
44  /**
45  *
46  *
47  * @var
48  * @access
49  */
50  var $props;
51  /**
52  *
53  *
54  * @var
55  * @access
56  */
57  var $depth;
58  /**
59  *
60  *
61  * @var
62  * @access
63  */
64  var $mode;
65  /**
66  *
67  *
68  * @var
69  * @access
70  */
71  var $current;
72  /**
73  * constructor
74  *
75  * @param string path of input stream
76  * @access public
77  */
79  {
80  $this->success = true;
81 
82  $this->depth = 0;
83  $this->props = array();
84  $had_input = false;
85 
86  $f_in = fopen($path, "r");
87  if (!$f_in) {
88  $this->success = false;
89  return;
90  }
91 
92  $xml_parser = xml_parser_create_ns("UTF-8", " ");
93 
94  xml_set_element_handler($xml_parser, array(&$this,
95  "_startElement"
96  ) , array(&$this,
97  "_endElement"
98  ));
99 
100  xml_set_character_data_handler($xml_parser, array(&$this,
101  "_data"
102  ));
103 
104  xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
105 
106  while ($this->success && !feof($f_in)) {
107  $line = fgets($f_in);
108  if (is_string($line)) {
109  $had_input = true;
110  $this->success&= xml_parse($xml_parser, $line, false);
111  }
112  }
113 
114  if ($had_input) {
115  $this->success&= xml_parse($xml_parser, "", true);
116  }
117 
118  xml_parser_free($xml_parser);
119 
120  fclose($f_in);
121  }
122  /**
123  * tag start handler
124  *
125  * @param resource parser
126  * @param string tag name
127  * @param array tag attributes
128  * @return void
129  * @access private
130  */
131  function _startElement($parser, $name, $attrs)
132  {
133  if (strstr($name, " ")) {
134  list($ns, $tag) = explode(" ", $name);
135  if ($ns == "") $this->success = false;
136  } else {
137  $ns = "";
138  $tag = $name;
139  }
140 
141  if ($this->depth == 1) {
142  $this->mode = $tag;
143  }
144 
145  if ($this->depth == 3) {
146  $prop = array(
147  "name" => $tag
148  );
149  $this->current = array(
150  "name" => $tag,
151  "ns" => $ns,
152  "status" => 200
153  );
154  if ($this->mode == "set") {
155  $this->current["val"] = ""; // default set val
156 
157  }
158  }
159 
160  if ($this->depth >= 4) {
161  $this->current["val"].= "<$tag";
162  if (isset($attr)) {
163  foreach ($attr as $key => $val) {
164  $this->current["val"].= ' ' . $key . '="' . str_replace('"', '&quot;', $val) . '"';
165  }
166  }
167  $this->current["val"].= ">";
168  }
169 
170  $this->depth++;
171  }
172  /**
173  * tag end handler
174  *
175  * @param resource parser
176  * @param string tag name
177  * @return void
178  * @access private
179  */
180  function _endElement($parser, $name)
181  {
182  if (strstr($name, " ")) {
183  list($ns, $tag) = explode(" ", $name);
184  if ($ns == "") $this->success = false;
185  } else {
186  $ns = "";
187  $tag = $name;
188  }
189 
190  $this->depth--;
191 
192  if ($this->depth >= 4) {
193  $this->current["val"].= "</$tag>";
194  }
195 
196  if ($this->depth == 3) {
197  if (isset($this->current)) {
198  $this->props[] = $this->current;
199  unset($this->current);
200  }
201  }
202  }
203  /**
204  * input data handler
205  *
206  * @param resource parser
207  * @param string data
208  * @return void
209  * @access private
210  */
211  function _data($parser, $data)
212  {
213  if (isset($this->current)) {
214  $this->current["val"].= $data;
215  }
216  }
217 }
218 /*
219  * Local variables:
220  * tab-width: 4
221  * c-basic-offset: 4
222  * indent-tabs-mode:nil
223  * End:
224 */
_endElement($parser, $name)
_data($parser, $data)
_startElement($parser, $name, $attrs)
$path
Definition: dav.php:39
$data
← centre documentaire © anakeen