API Documentation for: 1.1.1
Show:

Site Class

Namespace: Canteen

This is the main class of the framework that needs to be implemented in order to use. Canteen is a backend which provides a JSON server, Database connect, template engine, User authentication and many other features for building very dynamic data-driven websites.

// Externally load the deployment settings from a PHP file (default)
$site = new Canteen\Site('config.php');

// Or set the single deployment settings directly
$site = new Canteen\Site([
    'dbUsername' => 'user',
    'dbPassword' => 'pass1234',
    'dbName' => 'my_settingsbase',
]);

 // Or create different deployments of the site
// for different domains where the site is hosted
$site = new Canteen\Site([
    // our local site accessible from http://localhost
    [
        'level' => DeploymentStatus::LOCAL,
        'domain' => 'localhost',
        'dbUsername' => 'root',
        'dbPassword' => '',
        'dbName' => 'my_settingsbase',
        'debug' => true
    ],
    // Our dev site accessible from http://dev.example.com
    [
        'level' => DeploymentStatus::DEV,
        'domain' => 'dev.example.com',
        'dbUsername' => 'user',
        'dbPassword' => 'pass1234',
        'dbName' => 'my_dev_settingsbase',
        'debug' => true
    ],
    // Our live site accessible from http://example.com
    [
        'level' => DeploymentStatus::LIVE,
        'domain' => 'example.com',
        'dbUsername' => 'user',
        'dbPassword' => 'pass1234',
        'dbName' => 'my_settingsbase',
        'minify' => true,
        'compress' => true,
        'cacheEnabled' => true
    ]
 ]);

// Echo out the page result
$site->render();

Constructor

Site

(
  • [settings='config.php']
  • [callerPath=null]
)

Parameters:

  • [settings='config.php'] String | Array | Dictionary optional

    The path to the settings PHP, the collection of deployment settings, or the single deployment dictionary.

    • dbUsername String

      The username for the database

    • dbPassword String

      The password for the database

    • dbName String | Dictionary

      The name of the database or collection of aliases and databases ('default' is required)

    • [dbHost='localhost'] String optional

      The name of the database host

    • [level=DeploymentStatus::LIVE] Int optional

      The deployment level of the site, see DeploymentStatus class for more info

    • [domain='*'] Array | String optional

      Single domain or collection of domains acceptable for this deployment to run

    • [debug=false] Boolean optional

      The debug mode

    • [cacheEnabled=false] Boolean optional

      If the cache is enabled

    • [compress=false] Boolean optional

      If the site should be compressed with gzip

    • [minify=false] Boolean optional

      If the output page should be minified

    • [cacheDirectory=null] String optional

      The directory for storing file cache if Memcache isn't available

  • [callerPath=null] String optional

    The path to the root script of the site, useful if we are inheriting this class.

Methods

addController

(
  • pageUri
  • controllerClassName
)

Store a page user function call for dynamic pages

Parameters:

  • pageUri String | RegExp | Array

    The page ID of the dynamic page (array for multiple items) or can be an regular expression

  • controllerClassName String

    The user class to call

addSetting

(
  • name
  • value
  • [client=true]
  • [renderable=true]
)

Set the configuration setting

Parameters:

  • name String

    The name of the item to set

  • value String

    The value to set

  • [client=true] Boolean optional

    If the setting should be added to the global client JS settings

  • [renderable=true] Boolean optional

    If the setting can be rendered

errorHandler

(
  • e
)

Handle PHP errors, like wrong argument counts

Parameters:

  • e Exception

    The caught exception

fatalError

(
  • e
)

Create a fatalError

Parameters:

  • e Exception

    The caught exception

getController

(
  • pageUri
)
Controller

Get a page controller by uri

Parameters:

  • pageUri String

    The uri of the page

Returns:

Controller:

The controller matching the URI

instance

() Canteen static

Get the singleton instance

Returns:

Canteen:

The singleton instance of ServerCache

isDatabaseUpdated

(
  • variableName
  • targetVersion
  • updatesFolder
)

Check to make sure the database is up-to-date

Parameters:

  • variableName String

    The name of the config variable

  • targetVersion String

    The target version the database should be at

  • updatesFolder String

    The folder containing the update scripts

render

(
  • [capture=false]
)
String

Get the current page markup, echoes on the page

Parameters:

  • [capture=false] Boolean optional

    If we should return the page render (false) or echo (true)

Returns:

String:

If capture is true, return the page render as a string

requiresVersion

(
  • required
)

Check that a version of Canteen is required to run

Parameters:

  • required String

    The least required version to run

setup

(
  • settings
)
private

Finish setting up the site

Parameters:

  • settings String | Array | Dictionary

    The deployment json settings path

Properties

_controllers

Array private

The dynamic page controllers with keys 'uri' and 'controller'

_instance

Canteen private static

The singleton instance

browserUri

String

The uri name for the service browser

Default: browser

cache

ServerCache

The instance of the server cache

db

Database

The instance of the database for fetching data using SQL

DB_VERSION

String final static

The current database version

formFactory

FormFactory

The form factory handles the processing of form POST requests

gateway

Gateway

The Gateway is used for client connection to services or other data

logoutUri

String

The logout uri

Default: logout

MAIN_TEMPLATE

String final static

The name of the main site template alias

MIN_PHP_VERSION

String final static

The minimum PHP version required to run termite

parser

Parser

The template parser

// Add a template to the site
$site->parser->addTemplate('Footer', 'Templates/Footer.html');

// Or add a JSON manifest with an array of template files
 $site->parser->addManifest('templates.json');

profiler

Profiler

The Profiler is use for debugging performance issues, SQL speed

settings

SettingsManager

The site configuration an associative array in key => value pairs

startTime

Int

The starting time to keep track of buildtime

user

Authorization

The user authorization object, deals with login and session

VERSION

String final static

The current version of the Canteen site