Package Data | |
---|---|
Maintainer Username: | andrewsuzuki |
Package Create Date: | 2014-04-11 |
Package Last Update: | 2014-04-12 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:03:31 |
Package Statistics | |
---|---|
Total Downloads: | 164 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
perm offers a simple way to save and retrieve "native" php configuration files in the filesystem.
For example, if writing a cms like Vessel, you might want to save fast configuration values (like a site title or url) perm-anently from an admin interface. This is easy with perm.
perm installs with Composer through Packagist.
Add the following to your composer.json:
{
"require": {
"andrewsuzuki/perm": "dev-master",
}
}
Then run composer update
.
Now add the following to your providers
array in config/app.php:
'Andrewsuzuki\Perm\PermServiceProvider',
Now add the facade alias to the aliases
array:
'Perm' => 'Andrewsuzuki\Perm\Facades\Perm',
And that's it.
If you'd like to load/save files from a base directory other than app/config, publish the package's configuration:
php artisan config:publish hokeo/vessel
Then modify the basepath in app/config/packages/andrewsuzuki/perm/config.php.
// dot notation from base path (see above for configuration)
$perm = Perm::load('profile.andrew');
// ...or absolute path (no extension)
$perm = Perm::load('/path/to/file');
If the file's directory does not exist, it will be created.
$location = $perm->get('location');
$location = $perm->location; // for the first level, you can use magic properties
$first_name = $perm->get('name.first'); // use dot notation for nested values
$locationAndFirstName = $perm->get(array('location', 'name.first'));
// or...
list($location, $firstName) = $perm->get(array('location', 'name.first'));
$config = $perm->all();
$perm->set('timezone', 'UTC');
// for the first level, you can use magic properties
$perm->timezone = 'UTC';
$perm->setIf('timezone', 'UTC');
$perm->set(array('timezone' => 'UTC', 'location' => 'Earth'));
$exists = $perm->has('location'); // true/false
$exists = $perm->has('name.first'); // true/false
$perm->forget('location');
$perm->reset();
$perm->save();
$perm->setFilename('/path/to/new/file');
// then you might set some more values, then call ->save() again, etc...
Chaining methods is an easy way to consolidate, and improve readability. You can combine any of the above methods marked as chainable. For example:
Perm::load('profile.andrew')->set('name', 'Andrew')->forget('location')->save();
To contribute, please fork and submit a pull request. Otherwise, feel free to submit possible enhancements/issues on the issues page.
Vessel is open-sourced software licensed under the MIT license