archer / clickatell-bundle
Symfony ClickatellBundle
此软件包的规范存储库似乎已不存在,因此该软件包已被冻结。
Requires
- php: >=5.5.9
- symfony/framework-bundle: ~2.8|~3.0
Requires (Dev)
- doctrine/doctrine-bundle: ~1.6
- symfony/validator: ~2.8|~3.0
- symfony/yaml: ~2.8|~3.0
This package is auto-updated.
Last update: 2020-03-28 08:54:42 UTC
README
先决条件
本版本的分包需要 Symfony 2.1+。
翻译
如果您希望使用此分包中提供的默认文本,请确保您已在其配置中启用了翻译器。
# app/config/config.yml framework: translator: ~
有关翻译的更多信息,请参阅Symfony 文档。
安装
安装是一个简单的5步骤过程。
- 使用 composer 下载 ArcherClickatellBundle。
- 启用 Bundle。
- 创建您的消息类。
- 配置 ArcherClickatellBundle。
- 更新您的数据库模式。
第1步:使用 composer 下载 ArcherClickatellBundle
在您的 composer.json 中添加 ArcherClickatellBundle。
{
"require": {
"archer/clickatell-bundle": "dev-master"
}
}
现在,运行以下命令让 composer 下载分包。
$ php composer.phar update archer/clickatell-bundle
Composer 将分包安装到您的项目的 vendor/archer 目录。
第2步:启用分包
在内核中启用分包。
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Archer\ClickatellBundle\ArcherClickatellBundle(), ); }
第3步:创建您的消息类
此分包的目标是将一些 Message 类持久化到数据库中(MySQL、MongoDB、CouchDB 等)。
该分包提供了基类,这些基类已经为大多数字段进行了映射,以便于创建实体。以下是使用方法:
- 扩展基
Message类(要使用的类取决于您的存储) - 映射
id字段。它必须被保护,因为它是从父类继承的。
注意
文档使用了一个名为
AcmeMessageBundle的分包。如果您想使用相同的名称,您需要在内核中注册它。但您当然可以将您的消息类放在您想要的分包中。
警告
如果您在您的消息类中覆盖了 __construct() 方法,请确保调用 parent::__construct(),因为基消息类依赖于它来初始化一些字段。
a) Doctrine ORM 消息类
如果您通过 Doctrine ORM 持久化消息,则您的 message 类应位于您的分包的 Entity 命名空间中,并像这样开始:
<?php // src/Acme/MessageBundle/Entity/Message.php namespace Acme\MessageBundle\Entity; use Archer\ClickatellBundle\Entity\Message as BaseMessage; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="clickatell_message") */ class Message extends BaseMessage { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; public function __construct() { parent::__construct(); // your own logic } }
b) MongoDB 消息类 c) CouchDB 消息类 d) Propel 消息类
第4步:配置 ArcherClickatell
根据您使用的数据存储类型,将以下配置添加到您的 config.yml 文件中。
# app/config/config.yml archer_clickatell: user: ~ # your username for clickatell password: ~ # your password for clickatell api_id: ~ # your id for clickatell message_class: Acme\MessageBundle\Entity\Message
# app/config/config.xml <!-- app/config/config.xml --> <archer_clickatell:config user="username" password="password" api-id="api_id" message-class="Acme\MessageBundle\Entity\Message" />
第5步:更新您的数据库模式
现在配置好bundle后,你需要做的是更新你的数据库模式,因为你在第4步中添加了一个新实体,即你创建的Message类。
对于ORM,请运行以下命令。
$ php app/console doctrine:schema:update --force
使用步骤
//send Sms $form = $this->get('clickatell.send_message.form'); $form->bind($this->getRequest()); if ($form->isValid()) { $message = $form->getData(); $clickatell = $this->get('clickatell.http'); $response = $clickatell->sendMessage($message->getToPhone(), $message->getText()); }