定制 stratease/salesforcery 二次开发

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

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

stratease/salesforcery

Composer 安装命令:

composer require stratease/salesforcery

包简介

A PHP Salesforce ORM, inspired by Eloquent's API.

README 文档

README

Latest Stable Version Total Downloads License

A PHP ORM for Salesforce client applications, utilizing an OAuth2 REST client. Inspired by Eloquent's simple API.

Setup

1. Setting up a Connected App

You need to create a Connected App to generate the client_id and client_secret values for the OAuth2 connection. Once created use the credentials to register a connection.

2. Installation

composer require stratease/salesforcery

3. Connection

use Stratease\Salesforcery\Salesforce\Connection\REST\Authentication\PasswordAuthentication;
use Stratease\Salesforcery\Salesforce\Connection\REST\Client;
use Stratease\Salesforcery\Salesforce\Database\Model;


$authentication = new PasswordAuthentication([
     'grant_type' => 'password',
     'client_id' => 'your app ID',
     'client_secret' => 'your app secret',
     'username' => 'salesforce@user.com',
     'password' => 'password+token',
     'authorization_url' => 'https://test.salesforce.com/'
 ]);

// Typically https://login.salesforce.com, for testing use https://test.salesforce.com 
$authentication->setEndpoint('https://test.salesforce.com/');

$client = new Client($authentication);
$response = $client->query("SELECT Id FROM Account LIMIT 1");

// Should output a response with a 'records' key that conains an array of results.
print_r($response); 

// Register your connection so the ORM can connect
Model::registerConnection($client);

// Your model to connect to the Salesforce Account object
$account = Your/Models/Account::findOneBy('Id', 'abc123');
     

Examples

Defining a model

For a simple setup...

use Stratease\Salesforcery\Salesforce\Database\Model;

class Account extends Model
{
    // Account maps to Account in Salesforce, nothing else required.
}

More advanced usage...

use Stratease\Salesforcery\Salesforce\Database\Model;

class Product extends Model
{
    public static $resourceName = 'Product2';
}
  • Extend Stratease\Salesforcery\Salesforce\Database\Model and you're set! Sorta...
  • The model's Salesforce Object name is mapped by default via the {ClassName} -> {ObjectName}. You can override by defining the resourceName property.
  • Explicit field definitions allowed with option to override. get{Field}()
  • Will use SchemaInspector to discover fields for this resource and automatically hydrate instances with the fields

Query Objects

// Account is returned
$account = Account::findOneBy('Name', 'Acme Corp');
// An iterable Collection is returned
$accountCollection = Account::findBy(['OwnerId' => '123', 'Status' => 'Active']); // performs an AND expression on the associative array
foreach($accountCollection as $account) {
    echo "\n".$account->Name;
}

Modify Objects

// create
$account = new Account();
$account->Name = 'Acme Uber Corp';
$account->save(); 

// update
$account2 = Account::findOneBy('Name', 'Acme Uber Corp');
$account2->Name = 'Acme Uber Inc.';
$account2->save(); 

// delete
$account2->delete();

Salesforce

This library uses Salesforces REST API. Tested on version 39.

Todo

  • Object relations mapping, i.e. $contact->phone->isMobile
  • Add more REST endpoint support
  • Batch REST integration
  • Object -> field schema cache. As it stands it will request the schema n * Models times per run. So if you do a series of requests utilizing Account and User models, it will request the schema twice, once for each model.
  • Query builder object
  • Look into extended Eloquent more formally.
  • Test with other php versions. Was developed on 7.1
  • Docker environment for tests. As it stands now tests require a connection to a sandbox environment. Preferred setup for now in order to validate various Salesforce REST protocols are passing muster.
  • Currently only support for OAuth2 password grant type. Accepting pull requests for other authorization protocols.

stratease/salesforcery 适用场景与选型建议

stratease/salesforcery 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 964 次下载、GitHub Stars 达 6, 最近一次更新时间为 2018 年 03 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「orm」 「php」 「rest」 「client」 「salesforce」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 stratease/salesforcery 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2018-03-08