Skip to content

Commit 70b77cd

Browse files
committed
Alpha Development
1 parent f19ddff commit 70b77cd

File tree

249 files changed

+651
-37286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+651
-37286
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"email": "[email protected]"
88
}
99
],
10-
"require": {
10+
"require-dev": {
1111
"smarty/smarty": "v3.1.31"
1212
},
1313
"autoload": {

composer.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Auth.php

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
<?php
2-
3-
namespace Mvc;
4-
5-
use Mvc\Controllers\AuthController;
6-
7-
class Auth extends Foundation {
8-
9-
public static function login($referer = null, $area = null) {
10-
Cookie::instance()->referer = $referer;
11-
Cookie::instance()->area = $area;
12-
13-
header("location : /auth/login");
14-
}
15-
16-
public static function logout($area = null) {
17-
$auth = Cookie::instance()->auth;
18-
unset($auth[$area]);
19-
print_pre($auth);
20-
Cookie::instance()->auth = $auth;
21-
}
22-
23-
}
1+
<?php
2+
3+
namespace Mvc;
4+
5+
class Auth {
6+
7+
public static function login($referer = null, $area = null) {
8+
Cookie::instance()->referer = $referer;
9+
Cookie::instance()->area = $area;
10+
11+
header("location : /auth/login");
12+
}
13+
14+
public static function logout($area = null) {
15+
$auth = Cookie::instance()->auth;
16+
unset($auth[$area]);
17+
print_pre($auth);
18+
Cookie::instance()->auth = $auth;
19+
}
20+
21+
}

src/Context.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44

55
class Context extends Foundation {
66

7+
public $search_sequence_controllers_namespaces = [];
8+
public $search_sequence_templates = [];
9+
710
}

src/Controller.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
namespace Mvc;
44

5+
use Mvc\Controllers\AuthController;
6+
57
abstract class Controller extends Foundation {
68

79
protected $alerts = [];
810
protected $view;
911
protected $theme;
1012
protected $route;
1113
protected $cookie;
14+
protected $layout = 'layout';
1215
private static $rendered = [];
1316
protected $media;
1417
protected $breadcrumbs = [];
@@ -67,16 +70,10 @@ public function alert($type = 'info', $title = 'Info', $message = '') {
6770
public static function execute($route) {
6871

6972
//posible controllers namespace defination to purpose the search
70-
$search_path = [
71-
Context::instance()->setup['namespace'] . '\\Controllers', //search with App\Controllers
72-
Context::instance()->setup['namespace'], // search with App\
73-
'Mvc\\Controllers', //search with Mvc\Controllers
74-
'' //search directly without namespace
75-
];
76-
77-
$success = false;
7873

79-
foreach ($search_path as $namespace) {
74+
$namespaces = array_merge(array("\\" . Context::instance()->setup['namespace'] . "\\Controllers"), array_reverse(Context::instance()->search_sequence_controllers_namespaces));
75+
$success = false;
76+
foreach ($namespaces as $namespace) {
8077

8178
$controller = $namespace . '\\' . ucwords($route['controller']) . "Controller";
8279
//print_pre($controller);
@@ -186,15 +183,15 @@ public function view($template = null) {
186183
echo $this->render($template);
187184
}
188185

189-
public function viewLayout($template = null) {
186+
public function viewLayout($template = null, $layout = null) {
190187
Cookie::instance()->save();
191-
echo $this->renderLayout($template);
188+
echo $this->renderLayout($template, $layout);
192189
}
193190

194-
public function renderLayout($template = null) {
191+
public function renderLayout($template = null, $layout = null) {
195192
$output = '';
196193

197-
$layout = 'layout';
194+
$layout = !$layout ? $this->layout : $layout;
198195

199196
$this->view->HEADER_HTML = $this->header();
200197
$this->view->FOOTER_HTML = $this->footer();
@@ -290,10 +287,9 @@ public function logout($area = 'admin') {
290287
public static function getControllers($path) {
291288
$files = [];
292289
$files = array_merge($files, array_filter(rdir($path), function($a) {
293-
print_pre($a['dir'] . DS . $a['name']);
294-
return preg_match_all('/\\\\controllers\\\\(.*)Controller/', $a['dir'] . DS . $a['name']) > 0;
290+
return preg_match_all('/\\\\controllers\\\\(.*)Controller\.php/', $a['dir'] . DS . $a['name']) > 0;
295291
}));
296-
print_pre($files);
292+
return $files;
297293
}
298294

299295
}

src/Media.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77

88
class MediaTypes {
99

10-
const JS = 'js';
11-
const CSS = 'css';
10+
const JS = 'js';
11+
const CSS = 'css';
1212

1313
}
1414

1515
class Media extends Foundation {
1616

1717
private $media_files = [];
18-
private $scope = '';
18+
private $scope = '';
1919

2020
public function __construct($scope = '') {
21-
$this->media_files['js'] = [];
22-
$this->media_files['css'] = [];
23-
$this->scope = $scope;
21+
$this->media_files['js'] = [];
22+
$this->media_files['css'] = [];
23+
$this->scope = $scope;
2424
}
2525

2626
private function addMedia($type, $media, $validate = true, $module = '') {
@@ -33,15 +33,15 @@ private function addMedia($type, $media, $validate = true, $module = '') {
3333
}
3434

3535
if ($media != $media_path) {
36-
$validate = false;
37-
$media_path = "/media/$type/$media.$type";
36+
$validate = false;
37+
$media_path = "/media/$type/$media.$type";
3838
}
3939

4040

4141

4242
if (($validate && realpath(ROOT . $media_path)) || !$validate) {
43-
$this->media_files[$type][] = $media_path;
44-
$this->media_files[$type] = array_unique($this->media_files[$type]);
43+
$this->media_files[$type][] = $media_path;
44+
$this->media_files[$type] = array_unique($this->media_files[$type]);
4545
}
4646

4747
//print_pre($this->media_files);
@@ -60,8 +60,8 @@ public function addCss($media, $validate = true, $module = '') {
6060

6161
private function renderMedia($type) {
6262
$media_template = [
63-
'js' => JS_TEMPLATE
64-
, 'css' => CSS_TEMPLATE
63+
'js' => JS_TEMPLATE
64+
, 'css' => CSS_TEMPLATE
6565
];
6666

6767
$html = '';
@@ -91,12 +91,12 @@ private function getMedia($type, $file, $module = '') {
9191
return $file;
9292

9393

94-
$search_paths = array();
95-
$search_paths[] = $file;
96-
$search_paths[] = $theme->getCurrentThemePath() . '' . $type . '/' . $file;
97-
$search_paths[] = $theme->getDefaultThemePath() . '' . $type . '/' . $file;
98-
$search_paths[] = MVC_DEFAULT_MEDIA . '' . $type . DS . $file;
99-
$search_paths[] = ROOT . Context::instance()->setup['modules_path'] . $module . DS . $type . DS . $file;
94+
$search_paths = array();
95+
$search_paths[] = $file;
96+
$search_paths[] = $theme->getCurrentThemePath() . '' . $type . '/' . $file;
97+
$search_paths[] = $theme->getDefaultThemePath() . '' . $type . '/' . $file;
98+
$search_paths[] = MVC_MEDIA . '' . $type . DS . $file;
99+
$search_paths[] = ROOT . Context::instance()->setup['modules_path'] . $module . DS . $type . DS . $file;
100100

101101
foreach ($search_paths as $path) {
102102

src/SmartyViewWidgets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function register($smarty) {
1010

1111
$this->smarty = $smarty;
1212
$theme = Theme::instance();
13-
$files = array_merge(rdir($theme->getCurrentThemePath()), rdir(MVC_DEFAULT_TEMPLATES));
13+
$files = array_merge(rdir($theme->getCurrentThemePath()), rdir(MVC_TEMPLATES));
1414

1515
$files = array_filter($files, function($item) {
1616
$matches = [];

src/Theme.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,15 @@ public function getDefaultThemePath($pNeedLogicalPath = false) {
3131
}
3232

3333
public function getTemplate($file, $throw_exception = true) {
34-
$search_paths = [];
35-
$search_paths[] = $file;
36-
$search_paths[] = $file . '.html';
34+
$search_paths = [$file, $this->getCurrentThemePath() . $file, $this->getDefaultThemePath() . $file];
35+
foreach (array_reverse(Context::instance()->search_sequence_templates) as $search_sequence) {
36+
$search_paths[] = $search_sequence . $file;
37+
}
3738

38-
foreach ($search_paths as $path) {
39+
print_pre($search_paths);
3940

40-
$this_path = realpath($path);
41-
$mvc_path = realpath(MVC_DEFAULT_TEMPLATES . $path);
42-
$full_path_default = realpath(Context::instance()->theme->getDefaultThemePath() . $path);
43-
$full_path = realpath(Context::instance()->theme->getCurrentThemePath() . $path);
44-
45-
if ($this_path && file_exists($this_path))
46-
return $this_path;
47-
else if ($full_path && file_exists($full_path))
48-
return $full_path;
49-
else if ($full_path_default && file_exists($full_path_default))
50-
return $full_path_default;
51-
else if ($mvc_path && file_exists($mvc_path))
52-
return $mvc_path;
41+
foreach ($search_paths as $path) {
42+
print_pre([file_exists($path . MVC_TEMPLATES_EXT), $path . MVC_TEMPLATES_EXT]);
5343
}
5444

5545
if ($throw_exception)

src/bootstrap.php

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,13 @@
99
SmartyView
1010
};
1111

12-
if (!defined('DS'))
13-
define('DS', DIRECTORY_SEPARATOR);
14-
15-
if (!defined('ROOT'))
16-
define('ROOT', realpath($_SERVER['DOCUMENT_ROOT']) . DS);
17-
18-
if (!defined('MVC_ROOT')) {
19-
define('MVC_ROOT', __DIR__);
20-
}
21-
22-
if (!defined('MVC_DEFAULT_TEMPLATES')) {
23-
define('MVC_DEFAULT_TEMPLATES', MVC_ROOT . DS . 'Templates' . DS);
24-
}
25-
26-
if (!defined('MVC_DEFAULT_MEDIA')) {
27-
define('MVC_DEFAULT_MEDIA', MVC_ROOT . DS . 'Media' . DS);
28-
}
29-
30-
if (!defined('DEBUG'))
31-
define('DEBUG', 1);
32-
3312
error_reporting(0);
3413

35-
3614
register_shutdown_function(function() {
3715

3816
$e = error_get_last();
3917
if ($e)
40-
echo'<pre>ERROR<BR>' . $e['message'] . '<BR><BR>FILE<BR>' . $e['file'] . '(' . $e['line'] . ')</pre>';
18+
echo'<pre>ERROR<BR>' . $e['message'] . ' < BR><BR>FILE<BR>' . $e['file'] . ' ( ' . $e['line'] . ' ) </pre>';
4119
});
4220

4321
set_error_handler(function($errno, $errstr, $errfile, $errline, $class) {
@@ -74,6 +52,24 @@
7452
return true;
7553
});
7654

55+
56+
if (!defined('DS'))
57+
define('DS', DIRECTORY_SEPARATOR);
58+
59+
if (!defined('ROOT'))
60+
define('ROOT', realpath($_SERVER['DOCUMENT_ROOT']) . DS);
61+
/*
62+
define('MVC_ROOT', __DIR__ . DS);
63+
define('MVC_CONTROLERS', MVC_ROOT . 'controllers' . DS);
64+
define('MVC_TEMPLATES', MVC_ROOT . 'templates' . DS);
65+
define('MVC_MEDIA', MVC_ROOT . 'media' . DS);
66+
67+
define('MVC_TEMPLATES_EXT', '.html');
68+
69+
70+
if (!defined('DEBUG'))
71+
define('DEBUG ', 1);
72+
*/
7773
require 'config_tools.php';
7874

7975
/**
@@ -88,18 +84,18 @@
8884
* @param 'default_theme' => 'default',
8985
* @param 'cookie_name' => 'your_choice_name',
9086
* @param 'routes' => '[
91-
* 'name' => 'routename',
92-
* 'pattern' => 'regex',
93-
* 'defaults' => [
94-
* controller =>''
95-
* action =>''
96-
* action_id =>''
97-
* module =>''
98-
* module_controller =>''
99-
* module_action =>''
100-
* module_action_id =>''
101-
* ],
102-
* ]',
87+
* 'name' => 'routename',
88+
* 'pattern' => 'regex',
89+
* 'defaults' => [
90+
* controller => ''
91+
* action => ''
92+
* action_id => ''
93+
* module => ''
94+
* module_controller => ''
95+
* module_action => ''
96+
* module_action_id => ''
97+
* ],
98+
* ]',
10399
*/
104100
function mvc_init($pSetup = []) {
105101

@@ -115,7 +111,7 @@ function mvc_init($pSetup = []) {
115111

116112
$pSetup = array_merge($default_setup, $pSetup);
117113

118-
foreach ($pSetup as $key => $value) {
114+
foreach ($pSetup as $key => $valu e) {
119115
if (strpos($key, 'path') > 0) {
120116
$path = $value;
121117
if (!file_exists(ROOT . $path)) {
@@ -138,16 +134,20 @@ function mvc_init($pSetup = []) {
138134
}
139135
}
140136

141-
142137
Context::instance()->setup = $pSetup;
143138

139+
Context::instance()->search_sequence_controllers_namespaces[] = '\\Mvc\\Controllers';
140+
Context::instance()->search_sequence_templates[] = MVC_TEMPLATES;
141+
144142
if (isset($pSetup['cookie_name'])) {
145143
Context::instance()->cookie = Cookie::instance($pSetup['cookie_name']);
146144
} else {
147145
Context::instance()->cookie = Cookie::instance();
148146
}
149147

150-
if ($pSetup['auto_dispatch'] && boolval($pSetup['auto_dispatch'])) {
148+
if ($pSetup['auto_dispatch'] && boolval($pSetup['auto_dispatch
149+
150+
'])) {
151151
Router::disptach();
152152
}
153153
}

0 commit comments

Comments
 (0)