2017 © Pedro PelĂĄez
 

library meta

Contains utility classes meant to reference themselves and manipulate events/storage

image

anekdotes/meta

Contains utility classes meant to reference themselves and manipulate events/storage

  • Thursday, November 17, 2016
  • by anekdotes
  • Repository
  • 1 Watchers
  • 0 Stars
  • 181 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 2 % Grown

The README.md

Anekdotes Meta

Latest Stable Version Build Status codecov.io StyleCI License Total Downloads Codacy Badge, (*1)

Contains utility classes meant to reference themselves and manipulate events/storage, (*2)

Installation

Install via composer into your project:, (*3)

composer require anekdotes/meta

Basic Usage

Call the namespace of the object you want to use and use its functions. There are many utilities classes to choose from, described below:, (*4)

Registry

A data storage class. Meant to be extended and to load arrays in dot notation., (*5)

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.

Additional functions to manipulate registries can be found in the source code, (*6)

StaticRegistry

The StaticRegistry is a Singleton instance of the Registry., (*7)

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

Config

A file loader that fills a registry based on the file content., (*8)

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

It can also load folder of config files., (*9)

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

Files must use the following format :, (*10)

<?php

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

Since Config extends Registry, you can obtain the content as with a registry., (*11)

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

Loading files can also be prefixed with the filename and have an additonal namespace as prefix, (*12)

$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"];

Dispatcher

The Dispatcher allows an observer design pattern usage. It simply stores listener functions that gets fired when their action is called., (*13)

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"

ObjectArrayActionDispatcher

The Object Array Action Dispatcher (OAAD) is a different kind of action dispatcher. It treats an array of objects having different actions to be called., (*14)

To use, simply : 1 - create the OAAD with the objects that have a function with the same signature to be called 2 - Call the function on the dispatcher, (*15)

The following examples demonstrates calling set on multiples registries using an OOAD., (*16)

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']

The Versions

17/11 2016

dev-master

9999999-dev

Contains utility classes meant to reference themselves and manipulate events/storage

  Sources   Download

MIT

The Requires

 

The Development Requires

service dispatcher meta registry

31/05 2016

1.3.1

1.3.1.0

Contains utility classes meant to reference themselves and manipulate events/storage

  Sources   Download

MIT

The Requires

 

The Development Requires

service dispatcher meta registry

03/05 2016

1.3.0

1.3.0.0

Contains utility classes meant to reference themselves and manipulate events/stora

  Sources   Download

MIT

The Requires

 

The Development Requires

service dispatcher meta registry

03/05 2016

1.2.0

1.2.0.0

Contains utility classes meant to reference themselves and manipulate events/stora

  Sources   Download

MIT

The Requires

 

The Development Requires

service dispatcher meta registry

03/05 2016

1.1.2

1.1.2.0

Contains utility classes meant to reference themselves and manipulate events/stora

  Sources   Download

MIT

The Requires

 

The Development Requires

service dispatcher meta registry

03/05 2016

1.1.1

1.1.1.0

Contains utility classes meant to reference themselves and manipulate events/stora

  Sources   Download

MIT

The Requires

 

The Development Requires

service dispatcher meta registry

03/05 2016

1.1.0

1.1.0.0

Contains utility classes meant to reference themselves and manipulate events/stora

  Sources   Download

MIT

The Requires

 

The Development Requires

service dispatcher meta registry

03/05 2016

1.0.2

1.0.2.0

Contains utility classes meant to reference themselves and manipulate events/stora

  Sources   Download

MIT

The Requires

 

The Development Requires

service dispatcher meta registry