Imports
Strata requires explicit imports for all symbols. There are no implicit imports or globals.
Import Syntax
Basic Import
strata
import App.Models.User;
import App.Services.Logger;Aliased Import
strata
import App.Models.User as UserModel;
import Illuminate.Http.Request as HttpRequest;Function Import
strata
import fn MyModule.myHelper;
import fn OtherModule.utility as helper;- Imports are file-level only
- Paths map to directory structure
- No wildcards
- Use
asfor aliasing to avoid name collisions - Use
fnprefix specifically for function imports
Import Rules
- All symbols must be imported: No magic imports
- File-level only: Imports at the top of the file
- No wildcards: Must import specific symbols
- Paths map to directories:
App.Models.Usermaps toApp/Models/User.str - Aliasing: Use
asto provide a local name for an imported symbol - Function explicitly: Use
fnfor importing standalone functions
Import Examples
Single Import
strata
import App.Models.User;
fn createUser(): User {
return User(name: "Donald", email: "donaldpakkies@gmail.com");
}Multiple Imports
strata
import App.Models.User;
import App.Models.Post;
import App.Services.UserService;
fn example(): Void {
let user = User(name: "Donald", email: "donaldpakkies@gmail.com");
let post = Post(title: "Hello", content: "World");
let service = UserService();
}Directory Structure
Imports map to your directory structure:
src/
App/
Models/
User.str
Services/
Logger.strstrata
import App.Models.User;
import App.Services.Logger;Import Path Resolution
Strata resolves imports based on:
- Current file location: Relative to the file
- Project root: Absolute from project root
- Composer autoload: If using Composer
Common Patterns
Models
strata
import App.Models.User;
import App.Models.Post;
import App.Models.Comment;Services
strata
import App.Services.UserService;
import App.Services.EmailService;
import App.Services.NotificationService;Utilities
strata
import App.Utils.StringHelper;
import App.Utils.DateHelper;
import App.Utils.Validator;Best Practices
- Group imports: Group by category (Models, Services, Utils)
- Use clear paths: Make import paths match directory structure
- Import only what you need: Don't import unused symbols
- Organize files: Keep related files in the same directory
Examples
Example: Web Application
strata
// src/App/Http/Controllers/UserController.str
import App.Models.User;
import App.Services.UserService;
import App.Http.Request;
import App.Http.Response;
class UserController {
public fn index(): Response {
let service = UserService();
let users = service.getAll();
return Response(data: users);
}
}Example: Library
strata
// src/MyLib/Utils/Math.str
import MyLib.Utils.NumberHelper;
fn calculateAverage(numbers: Array<Float>): Float {
let helper = NumberHelper();
return helper.sum(numbers: numbers) / count(numbers) as Float;
}Import Errors
Common import errors:
- Symbol not found: Import path doesn't match file location
- Circular dependency: Two files import each other
- Missing import: Using a symbol without importing it
Next Steps
- PHP Interoperability - Using PHP code in Strata
- Getting Started - Setting up your project structure