diff --git a/.gitignore b/.gitignore index ed70c79..90f3eb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /vendor/* +.idea +runtime/cache diff --git a/controllers/SiteController.php b/controllers/SiteController.php index 75f6273..7f5a9b3 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -32,11 +32,11 @@ public function actionTest() public function actionView() { - $cache = Sf::createObject('cache'); - $cache->set('111', '2222'); - $result = $cache->get('111'); - $cache->flush(); - var_dump($result);die; +// $cache = Sf::createObject('cache'); +// $cache->set('111', '2222'); +// $result = $cache->get('111'); +// $cache->flush(); +// var_dump($result);die; $this->render('site/view', ['body' => 'Test body information']); } diff --git a/src/base/Application.php b/src/base/Application.php index ab5da28..2abb75a 100644 --- a/src/base/Application.php +++ b/src/base/Application.php @@ -22,11 +22,12 @@ abstract class Application */ public function run() { - try { +// try { return $this->handleRequest(); - } catch (Exception $e) { - return $e; - } +// } catch (Exception $e) { +// var_dump($e); +// return $e; +// } } /** diff --git a/src/web/Controller.php b/src/web/Controller.php index 90746ad..ba69686 100644 --- a/src/web/Controller.php +++ b/src/web/Controller.php @@ -14,8 +14,24 @@ class Controller extends \sf\base\Controller */ public function render($view, $params = []) { + $file = '../views/' . $view . '.sf'; + $fileContent = file_get_contents($file); + $result = ''; + foreach (token_get_all($fileContent) as $token) { + if (is_array($token)) { + list($id, $content) = $token; + if ($id == T_INLINE_HTML) { + $content = preg_replace('/{{(.*)}}/', '', $content); + } + $result .= $content; + } else { + $result .= $token; + } + } + $generatedFile = '../runtime/cache/' . md5($file); + file_put_contents($generatedFile, $result); extract($params); - return require '../views/' . $view . '.php'; + require_once $generatedFile; } /** diff --git a/views/site/view.sf b/views/site/view.sf new file mode 100644 index 0000000..e90596e --- /dev/null +++ b/views/site/view.sf @@ -0,0 +1,14 @@ + + + + + {{ $title }} + + +

{{ $str }}

+

{{ $body }}

+ + \ No newline at end of file