PHP code example of ignaszak / registry
1. Go to this page and download the library: Download ignaszak/registry 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/ */
ignaszak / registry example snippets
use Ignaszak\Registry\Conf;
use Ignaszak\Registry\RegistryFactory;
// default: './src/tmp'
// Conf::setCookieLife(int $cookieLife); // default: 30 days
// Conf::setCookiePath(string $cookiePath) // default: '/'
// Use start method to begin
// RegistryFactory::start([string $registry = 'request']):
// 'request' - stores objects in variable - DEFAULT OPTION
// 'session' - stores objects in session
// 'cookie' - stores objects in cookie
// 'file' - stores objects in files
$registry = RegistryFactory::start();
// Use set and get methods
// The first parameter is a key at witch created object is stored
// Key is used in any other method
$registry->set('key', new AnyClass);
$registry->get('key'); // Returns AnyClass instance
// Returns true if the key is defined
$registry->has('key');
// Reload object
$registry->reload('key');
// Removes from register
$registry->remove('key');
// Use register method
// First use sets and returns instance of Namespace\AnyClass
// Any further use only returns instance of Namespace\AnyClass
$registry->register('Namespace\AnyClass');
// It is possible to use has, reload and remove methods
$registry->has('Namespace\AnyClass');
$registry->reload('Namespace\AnyClass');
$registry->remove('Namespace\AnyClass');