Repository navigation
Expand file tree
/
Copy pathexample.php
More file actions
217 lines (195 loc) · 5.97 KB
/
Copy pathexample.php
File metadata and controls
217 lines (195 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* PhpSPA Highlighter - Example File
*
* This file demonstrates the syntax highlighting capabilities
* of the PhpSPA Highlighter plugin for Acode.
*
* Open this file in Acode with the plugin installed to see
* the embedded HTML, CSS, and JavaScript properly highlighted.
*/
namespace App\Components;
class Button {
/**
* Render button HTML with variable interpolation
*/
public function render($name, $id, $class = 'btn-primary') {
return (<<<HTML
<button
class="btn {$class}"
id="{$id}"
onclick="handleClick('{$id}')">
<span class="btn-icon">👋</span>
<span class="btn-text">Hello {$name}!</span>
</button>
HTML);
}
/**
* Button styles with variable interpolation
*/
public function styles($primaryColor = '#007bff', $hoverColor = '#0056b3') {
return <<<CSS
.btn {
padding: 10px 20px;
background: {$primaryColor};
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
gap: 8px;
}
.btn:hover {
background: {$hoverColor};
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.btn-icon {
font-size: 20px;
}
.btn-text {
font-weight: 500;
}
CSS;
}
/**
* Button JavaScript with variable interpolation
*/
public function script($buttonId) {
return <<<JS
function handleClick(buttonId) {
console.log('Button clicked:', buttonId);
const button = document.getElementById(buttonId);
if (button) {
button.classList.add('clicked');
setTimeout(() => {
button.classList.remove('clicked');
}, 300);
}
alert('You clicked the button: ' + buttonId);
}
// Initialize buttons
document.addEventListener('DOMContentLoaded', () => {
console.log('Initializing buttons...');
const buttons = document.querySelectorAll('.btn');
buttons.forEach(btn => {
console.log('Found button:', btn.id);
});
});
JS;
}
/**
* Using JAVASCRIPT identifier (alternative to JS)
*/
public function scriptAlt() {
return <<<JAVASCRIPT
const APP_CONFIG = {
version: '1.0.0',
debug: true,
apiUrl: 'https://api.example.com'
};
class ButtonManager {
constructor() {
this.buttons = new Map();
}
register(id, handler) {
this.buttons.set(id, handler);
console.log(`Registered button: ${id}`);
}
trigger(id) {
const handler = this.buttons.get(id);
if (handler) {
handler();
}
}
}
JAVASCRIPT;
}
}
class Modal {
/**
* Nowdoc example - NO variable interpolation
* Variables like {$var} will be treated as literal text
*/
public function templateStatic() {
return <<<'HTML'
<div class="modal">
<div class="modal-header">
<h2>Static Template</h2>
<p>This {$variable} will not be interpolated</p>
</div>
<div class="modal-body">
<p>Nowdoc syntax uses quotes: <<<'HTML'</p>
</div>
</div>
HTML;
}
/**
* Nowdoc CSS example
*/
public function stylesStatic() {
return <<<'CSS'
.modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.modal-header {
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
CSS;
}
/**
* Nowdoc JavaScript example
*/
public function scriptStatic() {
return <<<'JS'
function showModal(content) {
const modal = document.createElement('div');
modal.className = 'modal';
modal.innerHTML = content;
document.body.appendChild(modal);
}
function hideModal() {
const modal = document.querySelector('.modal');
if (modal) {
modal.remove();
}
}
JS;
}
}
/**
* Indented heredoc example (PHP 7.3+)
*/
class Card {
public function render($title, $content) {
return <<<'HTML'
<div class="card">
<div class="card-header">
<h3>{$title}</h3>
</div>
<div class="card-body">
{$content}
</div>
</div>
HTML;
}
}
// Example usage
$button = new Button();
echo $button->render('World', 'btn-1', 'btn-primary');
echo $button->styles('#007bff', '#0056b3');
echo $button->script('btn-1');
$modal = new Modal();
echo $modal->templateStatic();
echo $modal->stylesStatic();