1 | <?php |
||
23 | class Transformation |
||
24 | { |
||
25 | /** |
||
26 | * @var string Reference to an object containing the business logic used to execute this transformation. |
||
27 | */ |
||
28 | protected $writer = null; |
||
29 | |||
30 | /** |
||
31 | * @var string the location where the output should be sent to; the exact function differs per writer. |
||
32 | */ |
||
33 | protected $artifact = ''; |
||
34 | |||
35 | /** |
||
36 | * @var string the location where input for a writer should come from; the exact function differs per writer. |
||
37 | */ |
||
38 | protected $source = ''; |
||
39 | |||
40 | /** |
||
41 | * @var string a filter or other form of limitation on what information of the AST is used; the exact function |
||
42 | * differs per writer. |
||
43 | */ |
||
44 | protected $query = ''; |
||
45 | |||
46 | /** |
||
47 | * @var Transformer The object guiding the transformation process and having meta-data of it. |
||
48 | */ |
||
49 | protected $transformer; |
||
50 | |||
51 | /** |
||
52 | * @var Parameter[] A series of parameters that can influence what the writer does; the exact function differs |
||
53 | * per writer. |
||
54 | */ |
||
55 | protected $parameters = []; |
||
56 | |||
57 | /** |
||
58 | * Constructs a new Transformation object and populates the required parameters. |
||
59 | * |
||
60 | * @param string $query What information to use as datasource for the writer's source. |
||
61 | * @param string $writer What type of transformation to apply (XSLT, PDF, Checkstyle etc). |
||
62 | * @param string $source Which template or type of source to use. |
||
63 | * @param string $artifact What is the filename of the result (relative to the generated root) |
||
64 | */ |
||
65 | 1 | public function __construct($query, $writer, $source, $artifact) |
|
66 | { |
||
67 | 1 | $this->setQuery($query); |
|
68 | 1 | $this->setWriter($writer); |
|
69 | 1 | $this->setSource($source); |
|
70 | 1 | $this->setArtifact($artifact); |
|
71 | 1 | } |
|
72 | |||
73 | /** |
||
74 | * Sets the query. |
||
75 | * |
||
76 | * @param string $query Free-form string with writer-specific values. |
||
77 | */ |
||
78 | 1 | public function setQuery($query) |
|
82 | |||
83 | /** |
||
84 | * Returns the set query. |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | 1 | public function getQuery() |
|
92 | |||
93 | /** |
||
94 | * Sets the writer type and instantiates a writer. |
||
95 | * |
||
96 | * @param string $writer Name of writer to instantiate. |
||
97 | */ |
||
98 | 1 | public function setWriter(string $writer): void |
|
102 | |||
103 | /** |
||
104 | * Returns an instantiated writer object. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | 1 | public function getWriter(): string |
|
112 | |||
113 | /** |
||
114 | * Sets the source / type which the writer will use to generate artifacts from. |
||
115 | * |
||
116 | * @param string $source Free-form string with writer-specific meaning. |
||
117 | */ |
||
118 | 1 | public function setSource($source) |
|
122 | |||
123 | /** |
||
124 | * Returns the name of the source / type used in the transformation process. |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | 1 | public function getSource() |
|
132 | |||
133 | /** |
||
134 | * Returns the source as a path instead of a regular value. |
||
135 | * |
||
136 | * This method applies the following rules to the value of $source: |
||
137 | * |
||
138 | * 1. if the template_path parameter is set and that combined with the |
||
139 | * source gives an existing file; return that. |
||
140 | * 2. if the value exists as a file (either relative to the current working |
||
141 | * directory or absolute), do a realpath and return it. |
||
142 | * 3. Otherwise prepend it with the phpDocumentor data folder, if that does |
||
143 | * not exist: throw an exception |
||
144 | * |
||
145 | * @throws Exception if no valid file could be found. |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | public function getSourceAsPath(): string |
||
193 | |||
194 | /** |
||
195 | * Filename of the resulting artifact relative to the root. |
||
196 | * |
||
197 | * If the query results in a set of artifacts (multiple nodes / array); |
||
198 | * then this string must contain an identifying variable as returned by the |
||
199 | * writer. |
||
200 | * |
||
201 | * @param string $artifact Name of artifact to generate; usually a filepath. |
||
202 | */ |
||
203 | 1 | public function setArtifact($artifact) |
|
207 | |||
208 | /** |
||
209 | * Returns the name of the artifact. |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | 1 | public function getArtifact() |
|
217 | |||
218 | /** |
||
219 | * Sets an array of parameters (key => value). |
||
220 | * |
||
221 | * @param Parameter[] $parameters Associative multidimensional array containing |
||
222 | * parameters for the Writer. |
||
223 | */ |
||
224 | 1 | public function setParameters(array $parameters) |
|
228 | |||
229 | /** |
||
230 | * Returns all parameters for this transformation. |
||
231 | * |
||
232 | * @return Parameter[] |
||
233 | */ |
||
234 | 1 | public function getParameters() |
|
238 | |||
239 | /** |
||
240 | * Returns a specific parameter, or $default if none exists. |
||
241 | * |
||
242 | * @param string $name Name of the parameter to return. |
||
243 | * |
||
244 | * @return Parameter|null |
||
245 | */ |
||
246 | 2 | public function getParameter($name): ?Parameter |
|
257 | |||
258 | /** |
||
259 | * Returns a specific parameter, or $default if none exists. |
||
260 | * |
||
261 | * @param string $name Name of the parameter to return. |
||
262 | * |
||
263 | * @return Parameter[] |
||
264 | */ |
||
265 | 2 | public function getParametersWithKey($name) |
|
278 | |||
279 | /** |
||
280 | * Sets the transformer on this transformation. |
||
281 | * |
||
282 | * @param \phpDocumentor\Transformer\Transformer $transformer |
||
283 | */ |
||
284 | 1 | public function setTransformer($transformer) |
|
288 | |||
289 | /** |
||
290 | * Returns the transformer for this transformation. |
||
291 | * |
||
292 | * @return \phpDocumentor\Transformer\Transformer |
||
293 | */ |
||
294 | 1 | public function getTransformer() |
|
298 | } |
||
299 |