Skip to content

Commit 407dee7

Browse files
committed
initial
0 parents  commit 407dee7

File tree

18 files changed

+320
-0
lines changed

18 files changed

+320
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/*

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: vendor/bin/heroku-php-nginx -C src/nginx.conf public/

Readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Tipsy MVC Example
2+
3+
A Structured MVC example with auto inclusion of controllers and libraries
4+
5+
6+
#### Deploying on Heroku
7+
8+
[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
9+
10+
11+
See [Tipsy Documentation](https://github.com/arzynik/tipsy/wiki) for more information.

app.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "Tipsy MVC Example",
3+
"description": "A Structured MVC example with auto inclusion of libraries",
4+
"website": "http://tipsy.la",
5+
"repository": "https://github.com/arzynik/tipsy-mvc",
6+
"keywords": ["tipsy", "mvc", "framework"],
7+
"logo": "http://tipsy.la/images/cocktail.png"
8+
}

app/controllers/about/index.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
// an example showing dependency injection
4+
5+
namespace App\Controller;
6+
7+
class About extends \Tipsy\Controller {
8+
public function init() {
9+
// normaly this would go in your apps init or index file
10+
$this->tipsy()->service('User', ['class' => '\App\User']);
11+
12+
parent::init();
13+
14+
$this->inject(function($View, $Request, $Scope, $User) {
15+
// @todo: for some reason $Scope is not being bound correctly
16+
$View->scope()->about = $User->data($Request->loc(1));
17+
$View->display('about');
18+
});
19+
}
20+
}

app/controllers/api/user/index.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Controller\Api;
4+
5+
class User extends \App\Rest {
6+
public function init() {
7+
header('Content-Type: application/json');
8+
$user = new \App\User;
9+
echo json_encode($user->data());
10+
}
11+
}

app/controllers/home/index.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
// basic view display example
4+
5+
namespace App\Controller;
6+
7+
class Home extends \Tipsy\Controller {
8+
public function init() {
9+
$this->tipsy()->view()->display('home');
10+
}
11+
}

app/models/User.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace App;
4+
5+
class User extends \Tipsy\Model {
6+
public function data($name) {
7+
return ['name' => $name, 'age' => rand(1,50)];
8+
}
9+
}

app/tipsy.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
use Tipsy\Tipsy;
6+
7+
Tipsy::config('../config/*.ini');
8+
9+
Tipsy::router()
10+
->otherwise(function($Request) {
11+
12+
$find = function($page, &$controller, &$posiblePage) {
13+
14+
$pageClass = explode('/',$page);
15+
$controllers = __DIR__.'/../app/controllers/';
16+
17+
foreach ($pageClass as $posiblePage) {
18+
$posiblePages[] = $fullPageNext.'/'.$posiblePage.'.php';
19+
$posiblePages[] = $fullPageNext.'/'.$posiblePage.'/index.php';
20+
$fullPageNext .= '/'.$posiblePage;
21+
}
22+
$posiblePages = array_reverse($posiblePages);
23+
24+
foreach ($posiblePages as $posiblePage) {
25+
if (file_exists($controllers.$posiblePage)) {
26+
$controller = $controllers.$posiblePage;
27+
break;
28+
}
29+
}
30+
31+
return $controller;
32+
};
33+
34+
$find($Request->path(), $controller, $posiblePage);
35+
36+
if (!isset($controller) || !file_exists($controller)) {
37+
$find('home', $controller, $posiblePage);
38+
}
39+
40+
require_once $controller;
41+
42+
$possibleClass = explode('/', substr($posiblePage, 0, strpos($posiblePage, '.')));
43+
$fullPageNext = '\\App\\Controller';
44+
45+
foreach ($possibleClass as $class) {
46+
if (!$class) {
47+
continue;
48+
}
49+
50+
$fullPageNext .= '\\'.ucfirst($class);
51+
52+
if (class_exists($fullPageNext, false)) {
53+
$c = new $fullPageNext(['tipsy' => $this->tipsy()]);
54+
if (method_exists($fullPageNext, 'init')) {
55+
$c->init();
56+
}
57+
}
58+
}
59+
});
60+
61+
Tipsy::run();

app/view/about.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><?=$about['name']?> is <?=$about['age']?> years old.</p>

0 commit comments

Comments
 (0)