PHP code example of anekdotes / meta

1. Go to this page and download the library: Download anekdotes/meta 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/ */

    

anekdotes / meta example snippets


use Anekdotes\Meta\Registry
$registry = new Registry();
$registry->load(["toaster.test" => "Test","toaster.toast" => "Toast","testing.test" => "Tested"]);
$registry->get("testing.test"); //Returns "Tested"
$registry->group("toaster"); //Returns ["test" => "Test","toast" = "Toast"]
$registry->has("testing.test"); //Checks if key exists. Returns true.

use Anekdotes\Meta\StaticRegistry
StaticRegistry::load(["toaster.test" => "Test"]);

use Anekdotes\Meta\Config
$config = new Config();
$path = "app/config/config.php";
$config->loadFile($path);

$config = new Config();
$path = "app/config";
$config->loadFolder($path);



return array(
    'dummy' => 'dummy.php',
    'test' => 'test.php',
);

$config->get("dummy"); //Returns "dummy.php"

$config = new Config();
$path = "app/config/config.php";
$prefix = true;
$namespace = "Meta";
$config->loadFile($path,$prefix,$namespace);
$config->all(); //This will return ["Meta::config.dummy" => "dummy.php","Meta::config.test","test.php"];

use Anekdotes\Meta\Dispatcher;
$functionThatWillGetFired = function(){
    echo "Hello world!";
}
$otherFunctionThatWillBeFired = function(){
    echo "I am fabulous.";
}
$dispatcher = new Dispatcher();
$dispatcher->listen('call',$functionThatWillGetFired);
$dispatcher->listen('call',$otherFunctionThatWillBeFired);
$dispatcher->fire('call'); //Will echo both "Hello world" and "I am fabulous"
$dispatcher->flush('call'); //Removes all listeners associated to the event "call"

use Anekdotes\Meta\ObjectArrayActionDispatcher;
$registry1 = new Registry();
$registry1->load(['Test' => 'Tests','Toast' => 'Toasts']);  
$registry2 = new Registry();
$registry2->load(['Test' => 'Nope','Toast' => 'Nope']);
$dispatcher = new ObjectArrayActionDispatcher([$registry1,$registry2]);
$dispatcher->set('Test','SuperTest'); //This calls the function SET on both registry objects, passing the parameters "Test" and "SuperTest."
$registry1->all(); //Now returns ['Test' => 'SuperTest', 'Toast' => 'Toasts']
$registry2->all(); //Now returns ['Test' => 'SuperTest', 'Toast' => 'Nope']