Download the PHP package stillat/proteus without Composer
On this page you can find all versions of the php package stillat/proteus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stillat/proteus
More information about stillat/proteus
Files in stillat/proteus
Package proteus
Short Description Provides utilities for parsing and updating Laravel-style PHP configuration files.
License MIT
Informations about the package proteus
This library provides utilities and features for parsing, updating, and writing Laravel style PHP configuration files.
Installation
To install Proteus issue the following command, or at stillat/proteus
to your composer.json
file:
Basic Usage
The ConfigWriter
facade will automatically load and manage your existing Laravel configuration files, and dramatically simplifies the usage of the configuration writer:
You may also write many configuration items at once:
If you only want the document contents (without writing to disk), you may use the preview
and previewMany
counterparts:
Preventing Changes to Configuration Items
You may use the guard
method to prevent changes to specific configuration entries:
If a change is detected for app.key
, an instance of GuardedConfigurationMutationException
will be thrown.
You may also restrict changes on entire configuration namespaces:
Or to just a sub-section of the configuration:
Enabling Function Rewrites
Changes to function calls (such as env
) can are disabled by default. To enable them, you may call the ignoreFunctionCalls
method with false
:
Preserving Configuration Values
You may ignore certain configuration value updates by using the preserve
method. The preserve
method accepts an array of strings (dot notation is also supported!).
Intermediate Usage
For more control to remove, replace, and even merge array values with existing configuration values, we can use the edit
helper method. This helper method expects a configuration namespace, and returns access to a convenient wrapper to perform a variety of configuration changes.
In the following example, we will start an edit instance for the app
configuration namespace, modify a few values, and save the results to a $document
variable:
We can save ourselves some keystrokes by supplying a key/value pair to the set
method:
To save the changes instead of assigning them to a value, we can call save
instead of preview
:
Removing Existing Configuration Values
You may use the remove
method to remove an existing configuration item:
This method will also remove the configuration key from the configuration file - not just the value!
Replacing an Existing Configuration Value
You may use the replace
method to completely replace an existing configuration item:
Merging Array Configuration Items
You may use the merge
method to add new values to an existing configuration item. For example, the following would add the SomeProvider
and SomeOtherProvider
class providers to the list of application providers:
The merge
method will make sure there are no duplicates in the resulting configuration values.
Performing Multiple Actions
You may perform multiple actions at once by chaining them. Chained actions are performed in the order they are specified.
`
Writing Function Calls to Configuration Files
You may also write Laravel function calls as part of the generated configuration by using the f
helper method:
The configuration output would then be similar to the following:
The following functions are available:
Advanced Usage
Given the following input configuration file:
We can manually create a configuration updater and apply our changes manually:
After running, $newConfigContents
would contain output similar to the following:
And yes, it did add the new-key
value as the default value for the env
call instead of replacing the lookup key :)
Features
- Attempts to preserve most file formatting,
- Handles adding new simple keys,
- Handles adding new deeply nested keys,
- Allows for appending configuration files to an existing configuration array,
- Allows for overwriting configuration files in an existing configuration array,
- Simple
ConfigWriter
facade
Road Map
There will undoubtedly be changes required overtime, and if you find something not working, please open an issue with the input you are supplying and the expected results. Bonus points if you add a test case for it :)
License
MIT License. See LICENSE.MD