Skip to content

Commit 621efcd

Browse files
committed
Merge branch 'development'
2 parents e42ebb5 + f8e477f commit 621efcd

23 files changed

Lines changed: 675 additions & 243 deletions

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wdalmut/simple-mvc",
33
"description": "A simple and full stack Push & Pull MVC framework.",
4-
"version":"0.1.0",
4+
"version":"0.1.1",
55
"type":"library",
66
"keywords":["mvc","framework","microframework","micro"],
77
"time":"2012-07-03",
@@ -21,7 +21,10 @@
2121
"php": ">=5.3.3"
2222
},
2323
"autoload": {
24-
"classmap": ["src/"]
24+
"classmap": [
25+
"src/",
26+
"exts/"
27+
]
2528
},
2629
"repositories": [
2730
{

examples/base/public/index.php

100644100755
File mode changed.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
{% block head %}
5+
<link rel="stylesheet" href="style.css" />
6+
<title>{% block title %}{% endblock %} - My Webpage</title>
7+
{% endblock %}
8+
</head>
9+
<body>
10+
<div id="content">{% block content %}{% endblock %}</div>
11+
<div id="footer">
12+
{% block footer %}
13+
&copy; Copyright 2012 by <a href="http://wdalmut.github.com/simple-mvc">Walter Dal Mut</a>.
14+
{% endblock %}
15+
</div>
16+
</body>
17+
</html>

examples/twig-integration/public/index.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
<?php
1+
<?php
22
require_once realpath(__DIR__ . '/../vendor/autoload.php');
3-
require_once realpath(__DIR__ . '/../library/SimpleTwigView.php');
3+
require_once realpath(__DIR__ . '/../../../exts/TwigView.php');
44

55
$app = new Application();
66

77
// By default but more clear
88
$app->setControllerPath(__DIR__ . '/../controllers');
99

1010
$app->bootstrap("view", function(){
11-
$view = new SimpleTwigView();
11+
$view = new TwigView();
12+
$view->addViewPath(realpath(__DIR__ . '/../layouts'));
1213
$view->addViewPath(realpath(__DIR__ . '/../views'));
1314
$view->setViewExt(".twig");
14-
$view->initTwig();
15-
15+
$view->initTwig(__DIR__ . '/../views/cache');
16+
1617
return $view;
1718
});
1819

examples/twig-integration/views/cache/.gitentry

Whitespace-only changes.
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
1-
<h1>{{ hello }}</h1>
2-
<p>{{ texts.para }}</p>
1+
{% extends "base.twig" %}
2+
3+
{% block title %}Index{% endblock %}
4+
{% block head %}
5+
{{ parent() }}
6+
<style type="text/css">
7+
.important { color: #336699; }
8+
</style>
9+
{% endblock %}
10+
{% block content %}
11+
<h1>Index</h1>
12+
<p class="important">
13+
Welcome to Twig example.
14+
</p>
15+
{% endblock %}

exts/HostnameRouter.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
class HostnameRouter extends Router
3+
{
4+
private $_hostname;
5+
6+
public function __construct($hostname)
7+
{
8+
$this->_hostname = $hostname;
9+
}
10+
11+
public function match(Request $request)
12+
{
13+
if ($request->getHostname() == $this->_hostname) {
14+
return parent::match($request, new Route());
15+
}
16+
17+
return false;
18+
}
19+
}

exts/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# simple-mvc Extensions
2+
3+
Just useful extensions
4+
5+
* HostnameRouter
6+
* A simple hostname router
7+
* StaticRouter
8+
* A simple static router
9+
* SimpleTwigView
10+
* A simple Twig integration
11+
12+

exts/StaticRouter.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
class StaticRouter extends Router
3+
{
4+
private $_action;
5+
private $_controller;
6+
private $_path;
7+
8+
public function __construct($path, $controller, $action)
9+
{
10+
$this->_path = $path;
11+
$this->_action = $action;
12+
$this->_controller = $controller;
13+
}
14+
15+
public function match(Request $request, $route = false)
16+
{
17+
if ($request->getUri() == $this->_path) {
18+
$static = new Route();
19+
$static->setControllerName($this->_controller);
20+
$static->setActionName($this->_action);
21+
$static->merge($route);
22+
23+
return parent::match($request, $static);
24+
}
25+
}
26+
}

examples/twig-integration/library/SimpleTwigView.php renamed to exts/TwigView.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
<?php
2-
class SimpleTwigView extends View
2+
class TwigView extends View
33
{
44
private $_twig;
5-
6-
public function initTwig()
5+
6+
public function initTwig($cache = false)
77
{
88
$loader = new Twig_Loader_Filesystem($this->getViewPaths());
9-
$this->_twig = new Twig_Environment($loader);
9+
10+
if ($cache) {
11+
$this->_twig = new Twig_Environment($loader, array(
12+
'cache' => $cache
13+
));
14+
} else {
15+
$this->_twig = new Twig_Environment($loader);
16+
}
1017
}
11-
18+
1219
public function render($filename, $data = false)
1320
{
1421
$template = $this->_twig->loadTemplate($filename);
15-
$data = (is_array($data)) ? array_merge($this->_getData(), $data) : $this->_getData();
16-
22+
$data = (is_array($data)) ? array_merge($this->_getData(), $data) : $this->_getData();
23+
1724
return $template->render($data);
1825
}
1926
}

0 commit comments

Comments
 (0)