Skip to content

Commit db1670e

Browse files
committed
updated documentation
1 parent 3bb0e0c commit db1670e

3 files changed

Lines changed: 58 additions & 18 deletions

File tree

core-concepts.html

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,25 @@ <h2 class="text-2xl font-bold text-gray-900 mb-4">Dependency Injection</h2>
198198

199199
<h3 class="text-lg font-semibold mb-3 text-gray-900">Service Discovery</h3>
200200
<p class="text-gray-600 mb-4">
201-
Services with the <code class="bg-gray-100 px-2 py-1 rounded">#[Service]</code> attribute are automatically discovered from specific directories:
201+
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. The framework recursively scans all directories, so you can organize your code however you prefer.
202+
</p>
203+
<p class="text-gray-600 mb-4">
204+
<strong>Attributes:</strong>
205+
</p>
206+
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
207+
<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>
208+
<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>, useful for non-service classes that need DI)</li>
209+
</ul>
210+
<p class="text-gray-600 mb-4">
211+
<strong>Discovery Scope:</strong> Services are discovered from:
202212
</p>
203213
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
204-
<li><code class="bg-gray-100 px-2 py-1 rounded">app/Services/</code></li>
205-
<li><code class="bg-gray-100 px-2 py-1 rounded">app/Repositories/</code></li>
206-
<li><code class="bg-gray-100 px-2 py-1 rounded">app/Middlewares/</code></li>
207-
<li><code class="bg-gray-100 px-2 py-1 rounded">app/Events/</code></li>
208-
<li>Same structure in modules: <code class="bg-gray-100 px-2 py-1 rounded">modules/ModuleName/src/Services/</code>, etc.</li>
214+
<li>All directories under <code class="bg-gray-100 px-2 py-1 rounded">app/</code></li>
215+
<li>All directories under <code class="bg-gray-100 px-2 py-1 rounded">modules/*/src/</code></li>
216+
<li>Engine core directories</li>
209217
</ul>
210218
<p class="text-gray-600 mb-4">
211-
Service discovery happens once at bootstrap and uses a class map cache for performance. If you add a new service and it's not being discovered, clear the cache with <code class="bg-gray-100 px-2 py-1 rounded">php forge.php cache:flush</code>.
219+
Service discovery happens once at bootstrap and uses an incremental class map cache for performance. The cache automatically updates when files change. If you add a new service and it's not being discovered, clear the cache with <code class="bg-gray-100 px-2 py-1 rounded">php forge.php cache:flush</code>.
212220
</p>
213221

214222
<h3 class="text-lg font-semibold mb-3 text-gray-900">Service Registration</h3>

forge-database-sql.html

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,24 @@ <h3 class="text-lg font-semibold mb-3">Complete Example</h3>
672672
<section id="migration-scoping" class="section-anchor mb-12">
673673
<h2 class="text-2xl font-bold text-gray-900 mb-4">Migration Scoping</h2>
674674
<p class="text-gray-600 mb-6">
675-
Migrations can be organized by scope: app, engine, or module. This allows you to run migrations selectively.
675+
Migrations can be organized by scope: app, engine, or module. The framework supports both <strong>folder-based</strong> and <strong>attribute-based</strong> migration discovery.
676+
</p>
677+
678+
<h3 class="text-lg font-semibold mb-3">Migration Discovery Methods</h3>
679+
<p class="text-gray-600 mb-4">
680+
Migrations are discovered using two methods:
681+
</p>
682+
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
683+
<li><strong>Folder-based:</strong> Migrations in traditional <code class="bg-gray-100 px-2 py-1 rounded">Database/Migrations/</code> directories</li>
684+
<li><strong>Attribute-based:</strong> Any migration class with <code class="bg-gray-100 px-2 py-1 rounded">#[Migration]</code> attribute, regardless of folder location</li>
685+
</ul>
686+
<p class="text-gray-600 mb-4">
687+
Both methods work together - migrations discovered through either method are included when running migrations.
676688
</p>
677689

678690
<h3 class="text-lg font-semibold mb-3">App Migrations</h3>
679691
<p class="text-gray-600 mb-4">
680-
Application-specific migrations in <code class="bg-gray-100 px-2 py-1 rounded">app/Database/migrations/</code>:
692+
Application-specific migrations can be placed in <code class="bg-gray-100 px-2 py-1 rounded">app/Database/migrations/</code> or anywhere in <code class="bg-gray-100 px-2 py-1 rounded">app/</code> with the <code class="bg-gray-100 px-2 py-1 rounded">#[Migration]</code> attribute:
681693
</p>
682694
<div class="code-block p-6 text-white rounded-lg mb-6">
683695
<pre><code class="language-bash">php forge.php db:migrate --type=app</code></pre>
@@ -693,7 +705,7 @@ <h3 class="text-lg font-semibold mb-3">Engine Migrations</h3>
693705

694706
<h3 class="text-lg font-semibold mb-3">Module Migrations</h3>
695707
<p class="text-gray-600 mb-4">
696-
Module-specific migrations in <code class="bg-gray-100 px-2 py-1 rounded">modules/{ModuleName}/src/Database/Migrations/</code>:
708+
Module-specific migrations can be placed in <code class="bg-gray-100 px-2 py-1 rounded">modules/{ModuleName}/src/Database/Migrations/</code> or anywhere in <code class="bg-gray-100 px-2 py-1 rounded">modules/{ModuleName}/src/</code> with the <code class="bg-gray-100 px-2 py-1 rounded">#[Migration]</code> attribute:
697709
</p>
698710
<div class="code-block p-6 text-white rounded-lg mb-6">
699711
<pre><code class="language-bash"># Run all module migrations
@@ -710,6 +722,18 @@ <h3 class="text-lg font-semibold mb-3">Tenant Migrations</h3>
710722
<p class="text-gray-600 mb-4">
711723
Automatically discovered when running module migrations.
712724
</p>
725+
726+
<h3 class="text-lg font-semibold mb-3">Attribute-Based Migration Example</h3>
727+
<div class="code-block p-6 text-white rounded-lg mb-6">
728+
<pre><code class="language-php">use Forge\Core\DI\Attributes\Migration;
729+
use App\Modules\ForgeDatabaseSQL\DB\Migrations\Migration as BaseMigration;
730+
731+
#[Migration(scope: 'app')]
732+
class CreateCustomTable extends BaseMigration
733+
{
734+
// Migration code here
735+
}</code></pre>
736+
</div>
713737
</section>
714738

715739
<!-- Migration Grouping -->

getting-started.html

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,24 +316,32 @@ <h3 class="text-lg font-semibold mb-3 text-gray-900">Skipping the Wizard</h3>
316316
<section id="services" class="section-anchor mb-12">
317317
<h2 class="text-2xl font-bold text-gray-900 mb-4">Services & Dependency Injection</h2>
318318
<p class="text-gray-600 mb-4">
319-
Forge uses attributes for dependency injection. Services are automatically discovered from specific directories when they have the <code class="bg-gray-100 px-2 py-1 rounded">#[Service]</code> attribute.
319+
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.
320320
</p>
321321

322322
<h3 class="text-lg font-semibold mb-3 text-gray-900">Service Discovery</h3>
323323
<p class="text-gray-600 mb-4">
324-
Services are automatically discovered at bootstrap from these directories:
324+
The framework automatically scans all directories recursively, so you can organize your code however you prefer. No specific folder structure is required.
325325
</p>
326326

327+
<p class="text-gray-600 mb-4">
328+
<strong>Attributes:</strong>
329+
</p>
330+
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
331+
<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>
332+
<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>
333+
</ul>
334+
335+
<p class="text-gray-600 mb-4">
336+
<strong>Discovery Scope:</strong> Services are discovered from all directories under:
337+
</p>
327338
<ul class="list-disc list-inside space-y-2 text-gray-600 mb-4">
328-
<li><code class="bg-gray-100 px-2 py-1 rounded">app/Services/</code></li>
329-
<li><code class="bg-gray-100 px-2 py-1 rounded">app/Repositories/</code></li>
330-
<li><code class="bg-gray-100 px-2 py-1 rounded">app/Middlewares/</code></li>
331-
<li><code class="bg-gray-100 px-2 py-1 rounded">app/Events/</code></li>
332-
<li>Same structure in modules: <code class="bg-gray-100 px-2 py-1 rounded">modules/ModuleName/src/Services/</code>, etc.</li>
339+
<li><code class="bg-gray-100 px-2 py-1 rounded">app/</code> - Any folder structure</li>
340+
<li><code class="bg-gray-100 px-2 py-1 rounded">modules/*/src/</code> - Any folder structure within module source directories</li>
333341
</ul>
334342

335343
<p class="text-gray-600 mb-4">
336-
<strong>Important:</strong> Services must be placed in these proper directories and have the <code class="bg-gray-100 px-2 py-1 rounded">#[Service]</code> attribute to be automatically discovered. This applies to both app and module (capability) services.
344+
<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.
337345
</p>
338346

339347
<div class="code-block p-6 text-white rounded-lg mb-6">

0 commit comments

Comments
 (0)