Coder Social home page Coder Social logo

fluf's Introduction

Fluf

Fluf is a small wrapper for Community that allows you to configure a YAML file to predefine static properties by dynamically calling setters within your class.

  • PSR-0 compliant
  • Easy to use
  • Stable

Dependencies

  • Outglow\Community
  • Symfony\Yaml

Installation

Add outglow/fluf to your composer.json file

{
    "require" : {
        "outglow/fluf" : "dev-master"
    }
}

Then run: php composer.phar install (NOTE: An update may be required first)

Usage

Here we will autoload both Community and Fluf into our project:

include('vendor/autoload.php');

use Outglow\Component\Community\Community;
use Outglow\Component\Fluf\Fluf;

$community = new Fluf(new Community());

$community->set('Facebook', function() {
    return new Facebook();
});

Here, we have just used Community like it normally works, and for the example, we are loading some sort of Facebook SDK class. But for something like that, we'd need need predefined properties, such as an AppID or an App Secret. With Fluf, we can do that by using a YAML file for our configuration.

app_id: YOURAPPID
app_secret: YOURAPPSECRET

For the example, let's say we call this facebook.yml and store it in the root of our project. To load it in, we'd do the following:

include('vendor/autoload.php');

use Outglow\Component\Community\Community;
use Outglow\Component\Fluf\Fluf;

$community = new Fluf(new Community());

$community->prepare(function()
    return array(
        'key'  => 'Facebook',
        'data' => function() {
            return new Facebook();
        },
        'configuration' => 'facebook.yml'
    );
});

So providing that in our Facebook class we had the methods setAppId and setAppSecret, our YAML file can store the values for those, and when the object is created using Community, those methods will be run automaticly.

You can still use Community how you normally would, with the set, get and remove methods available for you.

prepare is the only new public method so far that Fluf allows us to use along-side Community.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.