定制 comsave/salesforce-outbound-message-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

comsave/salesforce-outbound-message-bundle

Composer 安装命令:

composer require comsave/salesforce-outbound-message-bundle

包简介

This bundle allows you to easily process outbound messages sent by Salesforce.

README 文档

README

Create, update, remove objects in Symfony sent through Salesforce outbound messages.

Release Travis Test Coverage Packagist

Requirements

This bundle assumes you're using:

  1. MongoDB database (and specifically doctrine/mongodb-odm).
  2. comsave/salesforce-mapper-bundle for Salesforce object mapping to your MongoDB Document classes.

Bundle features

  • Object create
  • Object update
  • Object delete. To enable this complete additional setup steps.
  • Object custom handling beforeFlush
  • Object custom handling afterFlush

Installation

  • composer require comsave/salesforce-outbound-message-bundle
  • Register the bundle in your AppKernel.php by adding new Comsave\SalesforceOutboundMessageBundle\ComsaveSalesforceOutboundMessageBundle()
  • To handle the Salesforce's incoming outbound messages create a route (for example /sync) and a method to a controller:
<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Comsave\SalesforceOutboundMessageBundle\Services\RequestHandler\OutboundMessageRequestHandler;

class OutboundMessageController extends Controller
{
    public function syncAction(Request $request, OutboundMessageRequestHandler $requestHandler)
    {
        try {
            $outboundMessageXml = $request->getContent();
            return $requestHandler->handle($outboundMessageXml);
        }
        catch (\Throwable $e) {
            throw new \SoapFault("Server", $e->getMessage());
        }
    }
}
  • add the bundle configuration in your app/config/config.yml
comsave_salesforce_outbound_message:
    # WSDL_CACHE_NONE, WSDL_CACHE_DISK, WSDL_CACHE_MEMORY or WSDL_CACHE_BOTH
    wsdl_cache: 'WSDL_CACHE_DISK'                     
    # An absolute path to Salesforce object WSDL files
    wsdl_directory: '/absolute/path/' 
    document_paths:
        # Map a document using its Salesforce name and your local class 
        CustomObject__c:              
            path: 'YourNamespace\Documents\CustomObject'
            force_compare: false # if true, incoming object will be compared to existing ones in the database; will continue sync only if not equal
  • Add DocumentInterface to the document class you'd like to be tracked by the OutboundMessageBundle.
<?php

use Comsave\SalesforceOutboundMessageBundle\Interfaces\DocumentInterface;
use LogicItLab\Salesforce\MapperBundle\Model\Account as BaseAccount;

class Account extends BaseAccount implements DocumentInterface
{
}
  • Create an EventSubscriber for an object you'd like to sync. It would look something like this for the Account object:
<?php

namespace YourNamespace\EventSubscriber;

use Comsave\SalesforceOutboundMessageBundle\Event\OutboundMessageBeforeFlushEvent;
use Comsave\SalesforceOutboundMessageBundle\Event\OutboundMessageAfterFlushEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Comsave\SalesforceOutboundMessageBundle\Interfaces\DocumentInterface; 
use Comsave\Webservice\Core\UserBundle\Document\Account;

class AccountSoapRequestSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            OutboundMessageBeforeFlushEvent::NAME => [
                ['onBeforeFlush'],
            ],
            OutboundMessageAfterFlushEvent::NAME => [
                ['onAfterFlush'],
            ],
        ];
    }

    public function supports(DocumentInterface $document): bool
    {
        $documentClass = get_class($document);

        return Account::class == $documentClass || $document instanceof Account;
    }

    public function onBeforeFlush(OutboundMessageBeforeFlushEvent $event)
    {
        /**
         * Make sure to do call $this->supports() before you start processing the object
         * You only want to process the correct object in this EventSubscriber (which is Account in this case)
         */
        /** @var Account $newAccount */
        $newAccount = $event->getNewDocument();
        
        if (!$this->supports($newAccount)) return; 
    
        /** @var Account $existingAccount */
        $existingAccount = $event->getExistingDocument();
        
        /**
         * You can do any modifications you want to the object before it get's saved (flushed) to the database.
         * - - -
         * $event->getExistingDocument() provides you access to the existing object (if it exists) 
         * $event->getNewDocument() provides you access to the new object delivered by the outbound message. This is the object that will be merged over the existing one (if any) and saved to the database. In most of the cases you only need to use this one.
         */
    }

    public function onAfterFlush(OutboundMessageAfterFlushEvent $event)
    {
        /** @var Account $account */
        $account = $event->getDocument();

        if (!$this->supports($account)) return; 

        /**
         * You can process the object further if necessary after it has been saved (flushed) to the database.
         */
    }
}
  • Add your newly created route to the Salesforce outbound message for the object you want to sync (Account in our example).
  • That's it! Trigger an outbound message to be sent out and see everything happen automagically. 😎 👍

License

This project is licensed under the MIT License.

comsave/salesforce-outbound-message-bundle 适用场景与选型建议

comsave/salesforce-outbound-message-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.1k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2018 年 06 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 comsave/salesforce-outbound-message-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 comsave/salesforce-outbound-message-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 comsave/salesforce-outbound-message-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.1k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-22