Path

ez components / documentation / api reference / 2007.2.1 / webdav


eZ Components 2007.2.1

Webdav

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Source for file basic.php

Documentation is available at basic.php

  1. <?php
  2. /**
  3.  * File containing the ezcWebdavBasicPropertyStorage class.
  4.  * 
  5.  * @package Webdav
  6.  * @version 1.0
  7.  * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
  8.  * @license http://ez.no/licenses/new_bsd New BSD License
  9.  */
 10. /**
 11.  * Container class for ezcWebdavProperty objects.
 12.  *
 13.  * An instance of this class is used to manage WebDAV properties, namely
 14.  * instances of {@link ezcWebdavProperty}. Properties are structured by their
 15.  * name and the namespace they reside in.
 16.  * 
 17.  * @package Webdav
 18.  * @version 1.0
 19.  */
 20. class ezcWebdavBasicPropertyStorage implements ezcWebdavPropertyStorage
 21. {
 22.     /**
 23.      * Stores the WebDAV properties.
 24.      *
 25.      * The structure of this array is:
 26.      * <code>
 27.      * array(
 28.      *     'DAV:' => array(
 29.      *         '<live property name>' => ezcWebdavLiveProperty,
 30.      *         // ...
 31.      *     ),
 32.      *     '<another namespace URI>'array(
 33.      *         '<dead property name>' => ezcWebdavDeadProperty,
 34.      *         // ...
 35.      *     ),
 36.      *     // ...
 37.      * )
 38.      * </code>
 39.      * 
 40.      * @var array 
 41.      */
 42.     protected $properties = array();
 43.  
 44.     /**
 45.      * Stores a list of the assigned properties in the order they were
 46.      * assigned, to make this order accessible for the Iterator.
 47.      * 
 48.      * @var array 
 49.      */
 50.     protected $propertyOrder = array();
 51.  
 52.     /**
 53.      * Current position of the iterator in the ordered property list.
 54.      * 
 55.      * @var int 
 56.      */
 57.     protected $propertyOrderPosition = 0;
 58.  
 59.     /**
 60.      * Next ID for a element in the ordered property list, to generate valid
 61.      * IDs even when some contents has been removed.
 62.      * 
 63.      * @var int 
 64.      */
 65.     protected $propertyOrderNextId = 0;
 66.  
 67.     /**
 68.      * Attaches a property to the storage.
 69.      *
 70.      * Adds the given $property to the storage. The property can later be
 71.      * accessed by its name in combination with the namespace through the
 72.      * {@link get()} method. Live properties (and only these) reside in the
 73.      * namespace DAV:, which is the default for all accessor methods.
 74.      *
 75.      * If a property with the same namespace and name is already contained in
 76.      * the storage, it will be overwritten.
 77.      * 
 78.      * @param ezcWebdavProperty $property 
 79.      * @return void 
 80.      */
 81.     public function attachezcWebdavProperty $property )
 82.     {
 83.         // Update list of ordered properties
 84.         if ( ( isset$this->properties[$property->namespace=== false ||
 85.              isset$this->properties[$property->namespace][$property->name=== false ) )
 86.         {
 87.             $this->propertyOrder[$this->propertyOrderNextId++array$property->namespace$property->name );
 88.         }
 89.  
 90.         // Add property
 91.         $this->properties[$property->namespace][$property->name$property;
 92.     }
 93.     
 94.     /**
 95.      * Detaches a property from the storage.
 96.      *
 97.      * Removes the property with the given $name and $namespace from the
 98.      * storage. If the property does not exist in the storage, the call is
 99.      * silently ignored. If no $namespace is given, the default namespace for
100.      * live properties ('DAV:') is used.
101.      * 
102.      * @param string $name 
103.      * @param string $namespace 
104.      * @return void 
105.      */
106.     public function detach$name$namespace 'DAV:' )
107.     {
108.         if ( ( isset$this->properties[$namespace=== true &&
109.              isset$this->properties[$namespace][$name=== true ) )
110.         {
111.             unset$this->properties[$namespace][$name);
112.         }
113.     }
114.     
115.     /**
116.      * Returns if the given property exists in the storage.
117.      *
118.      * Returns if the property with the given $name and $namespace is contained
119.      * in the storage.  If the $namespace parameter is omited, the default live
120.      * property namespace ('DAV:') is used.
121.      *
122.      * @param string $name 
123.      * @param string $namespace 
124.      * @return bool 
125.      */
126.     public function contains$name$namespace 'DAV:' )
127.     {
128.         return isset$this->properties[$namespace][$name);
129.     }
130.  
131.     /**
132.      * Returns a property from the storage.
133.      *
134.      * Returns the property with the given $name and $namespace. If the
135.      * $namespace parameter is omitted, the default live property namespace
136.      * ('DAV:') namespace is used. If the desired property is not contained in
137.      * the storage, null is returned.
138.      * 
139.      * @param string $name 
140.      * @param string $namespace 
141.      * @return ezcWebdavProperty|null
142.      */
143.     public function get$name$namespace 'DAV:' )
144.     {
145.         if isset$this->properties[$namespace][$name=== true )
146.         {
147.             return $this->properties[$namespace][$name];
148.         }
149.         return null;
150.     }
151.  
152.     /**
153.      * Returns all properties of a given namespace.
154.      *
155.      * The returned array is indexed by the property names. Live properties can
156.      * be accessed by simply ommiting the $namespace parameter, since  then the
157.      * default namespace for live properties ('DAV:') is used.
158.      * 
159.      * @param string $namespace 
160.      * @return array(string=>ezcWebdavProperty) 
161.      */
162.     public function getProperties$namespace 'DAV:' )
163.     {
164.         if isset$this->properties[$namespace=== false )
165.         {
166.             return array();
167.         }
168.         return $this->properties[$namespace];
169.     }
170.  
171.     /**
172.      * Returns all properties contained in the storage.
173.      *
174.      * Returns the complete array stored in {@link $properties}.
175.      * 
176.      * @return array(string=>array(string=>ezcWebdavProperty)) 
177.      */
178.     public function getAllProperties()
179.     {
180.         return $this->properties;
181.     }
182.  
183.     /**
184.      * Diff two property storages.
185.      *
186.      * Returns a property storage, which does only contain properties that are
187.      * not present in the $properties parameter.
188.      * 
189.      * @param ezcWebdavPropertyStorage $properties 
190.      * @return ezcWebdavBasicPropertyStorage 
191.      */
192.     public function diffezcWebdavPropertyStorage $properties )
193.     {
194.         $foreign $properties->getAllProperties();
195.  
196.         $diffedProperties new ezcWebdavBasicPropertyStorage();
197.         foreach $this->properties as $namespace => $properties )
198.         {
199.             foreach $properties as $name => $property )
200.             {
201.                 if !isset$foreign[$namespace][$name) )
202.                 {
203.                     // Only add properties to new property storage, which could
204.                     // not be found in the foreign property storage.
205.                     $diffedProperties->attach$property );
206.                 }
207.             }
208.         }
209.  
210.         return $diffedProperties;
211.     }
212.  
213.     /**
214.      * Intersects between two property storages.
215.      *
216.      * Calculate and return an instance of {@link }
217.      * ezcWebdavBasicPropertyStorage} which contains the intersection of two
218.      * property storages. This means a new property storage will be return
219.      * which contains all values, which are present in the current and the
220.      * given $properties property storage.
221.      * 
222.      * @param ezcWebdavPropertyStorage $properties 
223.      * @return ezcWebdavBasicPropertyStorage 
224.      */
225.     public function intersectezcWebdavPropertyStorage $properties )
226.     {
227.         $foreign $properties->getAllProperties();
228.  
229.         $intersection new ezcWebdavBasicPropertyStorage();
230.         foreach $this->properties as $namespace => $properties )
231.         {
232.             foreach $properties as $name => $property )
233.             {
234.                 if isset$foreign[$namespace][$name) )
235.                 {
236.                     // Only add properties to new property storage, which could
237.                     // be found in both property storages.
238.                     $intersection->attach$property );
239.                 }
240.             }
241.         }
242.  
243.         return $intersection;
244.     }
245.  
246.     /*
247.      * Methods required for Countable
248.      */
249.  
250.     /**
251.      * Return property count.
252.      *
253.      * Implementation required by interface Countable. Count the numbers of
254.      * items contained by the instance. Will return the overall item count
255.      * ignoring different namespaces.
256.      * 
257.      * @return int 
258.      */
259.     public function count()
260.     {
261.         $count 0;
262.         foreach $this->properties as $properties )
263.         {
264.             $count += count$properties );
265.         }
266.         
267.         return $count;
268.     }
269.  
270.     /**
271.      * Methods required for Iterator
272.      */
273.  
274.     /**
275.      * Implements current() for Iterator.
276.      *
277.      * Returns the currently selected element during iteration with foreach.
278.      * 
279.      * @return ezcWebdavProperty 
280.      */
281.     public function current()
282.     {
283.         list$namespace$name $this->propertyOrder[$this->propertyOrderPosition];
284.  
285.         // Skip detached properties
286.         while !isset$this->properties[$namespace][$name) )
287.         {
288.             if !isset$this->propertyOrder[++$this->propertyOrderPosition) )
289.             {
290.                 // We reached the end.
291.                 return false;
292.             }
293.  
294.             list$namespace$name $this->propertyOrder[$this->propertyOrderPosition];
295.         }
296.  
297.         return $this->properties[$namespace][$name];
298.     }
299.  
300.     /**
301.      * Implements key() for Iterator
302.      *
303.      * Returns the key of the currently selected element during iteration with
304.      * foreach.
305.      * 
306.      * @return int 
307.      */
308.     public function key()
309.     {
310.         return $this->propertyOrderPosition;
311.     }
312.  
313.     /**
314.      * Implements next() for Iterator
315.      *
316.      * Advances the internal pointer to the next element during iteration with
317.      * foreach.
318.      * 
319.      * @return mixed 
320.      */
321.     public function next()
322.     {
323.         do 
324.         {
325.             if !isset$this->propertyOrder[++$this->propertyOrderPosition) )
326.             {
327.                 // We reached the end.
328.                 return false;
329.             }
330.  
331.             list$namespace$name $this->propertyOrder[$this->propertyOrderPosition];
332.         // Skip detached properties
333.         while !isset$this->properties[$namespace][$name) );
334.  
335.         return $this->properties[$namespace][$name];
336.     }
337.  
338.     /**
339.      * Implements rewind() for Iterator
340.      *
341.      * Resets the internal pointer to the first element before iteration with
342.      * foreach.
343.      * 
344.      * @return void 
345.      */
346.     public function rewind()
347.     {
348.         $this->propertyOrderPosition = 0;
349.     }
350.  
351.     /**
352.      * Implements valid() for Iterator
353.      *
354.      * Returns if the internal pointer still points to a valid element when
355.      * iteration with foreach. If this method returns false, iteration ends.
356.      * 
357.      * @return boolean 
358.      */
359.     public function valid()
360.     {
361.         return $this->propertyOrderPosition < $this->propertyOrderNextId );
362.     }
363. }
364.  
365. ?>
Last updated: Thu, 31 Jan 2008