HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: //var/www/html/inventory.breadsecret.com/class/Pages/Page.php
<?php
namespace Pages;

use Requests\Request;
use Responses\iResponse;
use Routing\Route;
use Utility\WebSystem;

class Page implements iResponse {
	private $view;
	private $vals;

	public function __construct(String $view, Array $vals = []) {
		$this->setView($view);
		$this->setValues($vals);
	}
	
	public function setView(String $view) {
		$this->view = $view;
		if (!$this->exists()) $this->view = '';
		return $this;
	}
	
	public function setValues(Array $vals = []) {
		if (is_null($this->vals)) $this->vals = $vals;
		else $this->vals = array_merge($this->vals, $vals);
		return $this;
	}
	
	public function emptyValues() {
		$this->vals = [];
		return $this;
	}
	
	public function viewName() { return $this->view; }
	
	public function viewFilePath() {
		return ((!empty(cfg()['viewPath']))?cfg()['viewPath']:'').$this->view.".php";
	}

	public function exists() {
		return file_exists($this->viewFilePath());
	}

	public function render() {
		$request = Request::get();
		foreach ($this->vals as $name => $vals) {
			${$name} = $vals;
		}
		if ($this->exists())
			include($this->viewFilePath());
	}
	
	public static function pagelink(string $pathName, Array $querystr = [], string $requestMethod = '') {
		return WebSystem::path(Route::getRouteByName($pathName, $requestMethod)->path($querystr), false, false);
	}
	
	// no use function
	/*
	public function add($view, $type = 'view') {
		if (property_exists('Page', $type)) {
			$this->$type[] = $view;
		}
	}
	*/
	
   public function display() {
      $this->render();
   }

   public function objArr() {
      return array('object'=>'page', 'view'=>$this->view, 'vals'=>$this->vals);
   }

   public function json() {
      return json_encode($this->objArr());
   }

   
}