wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.OutputVisitor.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.OutputVisitor.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/visitor/class.Visitor.php");
20 require_once(BASE."wcmf/lib/output/class.DefaultOutputStrategy.php");
21 /**
22  * @class OutputVisitor
23  * @ingroup Visitor
24  * @brief The OutputVisitor is used to output an object's content to different destinations and
25  * formats.
26  * The spezial output destination/format may be configured by using the corresponding
27  * OutputStrategy, which is set using the setOutputStrategy() method.
28  *
29  * @author ingo herwig <ingo@wemove.com>
30  */
31 class OutputVisitor extends Visitor
32 {
33  var $_outputStrategy = null;
34  /**
35  * Constructor.
36  * @param outputStrategy A reference to an OutputStrategy to use (If 'null', a DefaultOutputStrategy will be used).
37  */
38  function OutputVisitor($outputStrategy=null)
39  {
40  if (get_class($outputStrategy) != '')
41  $this->_outputStrategy = $outputStrategy;
42  else
43  $this->_outputStrategy = new DefaultOutputStrategy();
44  }
45  /**
46  * Set the PersistenceStrategy.
47  * @param strategy A reference to an OutputStrategy to use.
48  */
49  function setOutputStrategy(&$strategy)
50  {
51  $this->_outputStrategy = &$strategy;
52  }
53  /**
54  * Visit the current object in iteration and output its content using
55  * the configured OutputStrategy.
56  * @param obj A reference to the current object.
57  */
58  function visit(&$obj)
59  {
60  $this->_outputStrategy->writeObject($obj);
61  }
62  /**
63  * Output the document header.
64  */
65  function doPreVisit()
66  {
67  $this->_outputStrategy->writeHeader();
68  }
69  /**
70  * Output the document footer.
71  */
72  function doPostVisit()
73  {
74  $this->_outputStrategy->writeFooter();
75  }
76 }
77 ?>
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.
The OutputVisitor is used to output an object's content to different destinations and formats...
OutputVisitor($outputStrategy=null)
This OutputStrategy outputs an object's content to the Log category DefaultOutputStrategy. Classes used must implement the toString() method.
setOutputStrategy(&$strategy)