Download the PHP package dana/shellconf without Composer
On this page you can find all versions of the php package dana/shellconf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dana/shellconf
More information about dana/shellconf
Files in dana/shellconf
Package shellconf
Short Description Shell-style config-file encoder/decoder
License MIT
Homepage https://github.com/okdana/shellconf
Informations about the package shellconf
\Dana\ShellConf
\Dana\ShellConf
is a PHP project which provides methods for parsing and
manipulating shell-style (specifically bash-style) variable assignments, which
can be useful for simple configuration needs. (But see Rationale below.)
Usage
Install via Composer:
Given a config.sh
like this:
And a config.php
like this:
php config.php
produces:
Useful methods:
load($file)
— Load config file$file
parse($string)
— Parse config string$string
reset()
— Reset any loaded variables betweenparse()
callsset($name, $value)
— Create and set variable$name
to$value
unset($name)
— Unset variable$name
get($name, $default)
— Get the value of variable$name
toArray()
— Get all loaded variables and their values as an arraytoString()
— Get all loaded variables and their values as a bash-compatible config string (to write to a file for example)
Rationale
This project is extremely similar to a number of others designed to read 'dotenv' files, but i had some specific goals in mind that didn't necessarily align with theirs:
-
Most of them are focussed on loading files into environment variables, which isn't what i needed. I just want to parse the file, and maybe write it back.
-
Some of them don't seem to handle escaping and unescaping in exactly the same way as bash.
-
Many of them are overly clever for my purposes, supporting things like bash-incompatible extensions, variable interpolation, even command substition, which i don't want.
- I was interested in some finer-grained methods related to escaping as well as writing bash-compatible lines back out.
For all of those reasons, i decided to write my own implementation. But if you don't care about any of that, you should absolutely check out one of these, much more widely used, projects:
To do
More tests.