2017 © Pedro Peláez
 

library perm

Save array-return configuration files in Laravel 4.

image

andrewsuzuki/perm

Save array-return configuration files in Laravel 4.

  • Saturday, April 12, 2014
  • by andrewsuzuki
  • Repository
  • 1 Watchers
  • 1 Stars
  • 154 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

perm

Build Status Still Maintained, (*1)

perm offers a simple way to save and retrieve "native" php configuration files in the filesystem., (*2)

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., (*3)

Requirements

  • PHP 5.3+ or HHVM
  • Laravel 4
  • Composer

Installation

perm installs with Composer through Packagist., (*4)

Add the following to your composer.json:, (*5)

{
    "require": {
        "andrewsuzuki/perm": "dev-master",
    }
}

Then run composer update., (*6)

Now add the following to your providers array in config/app.php:, (*7)

'Andrewsuzuki\Perm\PermServiceProvider',

Now add the facade alias to the aliases array:, (*8)

'Perm' => 'Andrewsuzuki\Perm\Facades\Perm',

And that's it., (*9)

Configuration

If you'd like to load/save files from a base directory other than app/config, publish the package's configuration:, (*10)

php artisan config:publish hokeo/vessel

Then modify the basepath in app/config/packages/andrewsuzuki/perm/config.php., (*11)

Usage

  • Load a config file, or mark a non-existing file/directory for creation. chainable
// 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., (*12)

  • Get a config value.
$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
  • Get multiple values in one go (returns array).
$locationAndFirstName = $perm->get(array('location', 'name.first'));
// or...
list($location, $firstName) = $perm->get(array('location', 'name.first'));
  • Get all config values.
$config = $perm->all();
  • Set a value. chainable
$perm->set('timezone', 'UTC');
// for the first level, you can use magic properties
$perm->timezone = 'UTC';
  • Set a value if and only if it doesn't exist. chainable
$perm->setIf('timezone', 'UTC');
  • Set multiple values in one go. chainable
$perm->set(array('timezone' => 'UTC', 'location' => 'Earth'));
  • Check if a key exists.
$exists = $perm->has('location'); // true/false
$exists = $perm->has('name.first'); // true/false
  • Forget a key. chainable
$perm->forget('location');
  • Reset (forget all key/values). chainable
$perm->reset();
  • Save updated config. chainable
$perm->save();
  • Update current loaded filename (will not update loaded config). Filename basename must not contain dots. chainable
$perm->setFilename('/path/to/new/file');
// then you might set some more values, then call ->save() again, etc...

Method chaining

Chaining methods is an easy way to consolidate, and improve readability. You can combine any of the above methods marked as chainable. For example:, (*13)

Perm::load('profile.andrew')->set('name', 'Andrew')->forget('location')->save();

Contributors

To contribute, please fork and submit a pull request. Otherwise, feel free to submit possible enhancements/issues on the issues page., (*14)

License

Vessel is open-sourced software licensed under the MIT license, (*15)

The Versions

12/04 2014

dev-master

9999999-dev

Save array-return configuration files in Laravel 4.

  Sources   Download

MIT

The Requires

 

12/04 2014

v0.9

0.9.0.0

Save array-return configuration files in Laravel 4.

  Sources   Download

MIT

The Requires