simplify docblocks

580-view-class-steroids
fadrian06 1 day ago
parent 98e20c6ad1
commit f047d22fab

@ -16,37 +16,28 @@ use Exception;
*/ */
class View class View
{ {
/** Location of view templates. */ /** Location of view templates */
public string $path; public string $path;
/** File extension. */ /** File extension */
public string $extension = '.php'; public string $extension = '.php';
public bool $preserveVars = true; public bool $preserveVars = true;
/** /** @var array<string, mixed> View variables */
* View variables.
*
* @var array<string, mixed> $vars
*/
protected array $vars = []; protected array $vars = [];
/** Template file. */ /** Template file. */
private string $template; private string $template;
/** /** @param string $path Path to templates directory */
* Constructor.
*
* @param string $path Path to templates directory
*/
public function __construct(string $path = '.') public function __construct(string $path = '.')
{ {
$this->path = $path; $this->path = $path;
} }
/** /**
* Gets a template variable. * Gets a template variable
*
* @return mixed Variable value or `null` if doesn't exists * @return mixed Variable value or `null` if doesn't exists
*/ */
public function get(string $key) public function get(string $key)
@ -76,8 +67,7 @@ class View
} }
/** /**
* Checks if a template variable is set. * Checks if a template variable is set
*
* @return bool If key exists * @return bool If key exists
*/ */
public function has(string $key): bool public function has(string $key): bool
@ -86,8 +76,7 @@ class View
} }
/** /**
* Unsets a template variable. If no key is passed in, clear all variables. * Unsets a template variable. If no key is passed in, clear all variables
*
* @return $this * @return $this
*/ */
public function clear(?string $key = null): self public function clear(?string $key = null): self
@ -102,11 +91,9 @@ class View
} }
/** /**
* Renders a template. * Renders a template
*
* @param string $file Template file * @param string $file Template file
* @param ?array<string, mixed> $templateData Template data * @param ?array<string, mixed> $templateData Template data
*
* @throws Exception If template not found * @throws Exception If template not found
*/ */
public function render(string $file, ?array $templateData = null): void public function render(string $file, ?array $templateData = null): void
@ -132,11 +119,9 @@ class View
} }
/** /**
* Gets the output of a template. * Gets the output of a template
*
* @param string $file Template file * @param string $file Template file
* @param ?array<string, mixed> $data Template data * @param ?array<string, mixed> $data Template data
*
* @return string Output of template * @return string Output of template
*/ */
public function fetch(string $file, ?array $data = null): string public function fetch(string $file, ?array $data = null): string
@ -149,10 +134,8 @@ class View
} }
/** /**
* Checks if a template file exists. * Checks if a template file exists
*
* @param string $file Template file * @param string $file Template file
*
* @return bool Template file exists * @return bool Template file exists
*/ */
public function exists(string $file): bool public function exists(string $file): bool
@ -161,10 +144,8 @@ class View
} }
/** /**
* Gets the full path to a template file. * Gets the full path to a template file
*
* @param string $file Template file * @param string $file Template file
*
* @return string Template file location * @return string Template file location
*/ */
public function getTemplate(string $file): string public function getTemplate(string $file): string
@ -185,10 +166,8 @@ class View
} }
/** /**
* Displays escaped output. * Displays escaped output
*
* @param string $str String to escape * @param string $str String to escape
*
* @return string Escaped string * @return string Escaped string
*/ */
public function e(string $str): string public function e(string $str): string

Loading…
Cancel
Save