Skip to content

Commit 2f97748

Browse files
author
alddesign
committed
Update
minor improvements
1 parent 2dc9489 commit 2f97748

File tree

10 files changed

+60
-57
lines changed

10 files changed

+60
-57
lines changed

app/views/index.view.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
Come and check out our <a href="<?php Helper::echoUrl("/Product/list") ?>">products</a>
2121

2222
<!-- You can also pass some data to a child view -->
23-
<?php View::createChild("html-footer", $this, ["footerText" => "Copyright by me..."])->render(); ?>
23+
<?php View::createChild("html-footer", $this, false, ["footerText" => "Copyright by me..."])->render(); ?>

app/views/product-list.view.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@
5252
</form>
5353
</table>
5454

55-
<?php View::createChild("html-footer", $this, ["footerText" => "Copyright by me..."])->render(); ?>
55+
<?php View::createChild("html-footer", $this, false, ["footerText" => "Copyright by me..."])->render(); ?>

assets/icon128.png

2.05 KB
Loading

assets/icon192.png

3.02 KB
Loading

assets/icon32.png

885 Bytes
Loading

assets/icon512.png

5.28 KB
Loading

assets/icon64.png

1.27 KB
Loading

system/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function get(string $key = "", $default = "")
6060
* @param string $key
6161
* @param string $default Default value if key is not found
6262
*
63-
* @return [type]
63+
* @return mixed
6464
*/
6565
public static function system(string $key = "", $default = "")
6666
{

system/Helper.php

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,97 +11,98 @@ abstract class Helper
1111
*
1212
* ```
1313
* //Example usage:
14-
* $something = ['cars' => ['audi','bmw'], 'nothing' => (object)['name' => 'Mario', 'age' => 34]];
15-
* Helper::xout($something);
14+
* Helper::xout(['cars' => ['audi','bmw'], 'nothing' => (object)['name' => 'Mario', 'age' => 34]]);
1615
* ```
1716
*
1817
* @param mixed $value The variable to print out
1918
* @param bool $dontDie Default = false. If set to true the script will not be aborted after execution of this function.
19+
* @return void
2020
*/
21-
public static function xout($value, bool $dontDie = false)
22-
{
23-
self::xoutInternal($value, $dontDie, true);
24-
}
25-
26-
/** @ignore */
27-
private static function xoutInternal($value, bool $dontDie, bool $initCall)
21+
public static function xout($value, bool $dontDie = false, bool $initCall = true)
2822
{
29-
$result = $initCall ? '<div id="xout-container" style="font-family: Courier New; font-weight: bold; font-size: 15px;">' : '';
30-
31-
if(gettype($value) === 'array')
32-
{
33-
$isSimpleVar = false;
34-
$result .= '<span>ARRAY</span><br />'.htmlspecialchars('[');
35-
$result .= '<ul style="list-style-type: none; margin: 0; padding: 0 0 0 20px;">';
36-
}
37-
if(gettype($value) === 'object')
23+
//You can define your own syntax coloring here.
24+
$baseColor = 'black';
25+
$objectClassColor = 'gray';
26+
$arrayTypeColor = 'blue';
27+
$objectTypeColor = 'blue';
28+
$stringTypeColor = 'red';
29+
$integerTypeColor = 'orange';
30+
$doubleTypeColor = 'teal';
31+
$resourceTypeColor = 'purple';
32+
$resourceClosedTypeColor = 'plum';
33+
$booleanTypeColor = 'green';
34+
$nullTypeColor = 'gray';
35+
36+
$result = $initCall ? '<div id="xout-container" style="font-family: Courier New; font-weight: bold; font-size: 15px; color:'.$baseColor.';">' : '';
37+
38+
$isSimpleVar = false;
39+
$valueType = gettype($value);
40+
switch($valueType)
3841
{
39-
$isSimpleVar = false;
40-
$result .= '<span>OBJECT</span> <span style="color:grey;">' . get_class($value) . '</span><br />'.htmlspecialchars('(');
41-
$result .= '<ul style="list-style-type: none; margin: 0; padding: 0 0 0 20px;">';
42+
case 'array' : $result .= '<span>ARRAY</span><br />'.htmlspecialchars('['); break;
43+
case 'object' : $result .= '<span>OBJECT</span> <span style="color:'.$objectClassColor.';">' . get_class($value) . '</span><br />'.htmlspecialchars('('); break;
44+
default : $value = [$value]; $isSimpleVar = true; break;
4245
}
43-
if(gettype($value) !== 'array' && gettype($value) !== 'object')
44-
{
45-
$isSimpleVar = true;
46-
$result .= '<ul style="list-style-type: none; margin: 0; padding: 0;">';
47-
$value = [$value];
48-
}
49-
46+
47+
$result .= '<ul style="list-style-type: none; margin: 0;">';
48+
5049
foreach ($value as $key => $val)
5150
{
52-
if (gettype($val) === 'array' || gettype($val) === 'object')
51+
$valType = gettype($val);
52+
if ($valType === 'array' || $valType === 'object')
5353
{
54-
if (gettype($val) === 'array')
54+
if ($valueType === 'array')
5555
{
56-
$result .= '<li><span style="color:blue;">[' . htmlspecialchars(strval($key)) . ']</span><b style="color:black;"> '.htmlspecialchars('=>').' </b><span>' . self::xoutInternal($val, $dontDie, false) . '</span></li>';
56+
$result .= '<li><span style="color:'.$arrayTypeColor.';">[' . htmlspecialchars(strval($key)) . ']</span><b style="color:'.$baseColor.';"> '.htmlspecialchars('=>').' </b><span>' . self::xout($val, $dontDie, false) . '</span></li>';
5757
}
58-
if (gettype($val) === 'object')
58+
if ($valueType === 'object')
5959
{
60-
$result .= '<li><span style="color:blue;">' . htmlspecialchars(strval($key)) . '</span><b style="color:black;"> '.htmlspecialchars('->').' </b><span>' . self::xoutInternal($val, $dontDie, false) . '</span></li>';
60+
$result .= '<li><span style="color:'.$objectTypeColor.';">' . htmlspecialchars(strval($key)) . '</span><b style="color:'.$baseColor.';"> '.htmlspecialchars('->').' </b><span>' . self::xout($val, $dontDie, false) . '</span></li>';
6161
}
6262
}
6363
else
6464
{
6565
$color = 'black';
66-
switch(gettype($val))
66+
switch($valType)
6767
{
68-
case 'string' : $color = 'red'; $val = htmlspecialchars('\'').$val.htmlspecialchars('\''); break;
69-
case 'integer' : $color = 'orange'; break;
70-
case 'double' : $color = 'teal'; break;
71-
case 'resource' : $color = 'black'; break;
72-
case 'boolean' : $color = 'green'; $val = ($val === true) ? 'TRUE' : 'FALSE'; break;
73-
case 'NULL' : $color = 'grey'; $val = 'NULL'; break;
68+
case 'string' : $color = $stringTypeColor; $val = htmlspecialchars('\'').$val.htmlspecialchars('\''); break;
69+
case 'integer' : $color = $integerTypeColor; $val = strval($val); break;
70+
case 'double' : $color = $doubleTypeColor; $val = strval($val); break;
71+
case 'resource' : $color = $resourceTypeColor; $val = 'resource ('.get_resource_type($val).')'; break;
72+
case 'resource (closed)' : $color = $resourceClosedTypeColor; $val = 'resource (closed)'; break;
73+
case 'boolean' : $color = $booleanTypeColor; $val = ($val === true) ? 'TRUE' : 'FALSE'; break;
74+
case 'NULL' : $color = $nullTypeColor; $val = 'NULL'; break;
7475
}
75-
76+
7677
$result .= '<li>';
7778
if(!$isSimpleVar)
7879
{
79-
if(gettype($value) === 'array')
80+
if($valueType === 'array')
8081
{
81-
$result .= '<span style="color:blue;">[' . htmlspecialchars(strval($key)) . ']</span><b style="color:black;"> '.htmlspecialchars('=>').' </b>';
82+
$result .= '<span style="color:'.$arrayTypeColor.';">[' . htmlspecialchars(strval($key)) . ']</span><b style="color:'.$baseColor.';"> '.htmlspecialchars('=>').' </b>';
8283
}
83-
if(gettype($value) === 'object')
84+
if($valueType === 'object')
8485
{
85-
$result .= '<span style="color:blue;">' . htmlspecialchars(strval($key)) . '</span><b style="color:black;"> '.htmlspecialchars('->').' </b>';
86+
$result .= '<span style="color:'.$objectTypeColor.';">' . htmlspecialchars(strval($key)) . '</span><b style="color:'.$baseColor.';"> '.htmlspecialchars('->').' </b>';
8687
}
8788
}
88-
$result .= '<span style="color:'.$color.';">' . htmlspecialchars(strval($val)) . '</span></li>';
89+
$result .= '<span style="color:'.$color.';">' . htmlspecialchars($val) . '</span></li>';
8990
}
9091
}
91-
92+
9293
$result .= '</ul>';
93-
94+
9495
if(!$isSimpleVar)
9596
{
96-
switch(gettype($value))
97+
switch($valueType)
9798
{
9899
case 'array' : $result .= htmlspecialchars(']'); break;
99100
case 'object' : $result .= htmlspecialchars(')'); break;
100101
}
101102
}
102-
103+
103104
$result .= $initCall ? '</div>' : '';
104-
105+
105106
if($initCall) //Finished
106107
{
107108
echo($result);

system/View.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ public static function createRoot(string $name, array $data = [])
7171
/**
7272
* Creates a child view. Child views can be included into a root view or even other child views.
7373
* @param string $name
74-
* @param View The view in which this child view is included
75-
* @param array $data
74+
* @param View $parentView The view in which this child view is included
75+
* @param bool $inheritData (optional) inherit data from the parent view
76+
* @param array $data (optionl) specifiy your own array of data
7677
*
7778
* @return View
7879
*/
79-
public static function createChild(string $name, $parentView, array $data = [])
80+
public static function createChild(string $name, View $parentView, bool $inheritData = true, array $data = [])
8081
{
82+
$data = $inheritData ? $parentView->data : $data;
8183
$view = new View($name, $data);
8284

8385
$view->isRootView = false;

0 commit comments

Comments
 (0)