OutputVisitor.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\model\visitor;
12 
13 use wcmf\lib\model\output\DefaultOutputStrategy;
15 
16 /**
17  * OutputVisitor is used to output an object's content to different destinations and
18  * formats.
19  * The spezial output destination/format may be configured by using the corresponding
20  * OutputStrategy, which is set using the setOutputStrategy() method.
21  *
22  * @author ingo herwig <ingo@wemove.com>
23  */
24 class OutputVisitor extends Visitor {
25 
26  private $outputStrategy = null;
27 
28  /**
29  * Constructor.
30  * @param $outputStrategy OutputStrategy instance to use (If 'null', a DefaultOutputStrategy will be used).
31  */
32  public function __construct($outputStrategy=null) {
33  if (get_class($outputStrategy) != '') {
34  $this->outputStrategy = $outputStrategy;
35  }
36  else {
37  $this->outputStrategy = new DefaultOutputStrategy();
38  }
39  }
40 
41  /**
42  * Set the PersistenceStrategy.
43  * @param $strategy OutputStrategy instance to use.
44  */
45  public function setOutputStrategy($strategy) {
46  $this->outputStrategy = $strategy;
47  }
48 
49  /**
50  * Visit the current object in iteration and output its content using
51  * the configured OutputStrategy.
52  * @param $obj PersistentObject instance
53  */
54  public function visit($obj) {
55  $this->outputStrategy->writeObject($obj);
56  }
57 
58  /**
59  * Output the document header.
60  */
61  public function doPreVisit() {
62  $this->outputStrategy->writeHeader();
63  }
64 
65  /**
66  * Output the document footer.
67  */
68  public function doPostVisit() {
69  $this->outputStrategy->writeFooter();
70  }
71 }
72 ?>
OutputVisitor is used to output an object's content to different destinations and formats.
doPostVisit()
Output the document footer.
__construct($outputStrategy=null)
Constructor.
Visitor is used to extend an object's functionality by not extending its interface.
Definition: Visitor.php:26
visit($obj)
Visit the current object in iteration and output its content using the configured OutputStrategy.
setOutputStrategy($strategy)
Set the PersistenceStrategy.
doPreVisit()
Output the document header.