Skip to content

Commit 6191d4d

Browse files
committed
Add phpdocs
1 parent 6fc375f commit 6191d4d

File tree

1 file changed

+119
-6
lines changed

1 file changed

+119
-6
lines changed

src/View.php

Lines changed: 119 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public function __destruct()
7070
}
7171
}
7272

73+
/**
74+
* Tells whether it is able to throw exceptions in the destructor.
75+
*
76+
* @return bool
77+
*/
7378
public function isThrowExceptionsInDestructor() : bool
7479
{
7580
return $this->throwExceptionsInDestructor;
@@ -88,6 +93,13 @@ public function setThrowExceptionsInDestructor(bool $active = true) : static
8893
return $this;
8994
}
9095

96+
/**
97+
* Sets the base directory where the views files are located.
98+
*
99+
* @param string $baseDir
100+
*
101+
* @return static
102+
*/
91103
public function setBaseDir(string $baseDir) : static
92104
{
93105
$real = \realpath($baseDir);
@@ -98,23 +110,42 @@ public function setBaseDir(string $baseDir) : static
98110
return $this;
99111
}
100112

113+
/**
114+
* Get the base directory.
115+
*
116+
* @return string|null
117+
*/
101118
public function getBaseDir() : ?string
102119
{
103120
return $this->baseDir;
104121
}
105122

123+
/**
124+
* Set the extension of views files.
125+
*
126+
* @param string $extension
127+
*
128+
* @return static
129+
*/
106130
public function setExtension(string $extension) : static
107131
{
108132
$this->extension = '.' . \ltrim($extension, '.');
109133
return $this;
110134
}
111135

136+
/**
137+
* Get the extension of view files.
138+
*
139+
* @return string
140+
*/
112141
public function getExtension() : string
113142
{
114143
return $this->extension;
115144
}
116145

117146
/**
147+
* Set the name of a directory for layouts within the base directory.
148+
*
118149
* @param string $prefix
119150
*
120151
* @return static
@@ -126,6 +157,8 @@ public function setLayoutPrefix(string $prefix) : static
126157
}
127158

128159
/**
160+
* Get the name of the layouts directory.
161+
*
129162
* @return string
130163
*/
131164
public function getLayoutPrefix() : string
@@ -141,6 +174,8 @@ protected function makeDirectoryPrefix(string $prefix) : string
141174
}
142175

143176
/**
177+
* Set the name of a directory for includes within the base directory.
178+
*
144179
* @param string $prefix
145180
*
146181
* @return static
@@ -152,6 +187,8 @@ public function setIncludePrefix(string $prefix) : static
152187
}
153188

154189
/**
190+
* Get the name of the includes directory.
191+
*
155192
* @return string
156193
*/
157194
public function getIncludePrefix() : string
@@ -185,8 +222,11 @@ protected function getFilepath(string $view) : string
185222
}
186223

187224
/**
188-
* @param string $view
189-
* @param array<string,mixed> $data
225+
* Render a view file.
226+
*
227+
* @param string $view View path within the base directory
228+
* @param array<string,mixed> $data Data passed to the view. The array keys
229+
* will be variables
190230
*
191231
* @return string
192232
*/
@@ -234,6 +274,14 @@ protected function setDebugData(string $file, float $start, string $type) : stat
234274
return $this;
235275
}
236276

277+
/**
278+
* Extends a layout.
279+
*
280+
* @param string $layout The name of the file within the layouts directory
281+
* @param string|null $openBlock Optionally opens and closes this block automatically
282+
*
283+
* @return static
284+
*/
237285
public function extends(string $layout, ?string $openBlock = null) : static
238286
{
239287
$this->layout = $this->getLayoutPrefix() . $layout;
@@ -244,17 +292,38 @@ public function extends(string $layout, ?string $openBlock = null) : static
244292
return $this;
245293
}
246294

295+
/**
296+
* Extends a layout without prefix.
297+
*
298+
* @param string $layout The name of the file within the base directory
299+
*
300+
* @return static
301+
*/
247302
public function extendsWithoutPrefix(string $layout) : static
248303
{
249304
$this->layout = $layout;
250305
return $this;
251306
}
252307

308+
/**
309+
* Tells whether the current contents is inside a layout.
310+
*
311+
* @param string $layout
312+
*
313+
* @return bool
314+
*/
253315
public function inLayout(string $layout) : bool
254316
{
255317
return isset($this->layout) && $this->layout === $layout;
256318
}
257319

320+
/**
321+
* Open a block.
322+
*
323+
* @param string $name Block name
324+
*
325+
* @return static
326+
*/
258327
public function block(string $name) : static
259328
{
260329
$this->openBlocks[] = $name;
@@ -269,6 +338,11 @@ public function block(string $name) : static
269338
return $this;
270339
}
271340

341+
/**
342+
* Close an open block.
343+
*
344+
* @return static
345+
*/
272346
public function endBlock() : static
273347
{
274348
if (empty($this->openBlocks)) {
@@ -290,27 +364,60 @@ public function endBlock() : static
290364
return $this;
291365
}
292366

367+
/**
368+
* Render a block.
369+
*
370+
* @param string $name Block name
371+
*
372+
* @return string|null
373+
*/
293374
public function renderBlock(string $name) : ?string
294375
{
295376
return $this->blocks[$name] ?? null;
296377
}
297378

379+
/**
380+
* Remove a block.
381+
*
382+
* @param string $name Block name
383+
*
384+
* @return static
385+
*/
298386
public function removeBlock(string $name) : static
299387
{
300388
unset($this->blocks[$name]);
301389
return $this;
302390
}
303391

392+
/**
393+
* Tells whether a given block is set.
394+
*
395+
* @param string $name Block name
396+
*
397+
* @return bool
398+
*/
304399
public function hasBlock(string $name) : bool
305400
{
306401
return isset($this->blocks[$name]);
307402
}
308403

404+
/**
405+
* Tells whether the current content is inside a block.
406+
*
407+
* @param string $name Block name
408+
*
409+
* @return bool
410+
*/
309411
public function inBlock(string $name) : bool
310412
{
311413
return $this->currentBlock() === $name;
312414
}
313415

416+
/**
417+
* Tells the name of the current block.
418+
*
419+
* @return string|null
420+
*/
314421
public function currentBlock() : ?string
315422
{
316423
if ($this->openBlocks) {
@@ -320,8 +427,11 @@ public function currentBlock() : ?string
320427
}
321428

322429
/**
323-
* @param string $view
324-
* @param array<string,mixed> $data
430+
* Returns the contents of an include.
431+
*
432+
* @param string $view The path of the file within the includes directory
433+
* @param array<string,mixed> $data Data passed to the view. The array keys
434+
* will be variables
325435
*
326436
* @return string
327437
*/
@@ -343,8 +453,11 @@ protected function involveInclude(string $view, string $contents) : string
343453
}
344454

345455
/**
346-
* @param string $view
347-
* @param array<string,mixed> $data
456+
* Returns the contents of an include without prefix.
457+
*
458+
* @param string $view The path of the file within the base directory
459+
* @param array<string,mixed> $data Data passed to the view. The array keys
460+
* will be variables
348461
*
349462
* @return string
350463
*/

0 commit comments

Comments
 (0)