liip / drupalregistrymodule
本模块提供API,用于持久化/缓存信息。
Requires
- php: >=5.3.8,<5.4
- beberlei/assert: dev-master
- liip/drupalconnectormodule: dev-master
- liip/registryadaptor: dev-master
- ruflin/elastica: 0.20.5.0.RC1
Requires (Dev)
- lapistano/proxy-object: dev-master
Suggests
- ruflin/elastica: Allows the registry to be an elasticsearch index.
This package is not auto-updated.
Last update: 2024-09-14 15:07:01 UTC
README
本模块提供API以存储信息中的键/值对。这个想法是在我们需要更改自定义数据存储的持久化层,以便以后系统可以使用时产生的。我们最初使用了标准的Drupal 7方式来通过实现variable_get()
、variable_set()
和variable_del()
函数的包装来缓存数据。此实现作为默认和示例实现提供给注册表。
限制
在不包含私有成员的情况下,无法存储除值对象之外的其他对象。请注意,任何实例的对象都将转换为stdClass实例。
当前Travis状态
安装
源代码现在兼容PSR-0。没有特定的安装程序需要遵循。只需将源代码克隆或检出至您的项目并使用即可。如果您不使用兼容PSR-0的自动加载器,只需将bootstrap.php
添加到您的引导或自动加载器中。
Composer
将以下行添加到您的composer.json
文件中,并更新您的项目composer安装。
{ "require": { "liip/drupalregistrymodule": "dev-master" } }
此Composer配置将检查项目的'cutting eadge'版本('dev-master')。请注意,这有时可能是有问题的。
注意:如果您不了解这意味着什么,请从composer项目网站开始。
Github
因此,我建议使用Composer方式将LiipDrupalRegistryModule作为项目的依赖项。源代码也通过github提供。只需像您所熟悉的那样进行克隆。
$ git clone git@github.com:liip/LiipDrupalRegistryModule.git
依赖项
- LiipDrupalConnector (https://github.com/liip/LiipDrupalConnectorModule.git)
- Assert (http://github.com/beberlei/assert)
可选
- Elastica (https://github.com/ruflin/elastica)
使用
在Tests文件夹中找到这个库如何工作的示例的好地方。对于那些不熟悉PHPUnit的人,这里有一个简短的介绍
$assertions = new \Assert\Assertion(); $registry = new D7Config('myEvents', $assertions); // put stuff in to the registry. $registry->register('eventItemRegister', $item); // get as single element out of the registry or an empty array if it does not exist. $item = $registry->getContentById('eventItemRegister', array()); // get complete register $items = $register->getContent(); // replace content of an item with a new value $register->replace('eventItemRegister', $newItem); // determine if an element is already registered $inRegister = $register->isRegistered('eventItemRegister'); // get rid of a single element $registry->unregister('eventItemRegister'); // destroy the complete registry $registry->destroy();
分发注册操作
结果证明,有必要将操作乘以多个注册表。在我们的情况下,我们需要将数据存储到ElasticSearch集群中,并且出于备份原因,还需要存储到MySQL数据库中。为此,引入了分发器。
分发器调用每个已注册注册表上的请求操作,为附加注册表提供容器。示例
$assertions = new \Assert\Assertion(); $indexName = 'myEvents'; $connection = new \PDO('mysql:host=localhost;dbname=testdb'); $drupalRegistry = new D7Config($indexName, $assertions); $esRegistry = new Elasticsearch($indexName, $assertion, new NoOpDecorator()); $dbRegistry = new MySql($indexName, $assertion, $connection); $dispatcher = new Dispatcher(); $dispatcher->attach($drupalRegistry, 'd7'); $dispatcher->attach($esRegistry, 'es'); $dispatcher->attach($dbRegistry, 'db'); $output = $dispatcher->dispatch('register', 'myDocumentId', array({some content})); if ($dispatcher->hasError()) { throw new RegistryException($dispatcher->getLastErrorMessages()); }
支持的系统
- D7配置数组(变量_get()、variable_set()、variable_del()的包装)
- Elasticsearch(基于elastica库)
- 内存
- MySQL