Class fusionary\craftcms\bootstrap\Bootstrap

Inheritancefusionary\craftcms\bootstrap\Bootstrap

Craft CMS bootstrap

Use this class in your entry script (index.php) to bootstrap your app.

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$appTypes array Valid application type. fusionary\craftcms\bootstrap\Bootstrap
$depth integer Depth of running script from project root. fusionary\craftcms\bootstrap\Bootstrap
$instance fusionary\craftcms\bootstrap\Bootstrap Singleton instance. fusionary\craftcms\bootstrap\Bootstrap

Public Methods

Hide inherited methods

MethodDescriptionDefined By
define() Gracefully define a PHP constant. fusionary\craftcms\bootstrap\Bootstrap
getApp() Get the bootstrapped app. fusionary\craftcms\bootstrap\Bootstrap
loadDotEnv() Apply environment variables from a .env file and defines CRAFT_ENVIRONMENT constant. fusionary\craftcms\bootstrap\Bootstrap
run() Run the app. fusionary\craftcms\bootstrap\Bootstrap
setDepth() Set depth from project root fusionary\craftcms\bootstrap\Bootstrap
setSite() Define the CRAFT_SITE constant fusionary\craftcms\bootstrap\Bootstrap

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
getInstance() Get instance statically. fusionary\craftcms\bootstrap\Bootstrap

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
APP_TYPE_CONSOLE 'console' fusionary\craftcms\bootstrap\Bootstrap
APP_TYPE_WEB 'web' fusionary\craftcms\bootstrap\Bootstrap

Property Details

$appTypes protected static property
protected static array $appTypes = [self::APP_TYPE_WEB, self::APP_TYPE_CONSOLE]
$depth protected static property

Depth of running script from project root.

protected static integer $depth = 1
$instance protected static property

Singleton instance.

Method Details

define() public static method

Gracefully define a PHP constant.

public static fusionary\craftcms\bootstrap\Bootstrap define ( \fusionary\craftcms\bootstrap\string $name, $value )
$name string
$value mixed
getApp() public static method

Get the bootstrapped app.

public static \yii\base\Application getApp ( \fusionary\craftcms\bootstrap\string $type )
$type string

One of $appTypes.

getInstance() protected static method

Get instance statically.

protected static fusionary\craftcms\bootstrap\Bootstrap getInstance ( )
loadDotEnv() public static method

Apply environment variables from a .env file and defines CRAFT_ENVIRONMENT constant.

Fails silently if:

  • .env file is not found (e.g. in production).
  • CRAFT_ENVIRONMENT is already defined.
public static fusionary\craftcms\bootstrap\Bootstrap loadDotEnv ( \fusionary\craftcms\bootstrap\string $path, \fusionary\craftcms\bootstrap\string $fileName = '.env', $logExceptions = false )
$path string

Path to directory containing env file

$fileName string

Filename of env file

$logExceptions boolean

Log exceptions with error_log

run() public method

Run the app.

public integer run ( \fusionary\craftcms\bootstrap\string $type = self::APP_TYPE_WEB )
$type string

One of $appTypes, deaults to 'web'.

return integer

The exit status

setDepth() public static method

Set depth from project root

public static fusionary\craftcms\bootstrap\Bootstrap setDepth ( \fusionary\craftcms\bootstrap\int $depth )
$depth integer
setSite() public static method

Define the CRAFT_SITE constant

public static fusionary\craftcms\bootstrap\Bootstrap setSite ( \fusionary\craftcms\bootstrap\string $handle )
$handle string

Site handle