Initial commit
This commit is contained in:
6
src/Pages/Converter.php
Normal file
6
src/Pages/Converter.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php namespace WpsMcloud\Pages;
|
||||
|
||||
class Converter extends Page
|
||||
{
|
||||
|
||||
}
|
||||
55
src/Pages/Page.php
Normal file
55
src/Pages/Page.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php namespace WpsMcloud\Pages;
|
||||
|
||||
use WpsMcloud\Exceptions\ViewNotFoundException;
|
||||
|
||||
abstract class Page
|
||||
{
|
||||
private static string $viewsDir = 'views';
|
||||
|
||||
/**
|
||||
* @throws ViewNotFoundException
|
||||
*/
|
||||
public function render(): void
|
||||
{
|
||||
$this->renderView();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ViewNotFoundException
|
||||
*/
|
||||
private function renderView(): void
|
||||
{
|
||||
$lowerCaseLastPartThisClassName = strtolower(array_reverse(explode('\\', get_class($this)))[0]);
|
||||
|
||||
$filePathWithoutExtension = self::getViewsPath() . DIRECTORY_SEPARATOR .$lowerCaseLastPartThisClassName;
|
||||
|
||||
$allowedExtensions = [
|
||||
'html',
|
||||
'php'
|
||||
];
|
||||
|
||||
$fileIsFound = false;
|
||||
|
||||
while (!$fileIsFound && $currentExtension = current($allowedExtensions)) {
|
||||
if (file_exists($filePath = $filePathWithoutExtension . '.' . $currentExtension)) {
|
||||
$fileIsFound = true;
|
||||
|
||||
include $filePath;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$fileIsFound) {
|
||||
throw new ViewNotFoundException(sprintf(
|
||||
'Not found any view file in view dir "%s" for this controller "%s" with these available extension: %s',
|
||||
self::getViewsPath(),
|
||||
$lowerCaseLastPartThisClassName,
|
||||
implode(', ', $allowedExtensions)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private static function getViewsPath(): string
|
||||
{
|
||||
return WPSTUDIO_MEDIA_CLOUD_TRANFORM_BASE_PATH . DIRECTORY_SEPARATOR . self::$viewsDir;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user