Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UPD]Update view extension required #199

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading