stave.dev

Getting Started

A site is a folder with core at core/. One script builds the rest of the folder, and nothing is installed globally.

Requirements

What Why Source
PHP 8.0 or newer Attributes, and the version core declares core/composer.json
A web server that sends every URL that is not a file to index.php The front controller answers every page. Samples for Apache (mod_rewrite) and nginx are included core/skeleton/frontend/www/.htaccess, core/skeleton/etc/
git and bash Core is a git submodule of the site; zero-init.sh is a bash script core/skeleton/README.md
A database, for anything with accounts Sign-in, permissions and the admin screens read the tables core/sql/core.sql creates. A site of pages that run no query needs none (see below) core/sql/README.md, core/Database.php

Composer and npm are not required. Core loads its own classes and every module's by namespace (Autoloading).

Start a Site

The site is a repository with core as a submodule at core/. Core has a submodule of its own, core/entity/, which sign-in needs, so the update is --recursive.

git init mysite && cd mysite
git submodule add <zero.core repository> core
git submodule update --init --recursive
core/skeleton/zero-init.sh            # or: core/skeleton/zero-init.sh /path/to/site mysite.com

zero-init.sh takes two optional arguments: the site directory (default: the folder that contains core/) and the domain. Without a domain, the folder's name stands in for PRIMARY_DOMAIN and the script says so.

What zero-init.sh Creates

mysite/
├── core/                  already there: the framework
├── etc/                   apache.conf, apache-ssl.conf, nginx.conf for the domain
├── entity/                the site's own entity classes (empty)
├── modules/               the site's own modules (empty)
├── storage/cache/         what core caches; the web server writes here
└── app/
    ├── config/            config.ini, constants.ini, database.ini, allowed-ips.lst
    ├── strings/site.ini   the site's wording
    ├── modules.ini        which modules are on
    ├── .gitignore         modules.ini.lock and .modules.ini.*.tmp
    └── frontend/
        ├── frame/         head, header, sideNav, footer and the partials
        └── www/           web root: index.php, .htaccess, assets/css/main.css

The Web Root's index.php

Four constants, one include, four calls. This is core/skeleton/frontend/www/index.php, the file the script copies to app/frontend/www/index.php:

<?php
// Zero Framework Bootstrap
// ZERO_ROOT is the folder three levels above www/ (app/frontend/www inside the
// zero root), whatever the site folder is called.
define("ZERO_ROOT", dirname(__DIR__, 3) . "/");
define("ROOT_PATH", dirname(ZERO_ROOT) . "/");
define("VIEW_PATH", ZERO_ROOT . "app/frontend/frame/");
define("MODULE_PATH", ZERO_ROOT . "modules/");

require ZERO_ROOT . "core/Application.php";

$app = new Zero\Core\Application();

$app->registerAutoloaders();
$app->parseRequest();
$app->defineConstants();

$app->run(
    \Zero\Core\Request::$module,
    \Zero\Core\Request::$endpoint,
    \Zero\Core\Request::$args
);
Constant Is
ZERO_ROOTThe site root, the folder that holds core/
ROOT_PATHIts parent
VIEW_PATHThe site's frame folder, app/frontend/frame/
MODULE_PATHThe site's modules/ folder

What each of the four calls does is on Routing.

Next Steps

The script prints these when it finishes:

  1. Fill in app/config/database.ini: NAME and USER are blank in the template, and nothing connects until they and DB_DRIVER are set. Check the domain and mail addresses in app/config/config.ini. Every key is on Configuration & Wording.
  2. Create the tables core needs by loading core/sql/core.sql into an empty database. It uses CREATE TABLE IF NOT EXISTS and never drops, truncates or updates, so loading it again is safe (core/sql/README.md).
  3. Make storage/cache/ writable by the web server user.
  4. Install a vhost from etc/. The document root is app/frontend/www/.
  5. Open the site, then build modules in modules/.
mysql <database> < core/sql/core.sql

Running Without a Database

Core opens no connection until code asks for one: Database::getConnection() connects on its first call (core/Database.php). The one check every request makes, Session::endIfDisabled() in Application::run(), returns before any query when nobody is signed in.

With DB_DRIVER, NAME or USER blank in database.ini, no connection is ever attempted: getConnection() throws Database is not configured and logs nothing. So with NAME and USER left blank, as the template has them:

Composer Packages

core/composer.json lists the packages core uses and does not bring with it. Nothing reads that file at runtime: it documents what to install, and a site requires the packages in its own composer.json.

Package Listed under Needed by
minishlink/web-push ^8.0 require The Push module
google/apiclient ^2.18 suggest The Auth module's Google sign-in

Application::registerAutoloaders() includes vendor/autoload.php from ROOT_PATH and from ZERO_ROOT when either exists. A site that uses neither package needs no vendor/ folder.

What a Site May Leave Out

core/skeleton/ is also the default core falls back to. A site overrides by having the file or the key:

Missing from the site Core uses
A frame piece (head, header, sideNav, footer) or a partial (_head-scripts, _oauth-brand, _oauth-buttons, _google-signin) The copy in core/skeleton/frontend/frame/
A config file named constants.ini or error_codes.ini in app/config/ The file of that name in core/skeleton/config/ (Application::configFiles())
A wording key The value in core/skeleton/strings/site.ini (Strings::loadDefaults())
modules/Index/ core/modules/Index/
app/modules.ini Every module at its tier's default

Frame lookup is on Views & Frames; config and wording on Configuration & Wording.

A First Module

mkmod scaffolds a module into the site's modules/ folder, never into core/. The name is StudlyCaps and may not be one a bundled module has: an override of a bundled module is written by hand.

core/modules/Module/mkmod Weather

With no flags it writes Weather.php, view/index.php, assets/css/weather.css, assets/js/weather.js and a .gitignore. The module is on by default and answers at /weather on the next request. mkmod --help lists the flags for the optional directories.