Left Icon Right Icon
Squehub SqueHub

🗂️ Namespaces & Usage in Squehub

Namespaces in Squehub organize your code into logical modules and folders, following PSR-4 standards. They allow autoloading and help avoid class name conflicts.

📦 Core Directory Namespaces

All core framework classes live under the App\Core namespace. This includes foundational classes and utilities such as:

  • Helper – common utility functions (globally available, no import needed)
  • View – template rendering engine
  • Mail – email sending
  • Notification – app notifications
  • Verification – verification utilities
  • Model – base model class for database ORM
  • MiddlewareHandler – middleware pipeline manager
  • Task – for scheduled/background tasks
  • Dumpper – data seeding and dumping tool

📁 Core Directory Structure Example

app/core/
├── Helper.php
├── Mail.php
├── MiddlewareHandler.php
├── Model.php
├── Notification.php
├── Task.php
├── Dumpper.php
├── Verification.php
├── View.php
└── ...

📁 Project Directory & Namespace Structure

Your application files live under the Project namespace. This mirrors the folder structure inside project/. For example:

project/
├── controllers/
│   └── AuthController.php
├── models/
│   └── User.php
├── middleware/
│   ├── AuthMiddleware.php
│   └── auth/
│       └── VerifyAdminMiddleware.php
├── utils/                 # Custom utility/helper PHP files (loaded globally)
│   └── customHelpers.php
└── tasks/
    └── CleanUpTask.php

🌟 Utils Directory: Global Utility Files

Both project/utils/ and any Utils/ directories inside packages may contain PHP files with helper functions or classes. These are automatically loaded globally by the framework during bootstrap, so you do not need to import them explicitly.

📜 Declaring Namespaces

In Core Files

Each core file must declare the App\Core namespace at the top (except helper functions which are globally accessible without import):

<?php
namespace App\Core;

class MiddlewareHandler {
    // ...
}

In Project Files

Declare namespaces matching the folder under Project. Examples:

<?php
namespace Project\Models;

use App\Core\Model;

class User extends Model {
    // ...
}
<?php
namespace Project\Middleware\Auth;

class VerifyAdminMiddleware {
    // ...
}
<?php
namespace Project\Tasks;

class CleanUpTask {
    // ...
}

📌 Important Notes

  • The namespace must exactly match the folder structure, including case sensitivity.
  • For subfolders, namespaces are nested (e.g., Project\Middleware\Auth for project/middleware/auth/).
  • Composer autoloading depends on this matching to work properly.
  • Helper functions and utility files inside project/utils/ and package Utils/ folders are globally loaded; no import needed.

🛠 Importing & Using Core Classes in Project Code

Use use statements to import core classes before using them in your controllers, models, middleware, tasks, or routes — except for helpers and utils, which require no import:

use App\Core\View;
use App\Core\Mail;
use App\Core\Notification;
use App\Core\Verification;
use App\Core\Model;
use App\Core\MiddlewareHandler;
use App\Core\Task;
use App\Core\Dumpper;

// Helper and Utils functions (csrf_token(), route(), custom helpers, etc.) are globally available without importing.

🖼 Using Views in Routes or Controllers

The View class must be imported to render templates properly. Use dot notation matching the view folder structure:

use App\Core\View;

return View::render('admin.dashboard');  // loads views/admin/dashboard.squehub.php

Make sure your views folders and namespaces correspond exactly for Squehub’s view loader to find the files.

✅ Summary

  • All core framework files reside in the App\Core namespace, except helper and utils functions that are globally available.
  • Your app files live in the Project namespace matching their folder structure.
  • Namespaces must be declared at the top of each PHP file.
  • Match namespace exactly to folder names (case-sensitive).
  • Use use to import classes before usage, except for helpers and utils.
  • Keep middleware, tasks, dumpper, and other components organized into subfolders with matching namespaces.
  • Views must be called with dot notation matching their folder paths and imported namespaces.
💡 Tip: Proper namespace usage and folder structure organization keep your codebase clean, maintainable, and scalable as your project grows.
;