stratease/salesforcery 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱: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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固