Platform  3.1
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  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * helper class for parsing PROPFIND 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_propfind.php,v 1.1 2006/11/22 10:33:59 eric Exp $
35 //
37 {
38  /**
39  * success state flag
40  *
41  * @var bool
42  * @access public
43  */
44  var $success = false;
45  /**
46  * found properties are collected here
47  *
48  * @var array
49  * @access public
50  */
51  var $props = false;
52  /**
53  * internal tag nesting depth counter
54  *
55  * @var int
56  * @access private
57  */
58  var $depth = 0;
59  /**
60  * constructor
61  *
62  * @access public
63  */
65  {
66  // success state flag
67  $this->success = true;
68  // property storage array
69  $this->props = array();
70  // internal tag depth counter
71  $this->depth = 0;
72  // remember if any input was parsed
73  $had_input = false;
74  // open input stream
75  $f_in = fopen($path, "r");
76  if (!$f_in) {
77  $this->success = false;
78  return;
79  }
80  // create XML parser
81  $xml_parser = xml_parser_create_ns("UTF-8", " ");
82  // set tag and data handlers
83  xml_set_element_handler($xml_parser, array(&$this,
84  "_startElement"
85  ) , array(&$this,
86  "_endElement"
87  ));
88  // we want a case sensitive parser
89  xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
90  // parse input
91  while ($this->success && !feof($f_in)) {
92  $line = fgets($f_in);
93  if (is_string($line)) {
94  $had_input = true;
95  $this->success&= xml_parse($xml_parser, $line, false);
96  }
97  }
98  // finish parsing
99  if ($had_input) {
100  $this->success&= xml_parse($xml_parser, "", true);
101  }
102  // free parser
103  xml_parser_free($xml_parser);
104  // close input stream
105  fclose($f_in);
106  // if no input was parsed it was a request
107  if (!count($this->props)) $this->props = "all"; // default
108 
109  }
110  /**
111  * start tag handler
112  *
113  * @access private
114  * @param resource parser
115  * @param string tag name
116  * @param array tag attributes
117  */
118  function _startElement($parser, $name, $attrs)
119  {
120  // name space handling
121  if (strstr($name, " ")) {
122  list($ns, $tag) = explode(" ", $name);
123  if ($ns == "") $this->success = false;
124  } else {
125  $ns = "";
126  $tag = $name;
127  }
128  // special tags at level 1: <allprop> and <propname>
129  if ($this->depth == 1) {
130  if ($tag == "allprop") $this->props = "all";
131 
132  if ($tag == "propname") $this->props = "names";
133  }
134  // requested properties are found at level 2
135  if ($this->depth == 2) {
136  $prop = array(
137  "name" => $tag
138  );
139  if ($ns) $prop["xmlns"] = $ns;
140  $this->props[] = $prop;
141  }
142  // increment depth count
143  $this->depth++;
144  }
145  /**
146  * end tag handler
147  *
148  * @access private
149  * @param resource parser
150  * @param string tag name
151  */
152  function _endElement($parser, $name)
153  {
154  // here we only need to decrement the depth count
155  $this->depth--;
156  }
157 }
158 ?>
← centre documentaire © anakeen - published under CC License - Dynacase