Skip to content

Commit

Permalink
Merge pull request #199 from kivudesign/update_view_extension_required
Browse files Browse the repository at this point in the history
[UPD]Update view extension required
  • Loading branch information
bim-g authored Sep 21, 2024
2 parents 68c8e4c + 821f687 commit c5e019e
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 101 deletions.
8 changes: 4 additions & 4 deletions controller/indexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ public function __construct()
}

/**
* @return void
*
*/
function home()
function home(): void
{
$this->view->display('home');
}

/**
* @return void
*
*/
function changeLang()
function changeLang(): void
{
Session::put('lang', Input::get("lang"));
Redirect::to("/");
Expand Down
43 changes: 31 additions & 12 deletions src/Core/Views/Provider/Contract/ViewsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,55 @@

namespace Wepesi\Core\Views\Provider\Contract;

use Wepesi\Core\MetaData;

/**
*
* @template T
*/
interface ViewsContract
{
/**
* Setup new folder location for layout template
* @param string $folder_name
* @return mixed
* @var class-string<T> $folder_name
*/
public function setFolder(string $folder_name);
public function setFolder(string $folder_name): void;

/**
* render html content
* @param string $view
* @return mixed
* @var class-string<T> $view
*/
public function display(string $view);

/**
* @param string $variable
* @param mixed $value
* @return mixed
* assign variables data to be displayed on file_page
* @var class-string<T> $variable
* @var <T> $value
*/
public function assign(string $variable, $value);

/**
* List all data assigned before being displayed
* @return array
*/
public function getAssignData(): array;
}

/**
* Render html string text
* @var class-string<T> $html
*/
public function renderHTML(string $html): void;

/**
* @var class-string<T> $template
*/
public function setLayout(string $template): void;

/**
* provide layout content name
* @var class-string<T> $layout_name
*/
public function setLayoutContent(string $layout_name): void;

/**
* reset view to default configuration
*/
public function flush(): void;
}
78 changes: 67 additions & 11 deletions src/Core/Views/Provider/ViewBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,59 @@

namespace Wepesi\Core\Views\Provider;

use Wepesi\Core\Application;
use Wepesi\Core\Escape;
use Wepesi\Core\Views\Provider\Contract\ViewsContract;

class ViewBuilderProvider implements Contract\ViewsContract
/**
* @template T
* @template-implements ViewsContract<T>
*/
abstract class ViewBuilderProvider implements ViewsContract
{
/**
* @var T[]
*/
protected array $data = [];
/**
* $reset
* @var bool
*/
protected bool $reset = false;

/**
* @var string
*/
protected string $layout = '';
/**
* @var string
*/
protected string $layout_content = '';
/**
* @var string
*/
protected string $folder_name = '';

/**
* @param string $folder_name
* @return void
* @param class-string<T> $folder_name
*
*/
public function setFolder(string $folder_name)
public function setFolder(string $folder_name): void
{
$this->folder_name = Escape::addSlashes($folder_name);
}

/**
* @inheritDoc
*/
public function display(string $view)
{
// TODO: Implement display() method.
}

abstract public function display(string $view);
/**
* assign variables data to be displayed on file_page
*
* @param string $variable
* @param class-string<T> $variable
* @param $value
*/
public function assign(string $variable, $value)
public function assign(string $variable, $value): void
{
$this->data[$variable] = $value;
}
Expand All @@ -52,4 +70,42 @@ public function getAssignData(): array
{
return $this->data;
}

/**
* render html string text
* @param class-string<T> $html *
*/
public function renderHTML(string $html): void
{
print($html);
}

/**
* you should provide the extension of your file,
* in another case the file will be missing
* @param class-string<T> $template
*/
public function setLayout(string $template): void
{
$this->layout = Application::$ROOT_DIR . '/views' . $template;
}

/**
* @param class-string<T> $layout_name
*
*/
public function setLayoutContent(string $layout_name): void
{
$this->layout_content = $layout_name;
}

/**
* Reset view to default configuration *
*/
public function flush(): void
{
$this->reset = true;
$this->layout = '';
$this->folder_name = '';
}
}
Loading

0 comments on commit c5e019e

Please sign in to comment.