ProjectConfig
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\ProjectConfig
- Since
- 3.1.0
Class ProjectConfig
View source (opens new window)
# Public Methods
Method | Description |
---|---|
cleanupConfig() | Traverse and clean a config array, removing empty values and sorting keys. |
diff() | Returns a diff of the pending project config YAML changes, compared to the currently loaded project config. |
encodeValueAsString() | Returns a project config compatible value encoded for storage. |
ensureAllFieldsProcessed() | Ensures all field config changes are processed immediately in a safe manner. |
ensureAllFilesystemsProcessed() | Ensures all filesystem config changes are processed immediately in a safe manner. |
ensureAllGqlSchemasProcessed() | Ensure all GraphQL schema config changes are processed immediately in a safe manner. |
ensureAllSectionsProcessed() | Ensure all section config changes are processed immediately in a safe manner. |
ensureAllSitesProcessed() | Ensure all site config changes are processed immediately in a safe manner. |
ensureAllUserGroupsProcessed() | Ensure all user group config changes are processed immediately in a safe manner. |
flattenConfigArray() | Flatten a config array to a dot.based.key array. |
lastPathSegment() | Returns the last segment in a given project config path. |
packAssociativeArray() | Prepares an associative array for storage in project config, so that the order of its items will be remembered. |
packAssociativeArrays() | Loops through an array, and prepares any nested associative arrays for storage in project config, so that the order of its items will be remembered. |
pathSegments() | Returns an array of the individual segments in a given project config path. |
pathWithoutLastSegment() | Returns the given project config path with all but its last segment, or null if the path only had one segment. |
reset() | Resets the static memoization variables. |
splitConfigIntoComponents() | Take a project config array and split it into components. |
touch() | Updates the dateModified value in config/project/project.yaml . |
traverseDataArray() | Traverse a nested data array according to path and perform an action depending on parameters. |
unpackAssociativeArray() | Restores an array that was prepared via packAssociativeArray() to its original form. |
unpackAssociativeArrays() | Loops through an array, and restores any arrays that were prepared via packAssociativeArray() to their original form. |
# cleanupConfig()
- Since
- 3.1.14
Traverse and clean a config array, removing empty values and sorting keys.
View source (opens new window)
Arguments
$config
(array (opens new window)) – Config array to clean
Returns
Throws
- yii\base\InvalidConfigException (opens new window)
if config contains unexpected data.
# diff()
- Since
- 3.5.6
Returns a diff of the pending project config YAML changes, compared to the currently loaded project config.
View source (opens new window)
Arguments
$invert
(boolean (opens new window)) – Whether to reverse the diff, so the loaded config is treated as the source of truth
Returns
# encodeValueAsString()
- Since
- 4.0.0
Returns a project config compatible value encoded for storage.
View source (opens new window)
Arguments
$value
(mixed
)
Returns
# ensureAllFieldsProcessed()
Ensures all field config changes are processed immediately in a safe manner.
View source (opens new window)
# ensureAllFilesystemsProcessed()
- Since
- 4.1.2
Ensures all filesystem config changes are processed immediately in a safe manner.
View source (opens new window)
# ensureAllGqlSchemasProcessed()
Ensure all GraphQL schema config changes are processed immediately in a safe manner.
View source (opens new window)
# ensureAllSectionsProcessed()
- Since
- 4.0.0
Ensure all section config changes are processed immediately in a safe manner.
View source (opens new window)
# ensureAllSitesProcessed()
Ensure all site config changes are processed immediately in a safe manner.
View source (opens new window)
Arguments
$force
(boolean (opens new window)) – Whether to proceed even if YAML changes are not currently being applied
# ensureAllUserGroupsProcessed()
Ensure all user group config changes are processed immediately in a safe manner.
View source (opens new window)
# flattenConfigArray()
- Since
- 3.4.0
Flatten a config array to a dot.based.key array.
View source (opens new window)
Arguments
$array
(array (opens new window))$path
(string (opens new window))$result
(array (opens new window))
# lastPathSegment()
- Since
- 3.7.44
Returns the last segment in a given project config path.
View source (opens new window)
Arguments
$path
(string (opens new window))
Returns
string (opens new window), null (opens new window)
Throws
- yii\base\InvalidArgumentException (opens new window)
if$path
is an empty string
# packAssociativeArray()
- Since
- 3.4.0
Prepares an associative array for storage in project config, so that the order of its items will be remembered.
TIP
Use unpackAssociativeArray() to restore the array to its original form when fetching the value from the Project Config.
View source (opens new window)
Arguments
$array
(array (opens new window))$recursive
(boolean (opens new window)) – Whether to process nested associative arrays as well
Returns
Example
$myArray = [
'foo' => 1,
'bar' => 2,
];
// "Pack" the array so it doesn't get reordered to [bar=>2,foo=>1]
$packedArray = \craft\helpers\ProjectConfig::packAssociativeArray($myArray);
Craft::$app->projectConfig->set($configKey, $packedArray);
# packAssociativeArrays()
- Since
- 3.4.0
Loops through an array, and prepares any nested associative arrays for storage in project config, so that the order of its items will be remembered.
View source (opens new window)
Arguments
$array
(array (opens new window))$recursive
(boolean (opens new window)) – Whether to process nested associative arrays as well
Returns
# pathSegments()
- Since
- 3.7.44
Returns an array of the individual segments in a given project config path.
View source (opens new window)
Arguments
$path
(string (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if$path
is an empty string
# pathWithoutLastSegment()
- Since
- 3.7.44
Returns the given project config path with all but its last segment, or null
if the path only had one segment.
View source (opens new window)
Arguments
$path
(string (opens new window))
Returns
string (opens new window), null (opens new window)
Throws
- yii\base\InvalidArgumentException (opens new window)
if$path
is an empty string
# reset()
Resets the static memoization variables.
View source (opens new window)
# splitConfigIntoComponents()
- Since
- 3.5.0
Take a project config array and split it into components.
Components are defined per each second-level config entry, where all the sibling entries are keyed by UIDs.
View source (opens new window)
Arguments
$config
(array (opens new window))
Returns
array (opens new window) – In the form of [$file => $config], where $file
is the relative config file path in Project Config folder
# touch()
- Since
- 3.5.14
Updates the dateModified
value in config/project/project.yaml
.
If a Git conflict is detected on the dateModified
value, a conflict resolution will also be attempted.
View source (opens new window)
Arguments
$timestamp
(integer (opens new window), null (opens new window)) – The updateddateModified
value. Ifnull
, the current time will be used.
# traverseDataArray()
- Since
- 4.0.0
Traverse a nested data array according to path and perform an action depending on parameters.
View source (opens new window)
Arguments
$data
(array (opens new window)) – A nested array of data to traverse$path
(string (opens new window), string (opens new window)[]) – Path used to traverse the array. Either an array or a dot.based.path$value
(mixed
) – Value to set at the destination. If null, will return the value, unless deleting$delete
(boolean (opens new window)) – Whether to delete the value at the destination or not.
Returns
mixed
# unpackAssociativeArray()
- Since
- 3.4.0
Restores an array that was prepared via packAssociativeArray() to its original form.
View source (opens new window)
Arguments
$array
(array (opens new window))$recursive
(boolean (opens new window)) – Whether to process nested associative arrays as well
Returns
# unpackAssociativeArrays()
- Since
- 3.4.0
Loops through an array, and restores any arrays that were prepared via packAssociativeArray() to their original form.
View source (opens new window)
Arguments
$array
(array (opens new window))