Local
in package
Uses
Singleton
This is a class that maintains values about the local environment and does error handling
Template rendering is done in here also so TWIG is initialised in this class. This allows TWIG to be used for things like generating nice offline pages.
Table of Contents
- ERROR = 0
- MESSAGE = 2
- WARNING = 1
- $instance : object
- The only instance of using class
- $basedname : string
- $basepath : string
- $devel : bool
- $errorHandler : ErrorHandler|null
- $fwconfig : array<, mixed>
- $messages : array<, array<, mixed>>
- $msgnames : array<, mixed>
- $tvals : array<, mixed>
- $twig : object|null
- addval() : void
- Add a value into the values stored for rendering the template
- adminOnly() : void
- Check to see if non-admin users are being excluded
- allconfig() : array<, mixed>
- Return all the config values
- assets() : string
- Return a path to the assets directory suitable for use in links
- assetsdir() : string
- Return a filesystem path to the assets directory
- base() : string
- Return the name of the directory for this site
- basedir() : string
- Return the path to the directory for this site
- clearMessages() : void
- Clear out messages
- config() : object|null
- Return a named config bean
- configval() : string
- Return a named config bean value
- debase() : string
- Remove the base component from a URL
- develMode() : bool
- Return state of devel flag
- eIgnore() : bool
- Allow system to ignore errors
- enabledebug() : void
- Put the system into debugging mode
- extendtwig() : void
- Calls a user defined function with the twig object as a parameter.
- getinstance() : object
- Checks, instantiates and returns the only instance of the using class.
- getrender() : string
- Render a twig and return the string - do nothing if the template is the empty string
- hastwig() : bool
- Return TRUE if Twig is enabled
- makebasepath() : string
- Join the arguments with DIRECTORY_SEPARATOR to make a path name and prepend the path to the base directory
- makepath() : string
- Join the arguments with DIRECTORY_SEPARATOR to make a path name
- message() : void
- Add a message into the messages stored for rendering the template
- render() : void
- Render a twig - do nothing if the template is the empty string
- sendmail() : string
- Send mail if possible
- setup() : Local
- Set up local information. Returns self
- setuptwig() : void
- Initialise twig template engine
Constants
ERROR
public
mixed
ERROR
= 0
MESSAGE
public
mixed
MESSAGE
= 2
WARNING
public
mixed
WARNING
= 1
Properties
$instance
The only instance of using class
protected
static object
$instance
= NULL
$basedname
private
string
$basedname
= ''
The name of the site directory
$basepath
private
string
$basepath
= ''
The absolute path to the site directory
$devel
private
bool
$devel
= FALSE
Developer mode?
$errorHandler
private
ErrorHandler|null
$errorHandler
= NULL
$fwconfig
private
array<, mixed>
$fwconfig
= []
Config values from database
$messages
private
array<, array<, mixed>>
$messages
= [[], [], []]
Stash away messages so that messages.twig works
$msgnames
private
static array<, mixed>
$msgnames
= ['fwerrmessage', 'fwwarnmessage', 'fwmessage']
Contains string names for the message constants - used for Twig variables
$tvals
private
array<, mixed>
$tvals
= []
Key/value array of data to pass into template renderer
$twig
private
object|null
$twig
= NULL
the Twig renderer
Methods
addval()
Add a value into the values stored for rendering the template
public
addval( $vname[, mixed $value = '' ][, bool $tglobal = FALSE ]) : void
Parameters
- $vname :
-
The name to be used inside the twig or an array of key/value pairs
- $value : mixed = ''
-
The value to be stored or "" if an array in param 1
- $tglobal : bool = FALSE
-
If TRUE add this as a twig global variable
Tags
Return values
void —adminOnly()
Check to see if non-admin users are being excluded
public
adminOnly(bool $admin) : void
Parameters
- $admin : bool
Return values
void —allconfig()
Return all the config values
public
allconfig() : array<, mixed>
Return values
array<, mixed> —assets()
Return a path to the assets directory suitable for use in links
public
assets() : string
Return values
string —assetsdir()
Return a filesystem path to the assets directory
public
assetsdir() : string
Return values
string —base()
Return the name of the directory for this site
public
base() : string
Return values
string —basedir()
Return the path to the directory for this site
public
basedir() : string
Return values
string —clearMessages()
Clear out messages
public
clearMessages([int|null $kind = NULL ]) : void
Parameters
- $kind : int|null = NULL
-
Either NULL for all messages or a specific kind
Return values
void —config()
Return a named config bean
public
config(string $name) : object|null
Parameters
- $name : string
-
The name of the item
Return values
object|null —configval()
Return a named config bean value
public
configval(string $name) : string
Parameters
- $name : string
-
The name of the item
Return values
string —debase()
Remove the base component from a URL
public
debase(string $url) : string
Note that this will fail if the base name contains a '#' character! The installer tests for this and issues an error when run.
Parameters
- $url : string
Return values
string —develMode()
Return state of devel flag
public
develMode() : bool
Return values
bool —eIgnore()
Allow system to ignore errors
public
eIgnore(bool $ignore) : bool
This always clears the wasignored flag
Parameters
- $ignore : bool
-
If TRUE then ignore the error otherwise stop ignoring
Return values
bool —The last value of the wasignored flag
enabledebug()
Put the system into debugging mode
public
enabledebug() : void
Tags
Return values
void —extendtwig()
Calls a user defined function with the twig object as a parameter.
public
extendtwig(callable $fn) : void
The user can then add extensions, filters etc.
Parameters
- $fn : callable
-
A user defined function
Return values
void —getinstance()
Checks, instantiates and returns the only instance of the using class.
public
static getinstance() : object
Tags
Return values
object —getrender()
Render a twig and return the string - do nothing if the template is the empty string
public
getrender(string $tpl[, array<, mixed> $vals = [] ]) : string
Parameters
- $tpl : string
-
The template
- $vals : array<, mixed> = []
-
Values to set for the twig
Return values
string —hastwig()
Return TRUE if Twig is enabled
public
hastwig() : bool
Return values
bool —makebasepath()
Join the arguments with DIRECTORY_SEPARATOR to make a path name and prepend the path to the base directory
public
makebasepath() : string
Return values
string —makepath()
Join the arguments with DIRECTORY_SEPARATOR to make a path name
public
makepath() : string
Return values
string —message()
Add a message into the messages stored for rendering the template
public
message(int $kind, $value) : void
The currently supported values for kind are :
\Framework\Local\ERROR
\Framework\Local\WARNING
\Framework\Local\MESSAGE
To have your Twig deal with these you need
{% include '@util/message.twig %}
somewhere in the relevant twig (usually at the top of the main body)
Parameters
- $kind : int
-
The kind of message
- $value :
-
The value to be stored or an array of values
Return values
void —render()
Render a twig - do nothing if the template is the empty string
public
render(string $tpl[, array<, mixed> $vals = [] ][, string $mimeType = Web::HTMLMIME ][, int $status = FrameworkWebStatusCodes::HTTP_OK ]) : void
Parameters
- $tpl : string
-
The template
- $vals : array<, mixed> = []
-
Values to set for the twig
- $mimeType : string = Web::HTMLMIME
- $status : int = FrameworkWebStatusCodes::HTTP_OK
Return values
void —sendmail()
Send mail if possible
public
sendmail(array<, string> $to, string $subject, string $msg[, string $alt = '' ][, array<, string> $other = [] ][, array<, string> $attach = [] ]) : string
Parameters
- $to : array<, string>
-
An array of people to send to.
- $subject : string
-
The subject
- $msg : string
-
The message - if $alt is not empty then this is assumed to be HTML.
- $alt : string = ''
-
The alt message - plain text
- $other : array<, string> = []
-
From, cc, bcc etc. etc.
- $attach : array<, string> = []
-
Any Attachments
Return values
string —setup()
Set up local information. Returns self
public
setup(string $basedir, bool $ajax, bool $devel, bool $loadtwig[, bool $loadrb = TRUE ]) : Local
The $loadrb parameter simplifies some of the unit testing for this class
Parameters
- $basedir : string
-
The full path to the site directory
- $ajax : bool
-
If TRUE then this is an AJAX call
- $devel : bool
-
If TRUE then we are developing the system
- $loadtwig : bool
-
If TRUE then load in Twig.
- $loadrb : bool = TRUE
-
If TRUE then load in RedBean
Return values
Local —setuptwig()
Initialise twig template engine
public
setuptwig([bool $cache = FALSE ]) : void
Parameters
- $cache : bool = FALSE
-
if TRUE then enable the TWIG cache