Craft

Type
Class
Inherits
Craft » Yii
Since
3.0.0

Craft is helper class serving common Craft and Yii framework functionality.

It encapsulates \Yii and ultimately yii\BaseYii (opens new window), which provides the actual implementation.

View source (opens new window)

# Public Methods

Method Description
autoload() Class autoloader.
cookieConfig() Generates and returns a cookie config.
createGuzzleClient() Creates a Guzzle client configured with the given array merged with any default values in config/guzzle.php.
dd() Displays a variable and ends the request. (“Dump and die”)
dump() Displays a variable.
parseEnv() Checks if a string references an environment variable ($VARIABLE_NAME) and/or an alias (@aliasName), and returns the referenced value.

# autoload()

Class autoloader.

View source (opens new window)

Arguments

# cookieConfig()

Generates and returns a cookie config.

View source (opens new window)

Arguments

Returns

array (opens new window) – The cookie config array.

# createGuzzleClient()

Creates a Guzzle client configured with the given array merged with any default values in config/guzzle.php.

View source (opens new window)

Arguments

Returns

\GuzzleHttp\Client

# dd()

Displays a variable and ends the request. (“Dump and die”)

View source (opens new window)

Arguments

  • $var (mixed) – The variable to be dumped.
  • $depth (integer (opens new window)) – The maximum depth that the dumper should go into the variable. Defaults to 10.
  • $highlight (boolean (opens new window)) – Whether the result should be syntax-highlighted. Defaults to true.

Throws

# dump()

Displays a variable.

View source (opens new window)

Arguments

  • $var (mixed) – The variable to be dumped.
  • $depth (integer (opens new window)) – The maximum depth that the dumper should go into the variable. Defaults to 10.
  • $highlight (boolean (opens new window)) – Whether the result should be syntax-highlighted. Defaults to true.

# parseEnv()

Since
3.1.0

Checks if a string references an environment variable ($VARIABLE_NAME) and/or an alias (@aliasName), and returns the referenced value.

If the string references an environment variable with a value of true or false, a boolean value will be returned.

View source (opens new window)

Arguments

Returns

string (opens new window), boolean (opens new window), null (opens new window) – The parsed value, or the original value if it didn’t reference an environment variable and/or alias.

Example

$value1 = Craft::parseEnv('$SMTP_PASSWORD');
$value2 = Craft::parseEnv('@webroot');

# Constants

Constant Description
Client
Personal
Pro
Solo