wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.Visitor.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.Visitor.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/core/class.WCMFException.php");
20 require_once(BASE."wcmf/lib/model/class.NodeIterator.php");
21 /**
22  * @class Visitor
23  * @ingroup Visitor
24  * @brief Visitor is used to extend an object's functionality by not extending
25  * its interface. Classes to use with the Visitor must implement the acceptVisitor() method.
26  * Visitor implements the 'Visitor Pattern'.
27  * It implements the 'Template Method Pattern' to allow subclasses
28  * to do any Pre- and Post Visit operations (doPreVisit() and doPostVisit() methods).
29  * The abstract base class Visitor defines the interface for all
30  * specialized Visitor classes.
31  *
32  * @author ingo herwig <ingo@wemove.com>
33  */
34 class Visitor
35 {
36  /**
37  * Start the visiting process by iterating over all objects using
38  * the given NodeIterator. The visit() method is called by every
39  * visited object.
40  * @param iterator A reference to the NodeIterator to use (configured with the start object).
41  */
42  function startIterator(&$iterator)
43  {
44  $this->doPreVisit();
45  while(!($iterator->isEnd()))
46  {
47  $currentObject = & $iterator->getCurrentObject();
48  $currentObject->acceptVisitor($this);
49  $iterator->proceed();
50  }
51  $this->doPostVisit();
52  }
53  /**
54  * Start the visiting process by iterating over all elements of a given array.
55  * The visit() method is called by every visited object.
56  * @param array An array holding references to the objects to visit.
57  */
58  function startArray(&$array)
59  {
60  $this->doPreVisit();
61  foreach($array as $currentObject)
62  $currentObject->acceptVisitor($this);
63 
64  $this->doPostVisit();
65  }
66  /**
67  * Visit the current object in iteration.
68  * Subclasses of Visitor override this method to implement the specialized
69  * functionality.
70  * @param obj A reference to the current object.
71  */
72  function visit(&$obj)
73  {
74  WCMFException::throwEx("visit() must be implemented by derived class: ".get_class($this), __FILE__, __LINE__);
75  }
76  /**
77  * Subclasses may override this method to do any operations before the visiting process here.
78  */
79  function doPreVisit() {}
80  /**
81  * Subclasses may override this method to do any operations after the visiting process here.
82  */
83  function doPostVisit() {}
84 }
85 ?>
Visitor is used to extend an object's functionality by not extending its interface. Classes to use with the Visitor must implement the acceptVisitor() method. Visitor implements the 'Visitor Pattern'. It implements the 'Template Method Pattern' to allow subclasses to do any Pre- and Post Visit operations (doPreVisit() and doPostVisit() methods). The abstract base class Visitor defines the interface for all specialized Visitor classes.
throwEx($message, $file='', $line='')
startIterator(&$iterator)
startArray(&$array)
visit(&$obj)