-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetting-started.html
More file actions
926 lines (795 loc) · 43.7 KB
/
getting-started.html
File metadata and controls
926 lines (795 loc) · 43.7 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
<!DOCTYPE html>
<html lang="en" class="scroll-smooth">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Getting Started - Forge Kernel Documentation</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/docs.css">
</head>
<body class="bg-gray-50 text-gray-900">
<!-- Navigation -->
<nav class="bg-white shadow-sm border-b">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16">
<div class="flex items-center">
<div class="flex-shrink-0">
<h1 class="text-xl font-bold text-gray-900">
Forge Kernel
</h1>
</div>
<div class="hidden sm:ml-6 sm:flex sm:space-x-8">
<a href="index.html"
class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium hover:text-blue-600">
Home
</a>
<a href="getting-started.html"
class="text-blue-600 inline-flex items-center px-1 pt-1 text-sm font-medium border-b-2 border-blue-600">
Getting Started
</a>
<a href="core-concepts.html"
class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium hover:text-blue-600">
Core Concepts
</a>
<a href="modules.html"
class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium hover:text-blue-600">
Capabilities
</a>
<a href="api-reference.html"
class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium hover:text-blue-600">
API Reference
</a>
<a href="tutorial.html"
class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium hover:text-blue-600">
Tutorials
</a>
</div>
</div>
<!-- Mobile menu button -->
<div class="flex items-center sm:hidden">
<button id="mobile-menu-button" class="text-gray-700 hover:text-blue-600 p-2">
<i class="fas fa-bars text-xl"></i>
</button>
</div>
</div>
</div>
<!-- Mobile menu -->
<div id="mobile-menu" class="sm:hidden hidden bg-white border-t border-gray-200">
<div class="px-2 pt-2 pb-3 space-y-1">
<a href="index.html"
class="block px-3 py-2 text-gray-900 hover:text-blue-600">
Home
</a>
<a href="getting-started.html"
class="block px-3 py-2 text-blue-600 font-medium">
Getting Started
</a>
<a href="core-concepts.html"
class="block px-3 py-2 text-gray-900 hover:text-blue-600">
Core Concepts
</a>
<a href="modules.html"
class="block px-3 py-2 text-gray-900 hover:text-blue-600">
Capabilities
</a>
<a href="api-reference.html"
class="block px-3 py-2 text-gray-900 hover:text-blue-600">
API Reference
</a>
<a href="tutorial.html"
class="block px-3 py-2 text-gray-900 hover:text-blue-600">
Tutorials
</a>
</div>
</div>
</nav>
<!-- Main Content -->
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div class="flex flex-col lg:flex-row gap-8">
<!-- Sidebar Navigation -->
<div id="sidebar-nav" class="lg:w-1/4">
<!-- Mobile menu overlay -->
<div id="mobile-menu-overlay" class="mobile-menu-overlay"></div>
<div class="bg-white rounded-lg shadow-sm p-6 sticky top-8">
<h3 class="text-lg font-semibold text-gray-900 mb-4">
Getting Started
</h3>
<nav class="space-y-2">
<a href="#requirements"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600">
Requirements
</a>
<a href="#installation"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600">
Installation
</a>
<a href="#configuration"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600">
Configuration
</a>
<a href="#first-controller"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600">
First Controller
</a>
<a href="#services"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600">
Services & DI
</a>
<a href="#routing"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600">
Routing
</a>
<a href="#views-templates"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600">
Views & Templates
</a>
<a href="#database"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600">
Database & ORM
</a>
<a href="#developer-mode"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600">
Developer Mode
</a>
<a href="#cli-commands"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600">
CLI Commands
</a>
</nav>
</div>
</div>
<!-- Main Content -->
<div class="lg:w-3/4">
<div class="bg-white rounded-lg shadow-sm p-8">
<h1 class="text-4xl font-bold text-gray-900 mb-6">
Getting Started with Forge
</h1>
<p class="text-xl text-gray-600 mb-8">
This guide will help you get Forge up and running. It's pretty straightforward.
</p>
<section id="requirements" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">Requirements</h2>
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
<li>PHP 8.2 or higher</li>
<li>Web server (Apache, Nginx, or PHP CLI built-in server)</li>
<li>SQLite, MySQL, or PostgreSQL (optional, install via database capability if needed)</li>
</ul>
<p class="text-gray-600 mb-4">
<strong>Note:</strong> Forge doesn't require Composer. The kernel is dependency-free. Database and ORM are capabilities you install when needed, not built-in requirements.
</p>
</section>
<section id="installation" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">Installation</h2>
<p class="text-gray-600 mb-4">A few ways to get Forge running.</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># Quick install with one command
bash <(curl -Ls https://raw.githubusercontent.com/forge-engine/installer/main/installer.sh)</code></pre>
</div>
<p class="text-gray-600 mb-4">
That's it! This command will clone the starter project, set up the folder structure, and give you a working Forge app you can run immediately.
</p>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Manual Installation</h3>
<p class="text-gray-600 mb-4">If you prefer to set things up manually:</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash">git clone https://github.com/forge-engine/forge-starter
cd forge-starter
cp env-example .env
php install.php
php forge.php key:generate
php forge.php package:install-project</code></pre>
</div>
</section>
<section id="configuration" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">Configuration</h2>
<p class="text-gray-600 mb-4">
Forge uses environment variables for configuration. Edit your <code class="bg-gray-100 px-2 py-1 rounded">.env</code> file:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># Application Settings
APP_NAME="My Forge App"
APP_ENV=development
APP_DEBUG=true
APP_KEY=your-generated-key
FORGE_DEVELOPER_MODE=false
# Database Configuration (only if you've installed a database capability)
DB_DRIVER=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=forge_app
DB_USER=root
DB_PASS=password
SQLITE_PATH=/storage/database
SQLITE_DB=/database.sqlite
# Cache Configuration
CACHE_DRIVER=file
# Session Configuration
SESSION_DRIVER=file
SESSION_LIFETIME=1440</code></pre>
</div>
<p class="text-gray-600 mb-4">
Start the development server to test your installation:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash">php forge.php serve</code></pre>
</div>
<p class="text-gray-600 mb-4">
Visit <code class="bg-gray-100 px-2 py-1 rounded">http://localhost:8000</code> to see your application running!
</p>
</section>
<section id="first-controller" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">Creating Your First Controller</h2>
<p class="text-gray-600 mb-4">
Most Forge commands use interactive wizards by default. Let's create a simple controller to handle HTTP requests:
</p>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Using the Wizard</h3>
<p class="text-gray-600 mb-4">
Run the command without arguments to start the interactive wizard:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># Run wizard (interactive)
php forge.php generate:controller
# The wizard will ask:
# Type (app or module): app
# Name (Controller class name without suffix): Welcome
# Path (Optional subfolder inside Controllers): [press Enter for none]</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Skipping the Wizard</h3>
<p class="text-gray-600 mb-4">
You can skip the wizard by providing options directly:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># Skip wizard for app scope
php forge.php generate:controller --type=app --name=Welcome
# Skip wizard for module scope
php forge.php generate:controller --type=module --module=Blog --name=Post
# With optional subfolder path
php forge.php generate:controller --type=app --name=User --path=Admin</code></pre>
</div>
<p class="text-gray-600 mb-4">
This creates a controller in <code class="bg-gray-100 px-2 py-1 rounded">app/Controllers/WelcomeController.php</code>:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-php"><?php
declare(strict_types=1);
namespace App\Controllers;
use Forge\Core\DI\Attributes\Service;
use Forge\Core\Http\Attributes\Middleware;
use Forge\Core\Http\Response;
use Forge\Core\Routing\Route;
use Forge\Core\Http\Request;
use Forge\Traits\ControllerHelper;
#[Service]
#[Middleware('web')]
final class WelcomeController
{
use ControllerHelper;
#[Route("/welcome")]
public function index(Request $request): Response
{
$data = [
"title" => "Welcome to Forge",
"message" => "Hello from your first controller!"
];
return $this->view(view: "pages/welcome/index", data: $data);
}
}</code></pre>
</div>
</section>
<section id="services" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">Services & Dependency Injection</h2>
<p class="text-gray-600 mb-4">
Forge uses attributes for dependency injection. Services are automatically discovered from <strong>any folder</strong> in your application or modules when they have the <code class="bg-gray-100 px-2 py-1 rounded">#[Service]</code> or <code class="bg-gray-100 px-2 py-1 rounded">#[Discoverable]</code> attribute.
</p>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Service Discovery</h3>
<p class="text-gray-600 mb-4">
The framework automatically scans all directories recursively, so you can organize your code however you prefer. No specific folder structure is required.
</p>
<p class="text-gray-600 mb-4">
<strong>Attributes:</strong>
</p>
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
<li><code class="bg-gray-100 px-2 py-1 rounded">#[Service]</code> - Register a class as a service in the dependency injection container</li>
<li><code class="bg-gray-100 px-2 py-1 rounded">#[Discoverable]</code> - Semantically marks a class as discoverable (same behavior as <code class="bg-gray-100 px-2 py-1 rounded">#[Service]</code>)</li>
</ul>
<p class="text-gray-600 mb-4">
<strong>Discovery Scope:</strong> Services are discovered from all directories under:
</p>
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
<li><code class="bg-gray-100 px-2 py-1 rounded">app/</code> - Any folder structure</li>
<li><code class="bg-gray-100 px-2 py-1 rounded">modules/*/src/</code> - Any folder structure within module source directories</li>
</ul>
<p class="text-gray-600 mb-4">
<strong>Note:</strong> While you can use any folder structure, traditional structures like <code class="bg-gray-100 px-2 py-1 rounded">app/Services/</code> or <code class="bg-gray-100 px-2 py-1 rounded">app/Repositories/</code> still work perfectly. The framework discovers services based on attributes, not folder location.
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-php"><?php
namespace App\Services;
use Forge\Core\DI\Attributes\Service;
#[Service]
class UserService
{
public function findUser(int $id)
{
// Your logic here
// Note: This example assumes you have a User model from an ORM capability
// return User::query()->id($id)->first();
}
}</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Using Services</h3>
<p class="text-gray-600 mb-4">
Use services in controllers by adding them to the constructor:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-php"><?php
namespace App\Controllers;
use App\Services\UserService;
use Forge\Core\DI\Attributes\Service;
use Forge\Core\Http\Response;
use Forge\Core\Routing\Route;
#[Service]
class UserController
{
public function __construct(
private readonly UserService $userService
) {}
#[Route('/users/{id}')]
public function show(string $id): Response
{
$user = $this->userService->findUser((int)$id);
return $this->view('users/show', ['user' => $user]);
}
}</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Service Discovery Cache</h3>
<p class="text-gray-600 mb-4">
Service discovery happens once at bootstrap and uses a class map cache for performance. The cache is automatically updated when files change. If you add a new service with <code class="bg-gray-100 px-2 py-1 rounded">#[Service]</code> and it's not being discovered, clear the cache:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash">php forge.php cache:flush</code></pre>
</div>
<p class="text-gray-600 mb-4">
<strong>Note:</strong> Services are automatically resolved by the container. Just add them to your constructor and they'll be injected. The discovery process has no performance trade-off since it uses class mapping and only updates entries when files change.
</p>
</section>
<section id="routing" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">Routing</h2>
<p class="text-gray-600 mb-4">
Forge uses attribute-based routing. Define routes directly on your controller methods:
</p>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Basic Routes</h3>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-php"><?php
#[Route("/")]
public function home(): Response
{
return $this->view("pages/home");
}
#[Route("/api/posts", method: "POST")]
public function createPost(Request $request): Response
{
// Handle POST request
return $this->json(["status" => "created"]);
}
// Using Middleware attribute on controller/method (recommended)
use Forge\Core\Http\Attributes\Middleware;
#[Middleware("web")]
class WebController
{
#[Middleware("auth")]
#[Route("/profile")]
public function profile(): Response
{
return $this->view("profile/index");
}
}</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Route Parameters</h3>
<p class="text-gray-600 mb-4">
Routes support parameters that are automatically extracted and type-cast based on your method signature:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-php"><?php
// Basic parameter - automatically cast to int
#[Route("/users/{id}")]
public function showUser(Request $request, int $id): Response
{
// $id is automatically cast to int
return $this->json(["user_id" => $id]);
}
// Multiple parameters
#[Route("/posts/{year}/{month}/{slug}")]
public function showPost(int $year, int $month, string $slug): Response
{
return $this->json([
"year" => $year,
"month" => $month,
"slug" => $slug
]);
}
// Complex parameter with constraint - matches anything including slashes
#[Route("/files/{path:.+}")]
public function serveFile(string $path): Response
{
// {path:.+} matches any path including slashes (e.g., /files/docs/user-guide.pdf)
return $this->file($path);
}
// Mix Request object with route parameters
#[Route("/users/{id}/posts/{postId}")]
public function showUserPost(Request $request, int $id, int $postId): Response
{
// Both $id and $postId are extracted from the route
// $request is injected automatically
return $this->json([
"user_id" => $id,
"post_id" => $postId,
"query" => $request->query("filter")
]);
}</code></pre>
</div>
<p class="text-gray-600 mb-4">
<strong>Parameter Constraints:</strong> Use <code class="bg-gray-100 px-2 py-1 rounded">{param:.+}</code> to match any path including slashes. Route parameters are automatically type-cast (int, float, bool) based on your method signature types.
</p>
<p class="text-gray-600 mb-4">
<strong>Note:</strong> The <code class="bg-gray-100 px-2 py-1 rounded">method</code> parameter accepts a single HTTP method as a string (e.g., "GET", "POST", "PUT", "DELETE"), not an array.
</p>
<p class="text-gray-600 mb-4">
Routes are automatically discovered from your controllers. No need for separate route files! Use <code class="bg-gray-100 px-2 py-1 rounded">#[Middleware]</code> attribute for cleaner middleware application on controllers/methods.
</p>
</section>
<section id="views-templates" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">Views & Templates</h2>
<p class="text-gray-600 mb-4">
Forge uses PHP-first templating. Views can be created in your app or within modules (capabilities).
</p>
<h3 class="text-lg font-semibold mb-3 text-gray-900">View Locations</h3>
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
<li><strong>App scope:</strong> <code class="bg-gray-100 px-2 py-1 rounded">app/resources/views/</code></li>
<li><strong>Module scope:</strong> <code class="bg-gray-100 px-2 py-1 rounded">modules/ModuleName/src/Resources/views/</code></li>
</ul>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Layout Locations</h3>
<p class="text-gray-600 mb-4">
Layouts are expected to be in:
</p>
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
<li><strong>App scope:</strong> <code class="bg-gray-100 px-2 py-1 rounded">app/resources/views/layouts/</code></li>
<li><strong>Module scope:</strong> <code class="bg-gray-100 px-2 py-1 rounded">modules/ModuleName/src/Resources/views/layouts/</code></li>
</ul>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Using Views</h3>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-php"><!-- app/resources/views/pages/welcome/index.php -->
<?php
use Forge\Core\View\View;
// Load layout from app
View::layout(name: "layouts/app", loadFromModule: false);
?>
<div class="container mx-auto px-4 py-8">
<h1 class="text-4xl font-bold text-gray-900 mb-4">
<?= $title ?>
</h1>
<p class="text-xl text-gray-600">
<?= $message ?>
</p>
</div></code></pre>
</div>
<p class="text-gray-600 mb-4">
To load a layout from a module (like ForgeUi):
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-php"><?php
use Forge\Core\View\View;
// Load layout from module
View::layout(name: "layouts/app", loadFromModule: true, moduleName: "ForgeUi");</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Creating Layouts</h3>
<p class="text-gray-600 mb-4">
Create a layout file in your app:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-html"><!-- app/resources/views/layouts/app.php -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Forge App</title>
</head>
<body>
<?php
use Forge\Core\View\View;
echo View::section('content');
?>
</body>
</html></code></pre>
</div>
<p class="text-gray-600 mb-4">
<strong>Note:</strong> See the <code class="bg-gray-100 px-2 py-1 rounded">ForgeUi</code> module for reference on module folder structure and component organization.
</p>
</section>
<section id="database" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">Database & ORM (Capabilities)</h2>
<p class="text-gray-600 mb-4">
Database and ORM are not built into the kernel. They're capabilities you install when you need them.
</p>
<p class="text-gray-600 mb-4">
Install a database capability first:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># Install a database capability (with wizard)
php forge.php package:install-module
# Or skip wizard and specify directly
php forge.php package:install-module --module=ForgeDatabaseSQL
# Or install an ORM capability
php forge.php package:install-module --module=ForgeSqlOrm</code></pre>
</div>
<p class="text-gray-600 mb-4">
Once installed, you can create migrations and models:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># Create a migration
php forge.php generate:migration CreateUsersTable
# Run migrations
php forge.php db:migrate</code></pre>
</div>
<p class="text-gray-600 mb-4">
<strong>Note:</strong> Database and ORM functionality requires installing the appropriate capability module first. The kernel doesn't include these by default.
</p>
</section>
<section id="developer-mode" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">Developer Mode</h2>
<p class="text-gray-600 mb-4">
Developer mode unlocks advanced CLI commands for working with registries and publishing kernel/capability versions. You only need this if you're building your own kernel or publishing capabilities.
</p>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Enabling Developer Mode</h3>
<p class="text-gray-600 mb-4">
Set <code class="bg-gray-100 px-2 py-1 rounded">FORGE_DEVELOPER_MODE=true</code> in your <code class="bg-gray-100 px-2 py-1 rounded">.env</code> file:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash">FORGE_DEVELOPER_MODE=true</code></pre>
</div>
<p class="text-gray-600 mb-4">
Or set it in <code class="bg-gray-100 px-2 py-1 rounded">config/app.php</code>:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-php"><?php
return [
'developer_mode' => true,
// ... other config
];</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Commands Unlocked</h3>
<p class="text-gray-600 mb-4">
When developer mode is enabled, these commands become available:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># Framework/Kernel registry commands
php forge.php dev:framework:list # List available kernel versions
php forge.php dev:framework:publish # Publish kernel registry changes
php forge.php dev:framework:version # Create new kernel version
# Module/Capability registry commands
php forge.php dev:module:list # List available capability versions
php forge.php dev:module:publish # Publish capability registry changes
php forge.php dev:module:version # Create new capability version
# Registry management
php forge.php dev:registry:config # Configure registry settings
php forge.php dev:registry:init # Initialize new registry</code></pre>
</div>
<p class="text-gray-600 mb-4">
<strong>When to enable:</strong> Only enable developer mode if you're building your own kernel fork or publishing capabilities to registries. For regular application development, you don't need it.
</p>
</section>
<section id="cli-commands" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">CLI Commands</h2>
<p class="text-gray-600 mb-4">
Most commands use interactive wizards by default. You can skip wizards by providing options with <code class="bg-gray-100 px-2 py-1 rounded">--option=value</code> flags.
</p>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Interactive Command Browser</h3>
<p class="text-gray-600 mb-4">
Forge includes a retro-styled interactive command browser that makes it easy to discover and execute commands. Simply run <code class="bg-gray-100 px-2 py-1 rounded">php forge.php</code> without any arguments to access it.
</p>
<div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-6">
<div class="flex">
<div class="flex-shrink-0">
<i class="fas fa-info-circle text-blue-500"></i>
</div>
<div class="ml-3">
<p class="text-sm text-blue-700">
<strong>Features:</strong> The interactive browser includes a splash screen (skippable with <code class="bg-blue-100 px-1 py-0.5 rounded text-xs">--no-splash</code>), multi-column command listings that adapt to your terminal width, category-based browsing, and the ability to execute commands or view help directly from the interface. Use arrow keys to navigate and Esc to exit.
</p>
</div>
</div>
</div>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># Launch interactive command browser
php forge.php
# Skip splash screen
php forge.php --no-splash
# Show traditional command list
php forge.php --list
# Launch interactive browser directly
php forge.php --interactive</code></pre>
</div>
<p class="text-gray-600 mb-4">
The interactive browser allows you to:
</p>
<ul class="list-disc list-inside text-gray-600 mb-6 space-y-2">
<li>Browse commands by category (General, Database, Modules, etc.)</li>
<li>View all commands in a searchable multi-column layout</li>
<li>Execute commands directly from the browser</li>
<li>View detailed help for any command</li>
<li>Navigate with arrow keys (↑↓←→) and exit with Esc</li>
</ul>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Generate Commands</h3>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># Generate files (wizards ask for type: app/module, name, etc.)
php forge.php generate:controller
php forge.php generate:middleware
php forge.php generate:migration
php forge.php generate:model
php forge.php generate:service
php forge.php generate:component
# Skip wizards with options
php forge.php generate:controller --type=app --name=User
php forge.php generate:controller --type=module --module=Blog --name=Post
# Generate test (wizard can ask for type: app/module/engine)
php forge.php generate:test
php forge.php generate:test --type=app --group=example
php forge.php generate:test --type=module --module=Blog --group=example
# Note: engine scope is for testing the kernel itself</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Database Operations</h3>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash">php forge.php db:migrate
php forge.php db:migrate:rollback</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Development Server</h3>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash">php forge.php serve</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Cache Management</h3>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash">php forge.php cache:clear
php forge.php cache:flush # Flush service discovery cache</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Application Maintenance</h3>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash">php forge.php down
php forge.php up</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Package Management</h3>
<p class="text-gray-600 mb-4">
Package management commands use wizards by default. Use <code class="bg-gray-100 px-2 py-1 rounded">--module=</code> to skip the wizard:
</p>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># With wizard (interactive)
php forge.php package:install-module
php forge.php package:remove-module
# Skip wizard
php forge.php package:install-module --module=ForgeAuth
php forge.php package:install-module --module=ForgeAuth@1.2.0
php forge.php package:remove-module --module=ForgeAuth
php forge.php package:list-modules</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3 text-gray-900">Other Commands</h3>
<div class="code-block p-6 text-white rounded-lg mb-6">
<pre><code class="language-bash"># Generate application key
php forge.php key:generate
# See all available commands (traditional list)
php forge.php help
# Launch interactive command browser
php forge.php</code></pre>
</div>
</section>
<section id="next-steps" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">Next Steps</h2>
<p class="text-gray-600 mb-4">
What you might want to look at next:
</p>
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
<li><strong><a href="core-concepts.html" class="text-blue-600 hover:underline">Core Concepts</a></strong> — How dependency injection, middleware, and the module system work.</li>
<li><strong><a href="modules.html" class="text-blue-600 hover:underline">Capabilities</a></strong> — Available capabilities and how to make your own.</li>
<li><strong><a href="api-reference.html" class="text-blue-600 hover:underline">API Reference</a></strong> — Complete API documentation for all kernel components.</li>
</ul>
</section>
</div>
</div>
</div>
</div>
<!-- Footer -->
<footer class="bg-gray-900 text-white py-8 mt-16">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
<div class="mb-4">
<span class="text-lg font-bold">Forge Kernel</span>
</div>
<p class="text-gray-400">
A toolbox for builders who like to do things their way.
</p>
</div>
</footer>
<script>
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Mobile menu toggle
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
const mobileSidebarButton = document.getElementById('mobile-sidebar-button');
const mobileMenuOverlay = document.getElementById('mobile-menu-overlay');
const sidebar = document.getElementById('sidebar-nav');
function toggleMobileMenu() {
mobileMenu.classList.toggle('hidden');
}
function openMobileSidebar() {
sidebar.classList.add('mobile-menu-open');
mobileMenuOverlay.classList.add('active');
}
function closeMobileSidebar() {
sidebar.classList.remove('mobile-menu-open');
mobileMenuOverlay.classList.remove('active');
}
if (mobileMenuButton) {
mobileMenuButton.addEventListener('click', toggleMobileMenu);
}
if (mobileSidebarButton) {
mobileSidebarButton.addEventListener('click', openMobileSidebar);
}
if (mobileMenuOverlay) {
mobileMenuOverlay.addEventListener('click', closeMobileSidebar);
}
// Close mobile menu when clicking on a link
document.querySelectorAll('#mobile-menu a').forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.add('hidden');
});
});
// Close mobile menu when clicking outside
document.addEventListener('click', function (event) {
const isClickInsideMenu = mobileMenu && mobileMenu.contains(event.target);
const isClickOnMenuButton = mobileMenuButton && mobileMenuButton.contains(event.target);
if (mobileMenu && !mobileMenu.classList.contains('hidden') && !isClickInsideMenu && !isClickOnMenuButton) {
mobileMenu.classList.add('hidden');
}
});
// Close mobile menu and sidebar on window resize if above mobile breakpoint
window.addEventListener('resize', function () {
if (window.innerWidth >= 640) {
if (mobileMenu) mobileMenu.classList.add('hidden');
closeMobileSidebar();
}
});
// Update active navigation on scroll
window.addEventListener('scroll', function () {
const sections = document.querySelectorAll('.section-anchor');
const navLinks = document.querySelectorAll('.nav-link');
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop - 100;
if (window.pageYOffset >= sectionTop) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('active');
}
});
});
</script>
</body>
</html>