Platform  3.1
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  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * helper class for parsing PROPPATCH request bodies
9  *
10  * @package FDL
11  * @author Hartmut Holzgraefe <hholzgra@php.net>
12  * @version @package-version@
13  */
14 /**
15  */
16 //
17 // +----------------------------------------------------------------------+
18 // | PHP Version 4 |
19 // +----------------------------------------------------------------------+
20 // | Copyright (c) 1997-2003 The PHP Group |
21 // +----------------------------------------------------------------------+
22 // | This source file is subject to version 2.02 of the PHP license, |
23 // | that is bundled with this package in the file LICENSE, and is |
24 // | available at through the world-wide-web at |
25 // | http://www.php.net/license/2_02.txt. |
26 // | If you did not receive a copy of the PHP license and are unable to |
27 // | obtain it through the world-wide-web, please send a note to |
28 // | license@php.net so we can mail you a copy immediately. |
29 // +----------------------------------------------------------------------+
30 // | Authors: Hartmut Holzgraefe <hholzgra@php.net> |
31 // | Christian Stocker <chregu@bitflux.ch> |
32 // +----------------------------------------------------------------------+
33 //
34 // $Id: _parse_proppatch.php,v 1.1 2006/11/22 10:33:59 eric Exp $
35 //
37 {
38  /**
39  *
40  *
41  * @var
42  * @access
43  */
44  var $success;
45  /**
46  *
47  *
48  * @var
49  * @access
50  */
51  var $props;
52  /**
53  *
54  *
55  * @var
56  * @access
57  */
58  var $depth;
59  /**
60  *
61  *
62  * @var
63  * @access
64  */
65  var $mode;
66  /**
67  *
68  *
69  * @var
70  * @access
71  */
72  var $current;
73  /**
74  * constructor
75  *
76  * @param string path of input stream
77  * @access public
78  */
80  {
81  $this->success = true;
82 
83  $this->depth = 0;
84  $this->props = array();
85  $had_input = false;
86 
87  $f_in = fopen($path, "r");
88  if (!$f_in) {
89  $this->success = false;
90  return;
91  }
92 
93  $xml_parser = xml_parser_create_ns("UTF-8", " ");
94 
95  xml_set_element_handler($xml_parser, array(&$this,
96  "_startElement"
97  ) , array(&$this,
98  "_endElement"
99  ));
100 
101  xml_set_character_data_handler($xml_parser, array(&$this,
102  "_data"
103  ));
104 
105  xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
106 
107  while ($this->success && !feof($f_in)) {
108  $line = fgets($f_in);
109  if (is_string($line)) {
110  $had_input = true;
111  $this->success&= xml_parse($xml_parser, $line, false);
112  }
113  }
114 
115  if ($had_input) {
116  $this->success&= xml_parse($xml_parser, "", true);
117  }
118 
119  xml_parser_free($xml_parser);
120 
121  fclose($f_in);
122  }
123  /**
124  * tag start handler
125  *
126  * @param resource parser
127  * @param string tag name
128  * @param array tag attributes
129  * @return void
130  * @access private
131  */
132  function _startElement($parser, $name, $attrs)
133  {
134  if (strstr($name, " ")) {
135  list($ns, $tag) = explode(" ", $name);
136  if ($ns == "") $this->success = false;
137  } else {
138  $ns = "";
139  $tag = $name;
140  }
141 
142  if ($this->depth == 1) {
143  $this->mode = $tag;
144  }
145 
146  if ($this->depth == 3) {
147  $prop = array(
148  "name" => $tag
149  );
150  $this->current = array(
151  "name" => $tag,
152  "ns" => $ns,
153  "status" => 200
154  );
155  if ($this->mode == "set") {
156  $this->current["val"] = ""; // default set val
157 
158  }
159  }
160 
161  if ($this->depth >= 4) {
162  $this->current["val"].= "<$tag";
163  if (isset($attr)) {
164  foreach ($attr as $key => $val) {
165  $this->current["val"].= ' ' . $key . '="' . str_replace('"', '&quot;', $val) . '"';
166  }
167  }
168  $this->current["val"].= ">";
169  }
170 
171  $this->depth++;
172  }
173  /**
174  * tag end handler
175  *
176  * @param resource parser
177  * @param string tag name
178  * @return void
179  * @access private
180  */
181  function _endElement($parser, $name)
182  {
183  if (strstr($name, " ")) {
184  list($ns, $tag) = explode(" ", $name);
185  if ($ns == "") $this->success = false;
186  } else {
187  $ns = "";
188  $tag = $name;
189  }
190 
191  $this->depth--;
192 
193  if ($this->depth >= 4) {
194  $this->current["val"].= "</$tag>";
195  }
196 
197  if ($this->depth == 3) {
198  if (isset($this->current)) {
199  $this->props[] = $this->current;
200  unset($this->current);
201  }
202  }
203  }
204  /**
205  * input data handler
206  *
207  * @param resource parser
208  * @param string data
209  * @return void
210  * @access private
211  */
212  function _data($parser, $data)
213  {
214  if (isset($this->current)) {
215  $this->current["val"].= $data;
216  }
217  }
218 }
219 /*
220  * Local variables:
221  * tab-width: 4
222  * c-basic-offset: 4
223  * indent-tabs-mode:nil
224  * End:
225 */
← centre documentaire © anakeen - published under CC License - Dynacase