php-arsenal / salesforce-outbound-message-bundle
此包已被废弃,不再维护。未建议替代包。
此包允许您轻松处理由 Salesforce 发送的出站消息。
1.1.0
2021-05-05 09:03 UTC
Requires
- php: >=7.4
- ext-json: *
- ext-soap: *
- doctrine/mongodb-odm: ^2.2
- php-arsenal/document-value-updater: ^0.1.1
- php-arsenal/salesforce-mapper-bundle: ^4.0
- symfony/config: ^5.2
- symfony/dependency-injection: ^5.2
- symfony/event-dispatcher: ^5.2
- symfony/http-kernel: ^5.2
- symfony/polyfill-apcu: ^1.22
- symfony/property-access: ^5.2
Requires (Dev)
- dg/bypass-finals: ^1.3
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: ^9.5
Provides
- ext-mongo: *
- dev-master
- 1.1.0
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.13.1
- 0.13.0
- 0.12.1
- 0.12.0
- 0.11.7
- 0.11.6
- 0.11.5
- 0.11.4
- 0.11.3
- 0.11.2
- 0.11.1
- 0.11.0
- 0.10.3
- 0.10.2
- 0.10.1
- 0.10.0
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.0
- 0.7.8
- 0.7.7
- 0.7.6
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4
- 0.3.10
- 0.3.9
- 0.3.8
- 0.3.7
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.2.37
- 0.2.36
- 0.2.35
- 0.2.34
- 0.2.33
- 0.2.32
- 0.2.31
- 0.2.30
- 0.2.29
- 0.2.28
- 0.2.27
- 0.2.26
- 0.2.25
- 0.2.23
- 0.2.22
- 0.2.21
- 0.2.20
- 0.2.19
- 0.2.18
- 0.2.17
- 0.2.15
- 0.2.14
- 0.2.13
- 0.2.12
- 0.2.11
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.1.17
- 0.1.15
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- dev-add-license-1
- dev-staging
- dev-add-after-flush-event
- dev-skip-and-delete-options
- dev-symfony3
This package is auto-updated.
Last update: 2022-01-05 10:27:03 UTC
README
通过 Salesforce 的出站消息创建、更新、删除在 Symfony 中发送的对象。
需求
此包假定您正在使用
- MongoDB 数据库(特别是
doctrine/mongodb-odm
)。 php-arsenal/salesforce-mapper-bundle
用于 Salesforce 对象映射到您的 MongoDBDocument
类。
包功能
- 对象
create
- 对象
update
- 对象
delete
。要启用此功能,请完成 附加设置步骤。 - 对象自定义处理
beforeFlush
- 对象自定义处理
afterFlush
安装
composer require php-arsenal/salesforce-outbound-message-bundle
- 在您的
AppKernel.php
中注册该包,通过添加new PhpArsenal\SalesforceOutboundMessageBundle\SalesforceOutboundMessageBundle()
- 要处理 Salesforce 的传入出站消息,创建一个路由(例如
/sync
)和一个控制器的方法
<?php use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use PhpArsenal\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()); } } }
- 在您的
app/config/config.yml
中添加包配置
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
- 将
DocumentInterface
添加到您希望由OutboundMessageBundle
跟踪的文档类中。
<?php use PhpArsenal\SalesforceOutboundMessageBundle\Interfaces\DocumentInterface; use PhpArsenal\Salesforce\MapperBundle\Model\Account as BaseAccount; class Account extends BaseAccount implements DocumentInterface { }
- 为要同步的对象创建一个
EventSubscriber
。对于Account
对象,它可能看起来像这样
<?php namespace YourNamespace\EventSubscriber; use PhpArsenal\SalesforceOutboundMessageBundle\Event\OutboundMessageBeforeFlushEvent; use PhpArsenal\SalesforceOutboundMessageBundle\Event\OutboundMessageAfterFlushEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use PhpArsenal\SalesforceOutboundMessageBundle\Interfaces\DocumentInterface; use PhpArsenal\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. */ } }
- 将您新创建的路由添加到您要同步的对象的 Salesforce 出站消息中(在我们的例子中是
Account
)。 - 就这样!触发一个出站消息发送,并看到所有事情自动发生。😎 👍
许可
此项目受 MIT 许可证许可。