dlin / keen-bundle
Keen.IO的官方库的Symfony 2 Bundle
v1.0.6
2013-11-28 23:40 UTC
Requires
- php: >=5.3.8
- keen-io/keen-io: dev-master
Requires (Dev)
- symfony/finder: 2.3.*
- symfony/framework-bundle: >=2.0
README
Dlin Keen Bundle是用于'Keen.IO' PHP库的Symfony2包装器Bundle
此Bundle提供了一个可配置的服务以与Keen.IO一起工作
版本
0.9
安装
使用Composer进行安装
将以下内容添加到您的composer.json
json
{
"require" : {
"dlin/keen-bundle": "dev-master"
}
}
在AppKernel.php中启用此Bundle
public function registerBundles()
{
$bundles = array(
...
new Dlin\Bundle\KeenBundle\DlinKeenBundle(),
...
}
配置
例如
#app/config/config.yml
dlin_keen:
project_id: werknskviehraf234slf
read_key: xxxxxxxxxxx
write_key: xxxxxxxxx
用法
在控制器中获取服务
$service = $this->get('dlin.keen_service');
在ContainerAwareService中获取服务
$service = $this->container->get('dlin.keen_service');
使用数据向Keen.IO发送事件
$eventCollectionName = "purchases";
$eventData = array('porduct_id'=>1, 'quantity'=>2, 'amount'=>120);
$service->fireEvent($eventCollectionName, $eventData);
以面向对象的方式发送事件。
//create an event object with public properties
$eventObject = new MyPurchaseEvent();
$eventObject->productId = 1;
$eventObject->quantity = 2;
$eventObject->amount = 120;
$service->fireEventObject($eventObject); //this is equivalent to the last fireEvent call
//You can defined your own event class
Class MyPurchaseEvent{
//Public properties will be send as event data
public $productId;
public $quantity;
public $amount;
// Procted and private properties are ignored
protected $customerAddress;
private $customerGender;
//By default, the event collection name will be the class name in camelCase (e.g. myPurchaseEvent)
//You can specify the collection name by defining a public method named 'getCollectionName'
public function getCollectionName(){
return 'purchases';
}
}
有时发送事件可能会减慢页面加载速度并影响用户体验。您可以在当前脚本执行完成后安排事件仅发送一次。这可以避免减慢页面加载速度。
...
$service->scheduleEventObject($eventObject);
$service->scheduleEvent('event_collection_name', array('data'=>123));
...
//You can get scheduled events using collection name
$service->getScheduledEvent('event_collection_name');
//You can also cancel schedule events by event collection name
$service->cancelScheduledEvents('event_collection_name');
许可证
MIT
自由软件,太棒了!