PHP code example of noflash / waffer

1. Go to this page and download the library: Download noflash/waffer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

noflash / waffer example snippets

 php
$myAwesomeConfiguration = array(
    'version' => 1.1, //This is global configuration option
    'yummyWaffers' => 10,
    'ACME\FooBar' => array( //Configuration for "FooBar" library by ACME
        'version' => M_PI,
        'bakingTemp' => 280,
        'defaultOwner' => 'Mr. Foo'
    )
);

$config = new DietWaffer($myAwesomeConfiguration); //We don't need full Waffer for options below

//Basic usage
echo "Global version: ".$config->storage['version']."\n"; //Fastest but completly non-OO

$config->setVersion(1.2); //Magic setter
echo "New global version: ".$config->getVersion()."\n"; //...with magic getter

$config->yummyWaffers++; //You can also use magic property set
echo "No. of yummy waffers: ".$config->yummyWaffers."\n"; //...and get

//Namespaces
echo "ACME FooBar version: ".$config->storage['ACME\FooBar']['version']."\n";

$config->setVersion(3.1, 'ACME\FooBar'); //Magic setter
echo "New ACME FooBar version: ".$config->getVersion('ACME\FooBar')."\n"; //...with magic getter


//Removing variables
unset($config->yummyWaffers);

//Checking if variable exists
var_dump(
    isset($config->version),
    isset($config->yummyWaffers),
    isset($config->notin)
);

//Let's drive OO teachers crazy ;]
var_dump(
    $config(),
    $config('ACME\FooBar')
);
 php
$config = new Waffer($myAwesomeConfiguration);

echo "JSON: ".$config->toJSON()."\n";
echo "Serialized: ".$config->serialize()."\n";
echo "Save to file ".print_r($config->toFile("example.conf"), true)."\n"; //This will save JSON file, you can pass Waffer::FORMAT_SERIAL to use serialization
//You can use fromFile() the same way
echo "PHP array: \n".$config."\n";
 php
namespace ACME\FooBar;

class FooBar {
    public static $defaultConfigutation = array(
        "welecome" => "Hello %s!"
        "funFacts" => array(
            "There's disease named Maple syrup urine disease",
            "Defibrillated patient isn't going to jump out of the bed (unless you're in Hollywood)"
        )
    );
    
    private $config;
    
    public function __construct(DietWaffer $config) {
        $this->config = $config;
        $this->config->storage[__NAMESPACE__] = array_replace_recursive(self::$defaultConfigutation, (array)@$this->config->storage[__NAMESPACE__]); 
    }
}