Skip to content

Commit d79a602

Browse files
Merge pull request #1 from technicalguru/1.0-dev
1.0-dev creation
2 parents 04e3807 + d929a7e commit d79a602

17 files changed

+214
-25
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"extra": {
3131
"branch-alias": {
32-
"dev-master": "main-dev"
32+
"dev-master": "1.0-dev"
3333
}
3434
}
3535
}

src/WebApp/BootstrapTheme/Grid.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace WebApp\BootstrapTheme;
4+
5+
class Grid extends \WebApp\Component\Div {
6+
7+
public function __construct($parent) {
8+
parent::__construct($parent);
9+
}
10+
11+
public function createRow() {
12+
return new GridRow($this);
13+
}
14+
}
15+
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace WebApp\BootstrapTheme;
4+
5+
class GridCell extends \WebApp\Component\Div {
6+
7+
protected $gridSizes;
8+
9+
public function __construct($parent, $content = NULL) {
10+
parent::__construct($parent, $content);
11+
$this->gridSizes = array();
12+
}
13+
14+
public function getGridSizes() {
15+
return $this->gridSizes;
16+
}
17+
18+
public function addSize($class, $span = 0) {
19+
$this->gridSizes[$class] = $span;
20+
return $this;
21+
}
22+
}
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace WebApp\BootstrapTheme;
4+
5+
class GridCellRenderer extends \WebApp\DefaultTheme\DivRenderer {
6+
7+
public function __construct($theme, $component) {
8+
parent::__construct($theme, $component);
9+
$sizes = $this->component->getGridSizes();
10+
if (count($sizes) > 0) {
11+
foreach ($sizes AS $class => $span) {
12+
if ($span > 0) {
13+
$this->addClass('col-'.$class.'-'.$span);
14+
} else {
15+
$this->addClass('col-'.$class);
16+
}
17+
}
18+
} else {
19+
$this->addClass('col');
20+
}
21+
}
22+
}
23+
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace WebApp\BootstrapTheme;
4+
5+
class GridRenderer extends \WebApp\DefaultTheme\DivRenderer {
6+
7+
public function __construct($theme, $component) {
8+
parent::__construct($theme, $component);
9+
$this->addClass('container');
10+
}
11+
}
12+

src/WebApp/BootstrapTheme/GridRow.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace WebApp\BootstrapTheme;
4+
5+
class GridRow extends \WebApp\Component\Div {
6+
7+
public function __construct($parent) {
8+
parent::__construct($parent);
9+
}
10+
11+
public function createCell($content = NULL) {
12+
return new GridCell($this, $content);
13+
}
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace WebApp\BootstrapTheme;
4+
5+
class GridRowRenderer extends \WebApp\DefaultTheme\DivRenderer {
6+
7+
public function __construct($theme, $component) {
8+
parent::__construct($theme, $component);
9+
$this->addClass('row');
10+
}
11+
}
12+

src/WebApp/BootstrapTheme/LoginPage.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ public function __construct($app) {
1212
}
1313

1414
public function getPublicMain() {
15-
$rc = new \WebApp\Component\Div($this);
16-
$rc->addClass('jumbotron');
17-
$rc->setStyle('margin-top', '1em');
18-
$title = new \WebApp\Component\Title($rc, 'login_title');
15+
$rc = new \WebApp\Component\MainContent($this);
16+
$panel = new \WebApp\Component\Div($rc);
17+
$panel->addClass('jumbotron');
18+
$title = new \WebApp\Component\Title($panel, 'login_title');
1919
$title->setStyle('margin-top', '0');
2020
$title->setStyle('margin-bottom', '0.5rem');
21-
$lead = new \WebApp\Component\Subtitle($rc, 'please_login');
22-
$rc->addChild('<hr class="my-4">');
23-
$rc->addChild($this->getMessages());
24-
$rc->addChild($this->getLoginForm());
21+
$lead = new \WebApp\Component\Subtitle($panel, 'please_login');
22+
$panel->addChild('<hr class="my-4">');
23+
$panel->addChild($this->getMessages());
24+
$panel->addChild($this->getLoginForm());
2525
return $rc;
2626
}
2727

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace WebApp\BootstrapTheme;
4+
5+
class MainContentRenderer extends \WebApp\DefaultTheme\DivRenderer {
6+
7+
public function __construct($theme, $component) {
8+
parent::__construct($theme, $component);
9+
$this->addClass('container-fluid');
10+
}
11+
}
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace WebApp\BootstrapTheme;
4+
5+
class SubtitleRenderer extends \WebApp\DefaultTheme\ContainerRenderer {
6+
7+
public function __construct($theme, $component) {
8+
parent::__construct($theme, $component, 'p');
9+
$this->addClass('lead');
10+
}
11+
}
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace WebApp\BootstrapTheme;
4+
5+
class TitleRenderer extends \WebApp\DefaultTheme\ContainerRenderer {
6+
7+
public function __construct($theme, $component) {
8+
parent::__construct($theme, $component, 'h1');
9+
$this->addClass('display-4');
10+
}
11+
}
12+

src/WebApp/Component/Image.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Image extends Component {
66

77
public function __construct($parent, $url, $title) {
88
parent::__construct($parent);
9-
$this->setAttribute('href', $url);
9+
$this->setAttribute('src', $url);
1010
$this->setAttribute('title', $title);
1111
}
1212

src/WebApp/Component/MainContent.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace WebApp\Component;
4+
5+
class MainContent extends Div {
6+
7+
public function __construct($parent, $child = NULL) {
8+
parent::__construct($parent, $child);
9+
$this->addClass('content-main');
10+
}
11+
12+
}
13+

src/WebApp/Layout.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ protected function renderLinks() {
5454
$files = $this->app->getCssFiles();
5555
if (!is_array($files)) $files = array($files);
5656
foreach ($files AS $file) {
57-
if (strpos($file, '://') === FALSE) {
58-
$rc .= '<link rel="stylesheet" href="'.Utils::getCssBaseUrl().'/'.$file.'" rel="stylesheet" type="text/css">';
59-
} else {
57+
//if (strpos($file, '://') === FALSE) {
58+
// $rc .= '<link rel="stylesheet" href="'.Utils::getCssBaseUrl().'/'.$file.'" rel="stylesheet" type="text/css">';
59+
//} else {
6060
$rc .= '<link rel="stylesheet" href="'.$file.'" rel="stylesheet" type="text/css">';
61-
}
61+
//}
6262
}
6363
return $rc;
6464
}

src/WebApp/Page/LoginPage.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public function getRequiredRight() {
2020
}
2121

2222
public function getPublicMain() {
23-
$rc = new \WebApp\Component\Div($this);
24-
$rc->addClass('container-fluid');
23+
$rc = new \WebApp\Component\MainContentContainer($this);
2524
new \WebApp\Component\Title($rc, 'login_title');
2625
$rc->addChild($this->getMessages());
2726
$rc->addChild($this->getLoginForm());

src/WebApp/Router.php

+47-7
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public function getPage() {
171171

172172
// Strip of the leading part
173173
$afterName = substr($pagePath, strlen($mapEntry));
174+
Log::debug($this->searchPageInNamespace($afterName, $name));
174175

175176
// Fix special cases such as empty start or trailing slash
176177
if ($afterName == '') $afterName .= '/index';
@@ -208,13 +209,7 @@ public function getPage() {
208209
}
209210
}
210211

211-
// Check whether the class exists
212-
if ($className != NULL) {
213-
if (substr($className, 0, 1) != '\\') $className = '\\'.$className;
214-
if (class_exists($className)) $page = new $className($this->app);
215-
}
216-
217-
return $page;
212+
return $this->createPageInstance($className);
218213
}
219214

220215
/** Returns the absolute path to a relative app path */
@@ -223,5 +218,50 @@ public function getAbsolutePath($relativePath) {
223218
return $request->webRoot.$request->relativeAppPath.$relativePath;
224219
}
225220

221+
protected function searchPageInNamespace($pagePath, $namespace) {
222+
// Fix special cases such as empty start or trailing slash
223+
if ($pagePath == '') $pagePath .= '/index';
224+
if (substr($pagePath, -1) == '/') $pagePath .= 'index';
225+
226+
// strip of the ending .html
227+
if (substr($pagePath, -5) == '.html') $pagePath = substr($pagePath, 0, strlen($pagePath)-5);
228+
229+
// split in parts and remove first part if it's empty
230+
$names = explode('/', $pagePath);
231+
if ($names[0] == '') array_shift($names);
232+
233+
// Replace special characters by whitespace and make it camel case and concatenate again
234+
$className = $name;
235+
foreach ($names AS $idx => $path) {
236+
if ($idx > 0) $className .= '\\';
237+
$path = str_replace(' ', '', ucwords(str_replace(array('_','-'), array(' ', ' '), $path)));
238+
$className .= ucfirst($path);
239+
}
240+
241+
// Make a bottom-2-top search for the class as long as you are in the namespace of the mapEntry
242+
$toSearch = '\\'.$className.'Page';
243+
while (!class_exists($toSearch) && (strpos($toSearch, $namespace) !== FALSE)) {
244+
// strip off from last backslash
245+
$toSearch = substr($toSearch, 0, strrpos($toSearch, '\\')).'Page';
246+
}
247+
if (class_exists($toSearch)) {
248+
$className = $toSearch;
249+
} else {
250+
$className .= 'Page';
251+
}
252+
Log::debug('Router::searchPageInNamespace(): '.$namespace.$className);
253+
return $namespace.$className;
254+
}
255+
256+
/** Returns the instance of the page or NULL if it doesnt exist */
257+
protected function createPageInstance($className) {
258+
$page = NULL;
259+
// Check whether the class exists
260+
if ($className != NULL) {
261+
if (substr($className, 0, 1) != '\\') $className = '\\'.$className;
262+
if (class_exists($className)) $page = new $className($this->app);
263+
}
264+
return $page;
265+
}
226266
}
227267

src/WebApp/Utils.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ public static function getCssBasePath($webapp = FALSE) {
4242
return self::getWebRootPath($webapp).'/css';
4343
}
4444

45-
public function getFontBaseUrl($webapp = FALSE) {
45+
public static function getFontBaseUrl($webapp = FALSE) {
4646
return self::getWebRootUrl($webapp).'/fonts';
4747
}
4848

49-
public function getFontBasePath($webapp = FALSE) {
49+
public static function getFontBasePath($webapp = FALSE) {
5050
return self::getWebRootPath($webapp).'/fonts';
5151
}
52+
5253
}
5354

0 commit comments

Comments
 (0)