Skip to content

polaris/yii

Polaris for PHP in a Yii 3 application: a yiisoft/config plugin whose polaris params become the Config, Polaris, Graph and Pipeline definitions on the application’s connection, cache, logger, event dispatcher and mailer; the 52 endpoints as routes in the routes group; an authentication method for your own routes; the polaris:* console commands. Every response is the one the framework-free core sends: the whole functional suite and the 184 contract fixtures replay through the Yii application in CI.

Terminal window
composer require polaris/yii

With yiisoft/config the package’s groups merge into the application (params, di, di-console, routes, events-web, events-console); the application’s own config/params.php sets what differs:

'polaris' => [
'root_path' => dirname(__DIR__),
'secrets' => [
'app_key' => getenv('POLARIS_APP_KEY'), // at least 32 bytes
'jwt_private_key_file' => 'var/keys/private.pem', // relative to root_path
'jwt_public_key_file' => 'var/keys/public.pem',
'jwt_kid' => 'key-1',
],
'auth' => ['issuer' => 'https://app.example.com'],
'database' => ['dsn' => 'sqlite:' . dirname(__DIR__) . '/var/polaris.sqlite'], // or a PDO / Yiisoft\Db connection definition
],
Terminal window
./yii polaris:schema:create # the tables, the permission catalog, the system roles
./yii polaris:doctor # secrets, keys, manifest, database, schema

The application provides what every Yii application has: PSR-17 factories, Psr\SimpleCache\CacheInterface (rate limits, the denylist and OTP quotas live there, so a cache that outlives a request), a PSR-3 logger, yiisoft/yii-event (the Polaris listeners are registered on every Polaris event class), and a RouteCollectionInterface built from the routes group.

KeyMeaning
root_path, path_prefix, manifest_directoryWhere relative PEM paths resolve; where the routes are mounted; the api/**/*.yaml directory
secretsapp_key, jwt_private_key, jwt_public_key, jwt_kid, the previous-key pair, each PEM also as <key>_file
auth, rate_limitsThe docs/auth/configuration.md keys; anything left out keeps core’s default
databasedsn/user/password, or leave the DSN null and define PDO, a Yiisoft\Db connection or a DatabaseAdapter in the container
mailer, mail_fromlog (codes go to the log), mail (the Yii mailer, plain text), or an OtpMailerInterface id
smslog, or an SmsSenderInterface id
breach_check, clock, encrypter, metrics, totp, qr_codes, rate_storeOptional port ids
// config/routes.php: your own routes behind Polaris access tokens
Route::get('/app/me')->middleware('polaris/authentication')->action(MeAction::class),
// in the action: the identity yiisoft/auth stored on the request
$identity = $request->getAttribute(Yiisoft\Auth\Middleware\Authentication::class); // Polaris\Yii\Auth\PolarisIdentity
$identity->user->email; // Polaris\Model\User
$identity->claim('org'); // the active organization from the token
// The services
$graph = $container->get(Polaris\Wiring\Graph::class);

Console: polaris:schema:create, polaris:schema:drop, polaris:schema:export, polaris:schema:diff, polaris:manifest --format=json|openapi, polaris:doctor.

The demo under examples/yii is a complete host in a dozen files.

MIT.