Properties

$path

$path : string

Type

string — Absolute path of project.

$configDir

$configDir : string

Type

string — The configuration directory.

$cli

$cli : string

Type

string — Is CLI request

$app

$app : object

Type

object — Static reference to instance of App {@link \Disco\classes\App}.

$defaultMatchCondition

$defaultMatchCondition : array

Type

array — Default regex matching conditions.

$config

$config : array

Type

array — Application configuration variables.

$alias

$alias : array

Type

array — Application aliases.

$domain

$domain : string

Type

string — The domain name of the current application.

$maintenance

$maintenance : string

Type

string — The PHP file path relative to the root of the app that should be executed when in maintenance mode.

$log

$log : string

Type

string — The log file the `log()` function writes to.

Methods

instance()

instance(null|string  $path = null, null|string  $domain = null) : \Disco\classes\App

Get the application instance singleton {@link \Disco\classes\App}.

Parameters

null|string $path

Absolute path to root of the project.

null|string $domain

The domain name the app is serving.

Returns

\Disco\classes\App

__construct()

__construct(null|string  $path = null, null|string  $domain = null) 

Set up the application path, domain, configs, services, factories,

Parameters

null|string $path

Absolute path to root of the project.

null|string $domain

The domain name the app is serving.

setUp()

setUp() : void

Set up some basic ini settings, the domain, running console commands if CLI, maintenance mode screen, and forcing requests to be HTTPS if necessary.

tearDown()

tearDown() : void

Make sure a \Disco\classes\Router matched against the requested URI, and serve the necessary page.

registerConfig()

registerConfig(array|string  $config) : boolean

Merge a configuration file with the current app configuration.

Parameters

array|string $config

Either an array of configs, or a path to a config definition file that returns an array.

Returns

boolean —

Was it registered.

config()

config(string  $name, mixed  $value = null) : false|mixed

Get/Set a config value.

Parameters

string $name

Configuration setting to touch.

mixed $value

The value to set.

Throws

\Exception

If the config key doesn't exist.

Returns

false|mixed —

False if not set, the value otherwise.

configKeyExists()

configKeyExists(string  $name) : boolean

Whether a configuration key exists. Use this if you dont want to catch an Exception thrown by `$this->config()` when a passed configuration key doesn't exist.

Parameters

string $name

Configuration key.

Returns

boolean

devMode()

devMode() : boolean

Whether the application is running in dev mode.

Returns

boolean

path()

path() : string

Return the root working system path of the discophp project.

Returns

string

domain()

domain() : string

Get the current fully qualified domain name. eg: `https://yoursite.com`.

Returns

string

registerAlias()

registerAlias(string  $name, string  $path) : void

Register an alias. Aliases should adhere to the convention `your.alias`.

Parameters

string $name

The alias name (key).

string $path

The alias path (value).

getAlias()

getAlias(string  $name) : string

Get a previously registerd alias.

Parameters

string $name

The alias name (key).

Returns

string

resolveAlias()

resolveAlias(string  $path) : boolean|string

Resolve a path that uses an alias that has been registered. Aliases are resolved by using the syntax `@your.alias:the/rest/of/your/path/to/file.ext` where `@your.alias:` was defined earlier by registering `your.alias`.

Parameters

string $path

The aliased path.

Returns

boolean|string —

False if no alias, the resolved alias path otherwise.

registerCondition()

registerCondition(string  $k, string  $v) : void

Add a default matching condition for use with Router and Data. Store the $k and $v in $this->defaultMatchConditions .

Parameters

string $k

The conditions key.

string $v

The conditions regex value.

getCondition()

getCondition(string  $k) : string

Get a matching condition.

Parameters

string $k

The conditions key.

Returns

string

matchCondition()

matchCondition(string  $k, mixed  $v) : boolean

Match a registered condition against a value.

Parameters

string $k

The condition key.

mixed $v

The value to test the condition against.

Returns

boolean —

The condition passed.

registerServices()

registerServices(array|string  $services) : boolean

Register services into the application container. If the service already exists, it will be extended.

Parameters

array|string $services

Either an array of services, or a path to a services definition file that returns an array.

Returns

boolean —

Were the services registered.

registerFactories()

registerFactories(array|string  $factories) : boolean

Register services as factories into the application container.

Parameters

array|string $factories

Either an array of factories, or a path to a factories definition file that returns an array.

Returns

boolean —

Were the factories registered.

with()

with(string  $obj) : Object

Get a service from the container.

Parameters

string $obj

The service to get from the container.

Returns

Object

make()

make(string  $obj, string|\Closure  $val) : void

Register a standard service with the container.

Parameters

string $obj

The service to register.

string|\Closure $val

The object name or \Closure function to be created or evaluated.

extend()

extend(string  $obj, string|\Closure  $val) : void

Overwrite an existing service in the application container with a new service.

Parameters

string $obj

The service to register.

string|\Closure $val

The object name or \Closure function to be created or evaluated.

makeFactory()

makeFactory(string  $obj, string|\Closure  $val) : void

Register a factory service with the container.

Parameters

string $obj

The factory service to register.

string|\Closure $val

The object name or \Closure function to be created or evaluated.

makeProtected()

makeProtected(string  $obj, string|\Closure  $val) 

Register a protected service ( a Class with __call() defined or a \Closure function).

Parameters

string $obj

The protected service to register.

string|\Closure $val

The object name or \Closure function to be created or evaluated.

handle()

handle(string  $key, string  $method, array  $args) : mixed

Call a method ($method) on a service defined by $key in the container with arguements $args.

Parameters

string $key

The service to call the method on.

string $method

The method to call on the service.

array $args

The arguements to pass to $key->$method();

Returns

mixed

handleMaintenance()

handleMaintenance() : void

When MAINTENANCE_MODE=true in config.php the application is in maintenance mode and the \Closure function returned from app/maintenance.php should be executed.

error()

error(string  $msg, string|Array  $methods, Array  $e) : void

Stack trace a Disco error and log it.

Parameters

string $msg

The error message to log.

string|Array $methods

The method call names that could have generated the error.

Array $e

The debug_stacktrace call.

log()

log(mixed  $msg) : void

Log an error in the log file defined by `$this->log` if it exists, also log the message in the standard log called by `error_log()`.

Parameters

mixed $msg

The error to log, if not a string or numeric will be var exported.

resolveDependencies()

resolveDependencies(string  $v) : Object

When constructing services (objects) in the container determine whether or not the constructor is requesting other services from the container as arguements.

If it is then we need to resolve those services from the container and pass them in.

Parameters

string $v

The service that is about to be instantiated.

Returns

Object