PHP Classes

PHP Registry with Singleton Trait: Set and get registry values using singleton trait

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 142 All time: 9,191 This week: 49Up
Version License PHP version Categories
falcraft-registry 3.0MIT/X Consortium ...5PHP 5, Data types, Design Patterns, T...
Description 

Author

This class can set and get registry values using singleton trait.

It implements a registry of values that acts like an associative arrays of key value pairs.

The class uses a singleton trait to prevent that more than one instance of the class exists in a given moment.

Picture of Asher Wolfstein
  Performance   Level  
Innovation award
Innovation award
Nominee: 5x

 

Example

<?php

require_once('../../Patterns/Registry.php');

use
Falcraft\Patterns;

echo
"Falcraft\\Patterns\\Registry.php Test\n";
echo
"-----------------------------------\n\n";

echo
"Instantiating Singleton -> ";

$success = true;

$testRegistryInstance = null;

try {
   
$testRegistryInstance = Patterns\Registry::instantiate();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
"Add Registry Slot: exampleKey => exampleValue -> ";

$success = true;

try {
   
$testRegistryInstance->set('exampleKey', 'exampleValue');
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
} else {
    echo
"Failure...\n\n";
}

var_dump($testRegistryInstance);

echo
"Instantiate Again Into Alternate Local Variable -> ";

$success = true;

$testRegistryInstanceTwo = null;

try {
   
$testRegistryInstanceTwo = Patterns\Registry::instantiate();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

var_dump($testRegistryInstanceTwo);


  Files folder image Files (15)  
File Role Description
Files folder imageFalcraft (3 directories)
Files folder imagesrc (1 directory)
Files folder imagetests (1 directory)
Accessible without login Plain text file composer.json Conf. Composer File
Accessible without login Plain text file LICENSE.txt Lic. License (MIT)
Accessible without login Plain text file phpunit.xml Conf. Unit Testing
Accessible without login Plain text file README.txt Doc. README

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadfalcraft-registry-2016-07-10.zip 13KB
Downloadfalcraft-registry-2016-07-10.tar.gz 6KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Singleton Trait Download .zip .tar.gz Required to make registry a singleton Required
 Version Control Unique User Downloads Download Rankings  
 0%
Total:142
This week:0
All time:9,191
This week:49Up