Documentation
Registry helper
Table of Contents ▼
Presentation
This helper is used to store data more cleanly than using global variables.
Data stored in a register can be accessed (read and write) in three different ways: via getters/setters, via an object-oriented notation, or via a notation such as an array.
Usage
use \Temma\Utils\Registry as TµRegistry;
// create a new registry
$registry = new \Temma\Utils\Registry();
// create a registry and set initial data
$registry = new \Temma\Utils\Registry([
'foo' => 'bar',
'abc' => 'xyz',
]);
// read an INI file and store its data in the registry
$registry->readIni('/path/to/file.ini');
// read a JSON file and store its data in the registry
$registry->readJson('/path/to/file.json');
// read an XML file and store its data in a key of the registry
$registry->readXml('/path/to/file.xml', 'config');
// access data from the registry (three methods, same result)
print($registry->get('foo'));
print($registry->foo);
print($registry['foo']);
// add data to the registry (three methods, same result)
$registry->set('foo', 'bar');
$registry->foo = 'bar';
$registry['foo'] = 'bar';
// add multiple data in one call
$registry->set([
'foo' => 'bar',
'abc' => 'xyz',
]);
// check if data exists (three methods, same result)
if ($registry->isset('foo'))
print('OK');
if (isset($registry->foo))
print('OK');
if (isset($registry['foo']))
print('OK');
// remove data (three methods, same result)
$registry->unset('foo');
unset($registry->foo);
unset($registry['foo']);
Previous: | Lock helper |
Next: | Smarty helper |
Table of Contents
- Migration : How to upgrade from Temma 1.x to version 2
- Installation : Download Temma and install it to start your web project
- Configuration : All the configuration directives of the etc/temma.json file and the optional environment variables
- External libraries : How to use external function libraries
- Routing : Temma's default routing system, and advanced routing
- Log : Use of the log system, management by criticality levels
- Controllers : Essential parts of your web application
- Views : Smarty templates or JSON/CSV/RSS/iCal/INI exports
- Dependency injection : The backbone of your application developments
- Sessions : Extension of user sessions managed by PHP
- Data sources : Unified data access management
- Model : How to use DAOs to access databases
- Execution flow : How to manage the execution flow, between plugins and the controller
- Plugins : How to use plugins, and create your own plugins to modularize your code
- Attributes : How to filter access to controllers and actions
- Command-line interface : To create executable scripts on the command line, automatically initialized by Temma
-
Helpers :
Items offered by Temma to help you in various circumstances
- Command-line scripts
-
Controller + plugin
- Auth : Controller and plugin to manage user authentication
- Plugins
- Attributes
-
Utility objects
- ANSI : To format texts written to standard output
- BaseConvert : To do digital base conversions
- DataFilter : To filter and validate data
- Email : To send emails
- HTMLCleaner : To clean up an HTML stream coming from a WYSIWYG editor
- IniExport : To export data in INI format
- Json : To read JSON streams that may contain comments
- Lock : To lock access to a file, or the execution of the current PHP script
- Registry : To properly store global variables
- Smarty : To process Smarty templates outside the view
- Term : Terminal management (TTY)
- Text : Different treatments on character strings
- Timer : To manage stopwatches