Skip to content

Commit e42efd3

Browse files
committed
Reverted to original simpler Init.php
1 parent d5cbca5 commit e42efd3

17 files changed

+524
-672
lines changed

doc/00-Theme-Selection.md

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Theme Selection and Session Variable Handling in HCP Framework
2+
3+
## Overview
4+
This document explains the interaction between initialization variables, session handling, and theme selection in the HCP Framework, specifically focusing on how theme persistence is managed across page requests.
5+
6+
## Variable Flow and Initialization
7+
8+
### Initial State
9+
The global configuration object `$g` starts with default values:
10+
```php
11+
public $in = [
12+
't' => 'Basic', // Default theme
13+
'o' => 'Home', // Default content object
14+
'm' => 'list', // Default method
15+
// ... other defaults
16+
];
17+
```
18+
19+
### Request Processing
20+
1. In `Init::__construct()`, the following sequence occurs:
21+
```php
22+
// Sanitize input values
23+
$g->in = Util::esc($g->in);
24+
25+
// This processes each input var against $_REQUEST
26+
// If a matching $_REQUEST key exists, it overrides the default
27+
// If not, the default value remains
28+
```
29+
30+
### Session Handling
31+
The `Util::ses()` method manages session variable persistence:
32+
```php
33+
public static function ses(string $k, string $v = '', ?string $x = null): string
34+
{
35+
// k: session key
36+
// v: default value
37+
// x: override value (if provided)
38+
39+
return $_SESSION[$k] =
40+
(!is_null($x) && (!isset($_SESSION[$k]) || ($_SESSION[$k] != $x)))
41+
? $x
42+
: (((isset($_REQUEST[$k]) && !isset($_SESSION[$k]))
43+
|| (isset($_REQUEST[$k], $_SESSION[$k])
44+
&& ($_REQUEST[$k] != $_SESSION[$k])))
45+
? self::enc($_REQUEST[$k])
46+
: ($_SESSION[$k] ?? $v));
47+
}
48+
```
49+
50+
## Theme Selection Process
51+
52+
### Priority Order
53+
Theme selection follows this priority sequence:
54+
1. URL Parameter (`?t=ThemeName`)
55+
2. Existing Session Value
56+
3. Default Value (`Basic`)
57+
58+
### Selection Flow
59+
```php
60+
// In Init.php
61+
$t = Util::ses('t', $g->in['t']); // Correct usage for theme persistence
62+
63+
// This evaluates as:
64+
// 1. If t exists in $_REQUEST, use that value
65+
// 2. If t exists in $_SESSION, use that value
66+
// 3. Otherwise, fall back to $g->in['t'] (usually 'Basic')
67+
```
68+
69+
### Theme Class Resolution
70+
After theme selection:
71+
```php
72+
$t2 = "HCP\\Themes\\$t"; // Constructs theme class name
73+
if (class_exists($t2)) {
74+
$thm->themeImpl = new $t2($g); // Instantiates theme
75+
}
76+
```
77+
78+
## Example Scenarios
79+
80+
### First Visit (No Session)
81+
- Default: `$g->in['t'] = 'Basic'`
82+
- No session or URL parameters
83+
- Result: Basic theme used and stored in session
84+
85+
### Theme Change via URL
86+
- URL: `?t=TopNav`
87+
- Session updated to store 'TopNav'
88+
- Theme persists on subsequent pages
89+
90+
### Subsequent Visits
91+
- No URL parameter
92+
- Existing session value used
93+
- Default 'Basic' ignored if session exists
94+
95+
## Important Notes
96+
1. Session persistence relies on proper parameter ordering in `Util::ses()`
97+
2. URL parameters always override existing session values
98+
3. Default values only apply when no session or URL parameter exists
99+
4. Theme class must exist in `HCP\Themes` namespace
100+
5. Invalid theme names fall back to base Theme class
101+
102+
This implementation allows for dynamic theme switching while maintaining user preference across page loads through session persistence.
103+

doc/multi-inheritance-test.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
class Theme {
4+
public function hello() {
5+
error_log(__METHOD__);
6+
return "Theme says hello";
7+
}
8+
}
9+
10+
class Basic extends Theme {
11+
public function hello() {
12+
error_log(__METHOD__);
13+
return "Basic says: " . parent::hello(); // Can access Theme's hello
14+
}
15+
}
16+
17+
class TopNav extends Basic {
18+
public function hello() {
19+
error_log(__METHOD__);
20+
return "TopNav says: " . parent::hello() . "\n"; // Can access Basic's hello
21+
}
22+
}
23+
24+
$nav = new TopNav();
25+
echo $nav->hello();
26+
27+
// Output: "TopNav says: Basic says: Theme says hello"

public/index.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
use HCP\Init;
1212

13-
echo new Init(new class() {
13+
echo new Init(new class()
14+
{
1415
public $cfg = [
1516
'email' => 'admin@example.com',
1617
'admpw' => 'admin123',
@@ -30,7 +31,7 @@
3031
'm' => 'list', // Method (action)
3132
'o' => 'Home', // Object (content)
3233
'r' => 'local', // Remotes (local)
33-
't' => 'SideBar', // Theme (Default)
34+
't' => 'Basic', // Theme (Default)
3435
'x' => '', // XHR (request)
3536
];
3637

src/Config/AppConfig.php

-40
This file was deleted.

src/Http/Request.php

-61
This file was deleted.

src/Http/Response.php

-80
This file was deleted.

0 commit comments

Comments
 (0)