obtao/recombeebundle
用于与 symfony 和 recombee API 交互的包
dev-master
2018-06-27 05:34 UTC
Requires
- php: >=7.1.0
- guzzle/guzzle: ~3.9
- jms/serializer-bundle: ^1.2
- symfony/symfony: ~2.8
This package is auto-updated.
Last update: 2024-09-18 15:22:38 UTC
README
步骤 1: 下载包
打开命令行,进入项目目录并执行以下命令以下载此包的最新稳定版本
$ composer require "obtao/recombeebundle:dev-master"
此命令要求您全局安装了 Composer,如 Composer 文档中的安装章节所述。
步骤 2: 启用包
然后,通过将其添加到已注册包列表中,在您的项目的 app/AppKernel.php 文件中启用该包
此包依赖于 JMS serializer 作为依赖项,因此如果您尚未使用它,您也必须添加它。
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new \Obtao\RecombeeBundle\ObtaoRecombeeBundle(), new \JMS\SerializerBundle\JMSSerializerBundle() // only if you are not using it yet ); // ... } // ... }
步骤 3: 配置包
// app/config.yml obtao_recombee: recombee_database_name: "your-database-name" recombee_secret_token: "your-api-key"
步骤 4: 使用方法
以下是在 symfony 控制器中创建用户和相关属性的示例用法。
该包提供 2 个自定义模型(用于用户和项目),可以根据需要自由修改。
BatchBuilder 辅助工具将提取此类项目的所有属性以猜测 recombee API 的最佳类型(需要实现 HasSkuInterface)
<?php namespace AppBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use \Obtao\RecombeeBundle as ObtaoRecombee; class DefaultController extends Controller { /** * @Route("/", name="homepage") */ public function indexAction() { // service to reach API $apiCaller = $this->get('obtao.recombee.api.caller'); // Helper to build batch of properties $batchBuilder = $this->get('obtao.recombee.batch.builder'); // reset database first (be careful !) : expected response "ok" $reset = var_dump($apiCaller->sendToApi(new ObtaoRecombee\Model\ResetDatase())); // create a new User $user = new ObtaoRecombee\Model\User(); $user->setSku(12345); $user->setNickName('JohnDoe'); $user->setOriginCountry('FR'); // use batch helper to build all properties for user above /** @var Batch $batch */ $batch = $batchBuilder->buildBatchOfProperties($user, ObtaoRecombee\Model\AddUserProperty::class); // send batch of properties to API : expected response batch of "ok" var_dump($apiCaller->sendToApi($batch)); // create user : expected response "ok" var_dump($apiCaller->sendToApi(new ObtaoRecombee\Model\SetUserValues($user))); die('that\'s all folks'); } }