File Generators
S-PHP includes powerful code generators to quickly scaffold common application components. All generators automatically create the necessary directory structure and generate properly namespaced PHP classes.Controller Generator
Create a new controller class:Basic Usage
app/controllers/UserController.php
Nested Controllers
Create controllers in subdirectories with automatic namespace resolution:app/controllers/Admin/UserController.php
Configuration
- Path:
app/controllers/{name}.php(Command.php:42) - Namespace:
Sphp\Controllers(Command.php:44) - Base Class:
Sphp\Controllers\Controller(Command.php:45)
Middleware Generator
Create a new middleware class:Basic Usage
app/middleware/AuthMiddleware.php
Nested Middleware
app/middleware/Api/RateLimitMiddleware.php
Configuration
- Path:
app/middleware/{name}.php(Command.php:48) - Namespace:
Sphp\Middleware(Command.php:50) - Base Class:
Sphp\Middleware\Middleware(Command.php:51)
Model Generator
Create a new model class:Basic Usage
app/models/User.php
Nested Models
app/models/Blog/Post.php
Configuration
- Path:
app/models/{name}.php(Command.php:54) - Namespace:
Sphp\Models(Command.php:56) - Base Class:
Sphp\Core\Models(Command.php:57)
View Generator
Create a new view file:Basic Usage
app/views/home.php
Nested Views
app/views/admin/users/index.php
Configuration
- Path:
app/views/{name}.php(Command.php:30) - Template: HTML comment with view name (Command.php:31)
- No namespace (views are plain PHP templates)
Generator Features
Automatic Directory Creation
All generators automatically create parent directories if they don’t exist (Command.php:132):Duplicate Detection
Generators check if files already exist and prevent accidental overwrites (Command.php:141):Namespace Resolution
For class-based generators (controller, middleware, model), subdirectories are automatically converted to sub-namespaces (Command.php:184-186):Admin/UserController→Sphp\Controllers\Admin\UserControllerApi/V1/Middleware→Sphp\Middleware\Api\V1\Middleware