-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportFactory.php
143 lines (124 loc) · 3.62 KB
/
ReportFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
namespace Orkestra\Bundle\ReportBundle;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface,
Symfony\Component\Form\FormFactory;
use Doctrine\ORM\EntityManager;
/**
* Responsible for instantiating Presentations
*
* The ReportFactory is also responsible for managing the "list" of
* registered Reports and Presenters
*/
class ReportFactory
{
/**
* @var Symfony\Bundle\FrameworkBundle\Templating\EngineInterface
*/
protected $_engine;
/**
* @var Doctrine\ORM\EntityManager
*/
protected $_entityManager;
/**
* @var Symfony\Component\Form\FormFactory
*/
protected $_formFactory;
/**
* @var array
*/
protected $_presenters = array();
/**
* @var array
*/
protected $_reports = array();
/**
* Constructor
*
* @param Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $engine
* @param Doctrine\ORM\EntityManager $entityManager
* @param Symfony\Component\Form\FormFactory $formFactory
*/
public function __construct(EngineInterface $engine, EntityManager $entityManager, FormFactory $formFactory)
{
$this->_engine = $engine;
$this->_entityManager = $entityManager;
$this->_formFactory = $formFactory;
}
/**
* Creates a new Presentation
*
* @param Orkestra\Bundle\ReportBundle\IPresenter $presenter
* @param Orkestra\Bundle\ReportBundle\IReport $report
*/
public function createPresentation(PresenterInterface $presenter, ReportInterface $report)
{
$queryBuilder = $this->_entityManager->createQueryBuilder();
return new Presentation($this->_engine, $queryBuilder, $this->_formFactory, $this, $presenter, $report);
}
/**
* Registers a Presenter with the factory
*
* @param Orkestra\Bundle\ReportBundle\PresenterInterface
*/
public function addPresenter(PresenterInterface $presenter)
{
$this->_presenters[$presenter->getName()] = $presenter;
}
/**
* Gets a registered Presenter
*
* @param string $alias The alias of the Presenter
*
* @return Orkestra\Bundle\ReportBundle\IPresenter
* @throws InvalidArgumentException if the supplied alias does not exist
*/
public function getPresenter($alias)
{
if (empty($this->_presenters[$alias])) {
throw new \InvalidArgumentException(sprintf('No presenter with the alias "%s" exists.', $alias));
}
return $this->_presenters[$alias];
}
/**
* Gets all registered Presenters
*
* @return array Key is the alias; value is the instance
*/
public function getPresenters()
{
return $this->_presenters;
}
/**
* Registers a Report with the factory
*
* @param Orkestra\Bundle\ReportBundle\ReportInterface
*/
public function addReport(ReportInterface $report)
{
$this->_reports[$report->getName()] = $report;
}
/**
* Gets a registered Report
*
* @param string $alias The alias of the Report
*
* @return Orkestra\Bundle\ReportBundle\IReport
* @throws InvalidArgumentException if the supplied alias does not exist
*/
public function getReport($alias)
{
if (empty($this->_reports[$alias])) {
throw new \InvalidArgumentException(sprintf('No report with the alias "%s" exists.', $alias));
}
return $this->_reports[$alias];
}
/**
* Gets all registered Reports
*
* @return array Key is the alias; value is the instance
*/
public function getReports()
{
return $this->_reports;
}
}