-
Notifications
You must be signed in to change notification settings - Fork 2
index
public/index.php is the single entry point of a Pair web application. In most projects it does only two things:
- load Composer
- create the
Applicationsingleton and run it
<?php
use Pair\Core\Application;
require dirname(__DIR__) . '/vendor/autoload.php';
Application::getInstance()->run();This is the preferred default for the stable Pair v3 line.
Use guestModule() when specific module actions must be accessible without authentication.
Important: in the current Pair code, the access check matches the module plus an explicit allow-list of actions. Pass the actions you want to expose; an empty array is not treated as a wildcard.
$app->guestModule('public', ['status', 'ping']);
$app->guestModule('oauth2', ['login', 'callback', 'refresh']);By default, Pair treats api as the API module. You can extend or replace the list:
$app->setApiModules(['api', 'v1', 'webhooks']);If your app extends Pair\Models\User, register it before run():
$app->setUserClass(\App\Models\User::class);For scripts that should execute controller logic without HTML rendering:
use Pair\Core\Application;
Application::getInstance()
->headless()
->run();Useful for testing, instrumentation, or advanced bootstrap code:
$app = Application::getInstance();
$app->initializeController();
// optional: assign last-minute template variables here
$app->var('buildNumber', '2026.03.26');
$app->renderTemplate();<?php
use Pair\Core\Application;
require dirname(__DIR__) . '/vendor/autoload.php';
$app = Application::getInstance();
$app->setUserClass(\App\Models\User::class);
$app->guestModule('public', ['status', 'ping']);
$app->guestModule('oauth2', ['login', 'callback']);
$app->setApiModules(['api', 'v1']);
$app->run();-
Application::run()internally callsinitializeController()and thenrenderTemplate(). - Environment variables are loaded from
APPLICATION_PATH/.env. - API modules and headless execution skip template rendering.
- Keep
index.phpsmall. Most project-specific behavior belongs in classes, not in bootstrap code.
See also: Application, Router, API, User.