gpaton / parse-bundle
在您的 Symfony2 项目中集成 Parse.com PHP SDK
1.1.1
2018-02-19 13:22 UTC
Requires
- php: >=5.4.0
- parse/php-sdk: 1.1.*
- symfony/framework-bundle: >=2.1
This package is not auto-updated.
Last update: 2024-09-14 18:47:36 UTC
README
简介
此包为您的 Symfony2 项目提供对 Parse.com PHP SDK 的集成。
由于我目前没有使用其他 Parse.com 工具,所以我只实现了 推送通知。您可以根据需要贡献其他工具。
变更日志
1.1.0
- 允许提前安排推送(由于 Parse.com 限制,最多提前两周)
1.0.0
- 允许向频道或 ParseQuery 发送推送
安装
安装 GpatonParseBundle
简单地运行,假设您已安装 composer.phar 或 composer 二进制文件
$ php composer.phar require gpaton/parse-bundle 1.1.*
启用包
最后,在内核中启用包
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Gpaton\ParseBundle\GpatonParseBundle(),
);
}
推送通知
设置
首先,您需要使用在 Parse.com 上创建应用时获得的密钥配置该包
# app/config/config.yml
gpaton_parse:
app_id: APPLICATION_ID
rest_key: REST_KEY
master_key: MASTER_KEY
使用方法
然后,您可以从控制器中通过加载服务 gpaton.parse.push
并使用 send
方法发送推送通知
<?php
// Acme\DemoBundle\Controller\PushController
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class PushController extends Controller {
public function indexAction() {
$push = $this->get('gpaton.parse.push');
$data = ['alert' => 'Hi there !'];
$channels = ['My Channel'];
$push->send($data, $channels);
// ...
}
}
send
方法最多接受 4 个参数。第一个是必需的,您至少必须提供第二个 或 第三个参数
-
数据数组
-
频道数组 (可选)
-
ParseQuery (可选)
-
推送时间 \DateTime (可选)
如果您想向频道发送推送,只需按照前面的示例操作。要向 Query 发送推送,您将使用 createQuery
方法
<?php
// Acme\DemoBundle\Controller\PushController
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class PushController extends Controller {
public function indexAction() {
$push = $this->get('gpaton.parse.push');
$data = ['alert' => 'Hi there !'];
$query = $push->createQuery();
$query->equalTo('foo', 'bar');
$push->send($data, null, $query);
// ...
}
}
如果您想提前安排推送(由于 Parse.com 限制,最多提前两周)
<?php
// Acme\DemoBundle\Controller\PushController
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class PushController extends Controller {
public function indexAction() {
$push = $this->get('gpaton.parse.push');
$data = ['alert' => 'Hi there !'];
$query = $push->createQuery();
$query->equalTo('foo', 'bar');
$scheduledTime = new \DateTime();
$scheduledTime->modify('+5 days');
$push->send($data, null, $query, $scheduledTime);
// ...
}
}
许可证
此包在 GPL v2 许可证下。请参阅包中的完整许可证
Resources/meta/LICENSE