- Lazy load.
- Simple KeyValue class.
- Simple configuration system
- Lazy hooks:
- Lazy for static hooks: permission, menu, theme, views, …
- Lazy for dynamic hooks: cron, node_*, …
- Redis wrapper for PhpRedis.
- @TODO: Callback wrapper, supports annotations.
To use this feature. Your module need implementing hook_vc_api().
Your class named ModuleNameFoo
, vc will be loaded the file in
/path/to/module_name/lib/Foo.php
.
ModuleName
->/path/to/module_name/lib/ModuleName.php
ModuleNameFoo
->/path/to/module_name/lib/Foo.php
ModuleName_Foo_Bar
->/path/to/module_name/lib/Foo/Bar.php
<?php
$kv = new VCKeyValue($collection = 'my_collection');
$kv->set('foo', 'bar');
$kv->setMultiple(array('foo' => 'bar', 'baz' => 'foo'));
$kv->delete('foo');
$kv->deleteMultiple(array('foo', 'baz');
…
…
Configure Redis connection in your Drupal settings.php (They are all optional, default values will be used).
<?php
$conf['redis_client_host'] = '127.0.0.1';
$conf['redis_client_port'] = '6379';
$conf['redis_client_base'] = '';
$conf['redis_client_password'] = NULL;
Usage, support IDE autocomplete:
<?php
$redis = VcRedis::getClient();
$redis->mget($array);
Supported annotations:
<?php
/**
* @cache($cid = __FUNCTION__, $bin = 'cache', $expire = '+ 30 minutes')
*/
function foo() {}
<?php
/**
* @queue($name = 'function_name', $data = 'function arguments')
*/
function foo() {}
<?php
/**
* @filter_xss('%function results', $allowed_tags = array('a', 'strong'))
* @strip_tags('%function results', $allowed_tags = array('a', 'strong'))
* @truncate_utf8(…)
*/
function foo() {}
<?php
/**
* @watchdog($type = '', $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL).
*/
function foo($a1, $a2) {
$my_complex_result = '…';
return $my_complex_result; // ' Hello '
}
Why not just using variable_get/set/del?
Drupal use variable system, load all variables on every pages, make them available as a global array. It takes a lot of memory. This is not, it just load the configuration value when you need.
Example configuration file in yaml format:
# path/to/module/conf/module_name.yaml
foo: bar
baz: [foo, bar]
Example Code:
<?php
// return bar
vc_conf('module_name.foo')->get();
// override configuration value
vc_conf('module_name.foo')->set('baz');
// Restore default configuration value.
vc_conf('module_name._name')->restore();