Skip to content

Commit c73e19f

Browse files
author
alddesign
committed
Update PHPDoc of /system
1 parent ad426a1 commit c73e19f

File tree

8 files changed

+151
-18
lines changed

8 files changed

+151
-18
lines changed

app/config/app.config.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@
66
*/
77
$GLOBALS["_EZMVC_APP_CONFIG"] = //Do not rename this key
88
[
9-
"title" => "Welcome to EZ-MVC."
9+
"title" => "Welcome to EZ-MVC.",
10+
"captions" =>
11+
[
12+
"id" => "ID",
13+
"price" => 'Price [$]',
14+
"name" => "Name"
15+
]
1016
];

app/sample-database.sqlite

0 Bytes
Binary file not shown.

app/views/product-list.view.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
<table>
1515
<tr>
16-
<th>id</th>
17-
<th>name</th>
18-
<th>price</th>
16+
<th><?php echo Config::get("captions.id"); ?></th>
17+
<th><?php echo Config::get("captions.name"); ?></th>
18+
<th><?php echo Config::get("captions.price"); ?></th>
1919
<th> </th>
2020
<th> </th>
2121
</tr>
@@ -29,7 +29,7 @@
2929
<tr>
3030
<td><?php echo $id; ?></td>
3131
<td><?php echo $product["name"]; ?></td>
32-
<td><?php echo $product["price"]; ?>$</td>
32+
<td><?php echo $product["price"]; ?></td>
3333
<?php if($product["active"] === "1"): ?>
3434
<td><span style="color: green;">active</span></td>
3535
<td><a href="<?php echo $deactivateUrl ?>">deactivate product</a></td>

system/Config.php

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44

55
abstract class Config
66
{
7+
8+
/**
9+
* Loads a value from the app.config.php. You can access the config via the dot syntax (separating keys with a ".")
10+
*
11+
* ```php
12+
* //Example
13+
* Config::get("captions.price");
14+
* Config::get("captions")["price"];
15+
* ```
16+
* @param string $key
17+
* @param string $default Default value if key is not found
18+
*
19+
* @return mixed
20+
*/
721
public static function get(string $key = "", $default = "")
822
{
923
global $_EZMVC_APP_CONFIG;
@@ -19,9 +33,35 @@ public static function get(string $key = "", $default = "")
1933
return $_EZMVC_APP_CONFIG;
2034
}
2135

22-
return isset($_EZMVC_APP_CONFIG[$key]) ? $_EZMVC_APP_CONFIG[$key] : $default;
36+
//Try key as literal
37+
if(isset($_EZMVC_APP_CONFIG[$key]))
38+
{
39+
return $_EZMVC_APP_CONFIG[$key];
40+
}
41+
42+
//Try the dot syntax
43+
$keys = explode('.', $key);
44+
$value = $_EZMVC_APP_CONFIG;
45+
foreach($keys as $k)
46+
{
47+
if(!isset($value[$k]))
48+
{
49+
return $default;
50+
}
51+
$value = $value[$k];
52+
}
53+
54+
return $value;
2355
}
2456

57+
/**
58+
* Loads a value from the ez-mvc system.config.php. Works the same way as Config::get()
59+
*
60+
* @param string $key
61+
* @param string $default Default value if key is not found
62+
*
63+
* @return [type]
64+
*/
2565
public static function system(string $key = "", $default = "")
2666
{
2767
global $_EZMVC_SYS_CONFIG;
@@ -37,10 +77,28 @@ public static function system(string $key = "", $default = "")
3777
return $_EZMVC_SYS_CONFIG;
3878
}
3979

40-
return isset($_EZMVC_SYS_CONFIG[$key]) ? $_EZMVC_SYS_CONFIG[$key] : $default;
80+
//Try key as literal
81+
if(isset($_EZMVC_SYS_CONFIG[$key]))
82+
{
83+
return $_EZMVC_SYS_CONFIG[$key];
84+
}
85+
86+
//Try the dot syntax
87+
$keys = explode('.', $key);
88+
$value = $_EZMVC_SYS_CONFIG;
89+
foreach($keys as $k)
90+
{
91+
if(!isset($value[$k]))
92+
{
93+
return $default;
94+
}
95+
$value = $value[$k];
96+
}
97+
98+
return $value;
4199
}
42100

43-
public static function load()
101+
private static function load()
44102
{
45103
require __DIR__ . '/system.config.php';
46104
require dirname(__DIR__) . '/app/config/app.config.php';

system/Controller.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
declare(strict_types = 1);
33
namespace Alddesign\EzMvc\System;
44

5+
/**
6+
* Controller base class. Controller classes have to extend it. Tbh it doesnt do much at this point...
7+
*/
58
abstract class Controller
69
{
710
protected static function isController()

system/Model.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use PDOQuery;
88
use PDOStatement;
99

10+
/**
11+
* The model handles the DB connetion
12+
*/
1013
abstract class Model
1114
{
1215
/** @var PDO */
@@ -47,19 +50,30 @@ private static function connect()
4750
self::$pdo->setAttribute(PDO::ATTR_ERRMODE, Config::system("db-error-mode", PDO::ERRMODE_SILENT));
4851
}
4952

50-
/** @return string */
51-
protected static function delimiter(string $value)
53+
/**
54+
* Encloses a value between the DB spcific field & table name delimiters.
55+
* @param string $value
56+
*
57+
* @return string
58+
*/
59+
protected static function delimit(string $value)
5260
{
5361
return sprintf('%s%s%s', self::$delimiters[0], $value, self::$delimiters[1]);
5462
}
5563

56-
/** @return array */
64+
/**
65+
* Returns the DB spcific field & table name delimiters.
66+
* @return string[]
67+
*/
5768
protected static function getDelimiters()
5869
{
5970
return self::$delimiters;
6071
}
6172

62-
/** @return PDO */
73+
/**
74+
* Connets to the DB and returns the PDO object.
75+
* @return PDO
76+
*/
6377
protected static function getPdo()
6478
{
6579
if(self::$pdo === null)
@@ -70,6 +84,13 @@ protected static function getPdo()
7084
return self::$pdo;
7185
}
7286

87+
/**
88+
* Formats the PDO errorInfo array as readable text.
89+
*
90+
* @param array $errorInfo
91+
*
92+
* @return string
93+
*/
7394
protected static function formatErrorInfo(array $errorInfo)
7495
{
7596
if($errorInfo[0] === "00000")

system/Router.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ abstract class Router
1616
private static $params = [];
1717
private const CONTROLLER_NAMESPACE = 'Alddesign\\EzMvc\\Controllers\\';
1818

19+
20+
/**
21+
* Resolves the request url and call the corrsponding Controller Action.
22+
*
23+
* @return void
24+
*/
1925
public static function routeRequest()
2026
{
2127
self::resolveRequestUrl();
@@ -40,7 +46,9 @@ public static function routeRequest()
4046
}
4147

4248
/**
43-
* Resolves request url into $action, $id and $params.
49+
* Splits request url into $action, $id and $params.
50+
*
51+
* @return void
4452
*/
4553
private static function resolveRequestUrl()
4654
{
@@ -50,7 +58,7 @@ private static function resolveRequestUrl()
5058
self::$originalRequestUrl = $urlPath;
5159

5260
//Base Url:
53-
$baseUrl = parse_url(Helper::addTrailingSlash(Config::system("base-url")));
61+
$baseUrl = parse_url(Helper::addTrailingSlash((string)Config::system("base-url")));
5462
$baseUrlPath = isset($baseUrl["path"]) ? $baseUrl["path"] : "/";
5563

5664
//Strip base url path from request url path:

system/View.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Exception;
66

7+
/**
8+
* View are used to display data.
9+
*/
710
class View
811
{
912
/** @var bool */
@@ -19,6 +22,12 @@ class View
1922

2023
private const VIEWPATH = __DIR__."/../app/views/";
2124

25+
/**
26+
* Creates a new View
27+
*
28+
* @param string $name
29+
* @param array $data
30+
*/
2231
private function __construct(string $name, array $data = [])
2332
{
2433
if(!is_string($name) || !preg_match('/^[a-zA-Z0-9_-]+$/', $name))
@@ -40,7 +49,13 @@ private function __construct(string $name, array $data = [])
4049
$this->data = $data;
4150
}
4251

43-
/** @return \EzMvc\View */
52+
/**
53+
* Creates a root view. A root can have subsidiary "child views". So the root view is the very "inner" part of a page, while child views are outer parts like a header, footer, menu...
54+
* @param string $name
55+
* @param array $data
56+
*
57+
* @return View
58+
*/
4459
public static function createRoot(string $name, array $data = [])
4560
{
4661
$view = new View($name, $data);
@@ -53,7 +68,14 @@ public static function createRoot(string $name, array $data = [])
5368
return $view;
5469
}
5570

56-
/** @return \EzMvc\View */
71+
/**
72+
* Creates a child view. Child views can be included into a root view or even other child views.
73+
* @param string $name
74+
* @param View The view in which this child view is included
75+
* @param array $data
76+
*
77+
* @return View
78+
*/
5779
public static function createChild(string $name, $parentView, array $data = [])
5880
{
5981
$view = new View($name, $data);
@@ -66,13 +88,23 @@ public static function createChild(string $name, $parentView, array $data = [])
6688
return $view;
6789
}
6890

69-
/** @return \EzMvc\View */
91+
/**
92+
* Returns the root view for a child view.
93+
*
94+
* @return View
95+
*/
7096
public function getRootView()
7197
{
7298
return $this->parentViews[0];
7399
}
74100

75-
/** @return \EzMvc\View */
101+
/**
102+
* Returns the parent view for this child view. This can be the root view or other child views in the hierachy.
103+
*
104+
* @param int $level Specifiy this level to get a parent view based on the hierarchy of your root + child views. 0 = direct parent, 1 = parent of parent,...
105+
*
106+
* @return View
107+
*/
76108
public function getParentView(int $level = 0)
77109
{
78110
$c = count($this->parentViews) - 1;
@@ -81,6 +113,11 @@ public function getParentView(int $level = 0)
81113
return $this->parentViews[$c - $level];
82114
}
83115

116+
/**
117+
* Echos this view to the browser.
118+
*
119+
* @return void
120+
*/
84121
public function render()
85122
{
86123
extract($this->data);

0 commit comments

Comments
 (0)