wabel / zoho-crm-orm

此包的最新版本(2.0.x-dev)没有可用的许可证信息。

一个ORM类包,用于通过API操作您的Zoho CRM账户中的数据。

2.0.x-dev 2019-03-17 11:23 UTC

This package is auto-updated.

Last update: 2024-09-25 01:37:30 UTC


README

Scrutinizer Code Quality Build Status Coverage Status

Wabel的Zoho-CRM ORM

大量借鉴自 mctekk的工作

这是什么?

本项目是一个PHP连接器,用于连接Zoho CRM。使用此连接器可以通过PHP应用程序访问ZohoCRM数据。

它与其他连接器有何不同?

与其他Zoho CRM客户端不同,Zoho-CRM ORM使用一个 代码生成器 来生成Beans和DAO,从而可以轻松地从PHP访问Zoho对象。

Beans和DAO是什么?

代码短小精悍胜过长篇大论,以下是一个示例

use \Wabel\Zoho\CRM\ZohoClient;

// The ZohoClient class is the low level class used to access Zoho.
$zohoClient = new ZohoClient($configuration, 'Europe/Paris');

// Use the "DAO" class to write to some module of Zoho.
// Each module (even custom ones) has its own class.
$contactZohoDao = new ContactZohoDao($zohoClient);

// For each DAO, there is a bean associated.
$contact = new Contact();
$contact->setLastName("Doe");
$contact->setFirstName("John");

// Use the "save" method to save the bean.
$contactDao->save($contact);

// Use the "searchRecords" method to fetch data from Zoho. 
$records = $contactDao->searchRecords("(Last Name:FooBar)");
foreach ($records as $record) {
    // Each record is a "Contact" object.
    echo $record->getLastName();
}

// Get Records from the dao
$contactDao->getRecords()

你必须永远记住的事情

  • Beans 用于映射Zoho中的记录。每个Zoho模块有一个类
  • DAOs 用于将Beans发送到Zoho。每个Zoho模块有一个DAO

那么,如何生成Beans和DAOs呢?

有几种技术。

使用纯PHP代码

use \Wabel\Zoho\CRM\ZohoClient;

// The ZohoClient class is the low level class used to access Zoho.
$zohoClient = new ZohoClient($zohoAuthToken);

// The EntitiesGeneratorService class is in charge of generating Beans and DAOs.
$entitiesGenerator = new EntitiesGeneratorService($client);

// The target directory we will write into.
$directory = __DIR__.'/src/TestNamespace/';
// The namespace for the beans and DAOs.
$namespace = 'TestNamespace';
// That returns an array containing each created Dao by using the fully qualified class name
$generator->generateAll($directory, $namespace);

针对正确的Zoho API

默认情况下,客户端将指向 https://crm.zoho.com/crm/private 终端。如果您的终端不同(一些用户指向 https://crm.zoho.eu/crm/private),您可以使用 Client 构造函数的第三个参数

$zohoClient = new ZohoClient([
    'client_id' => 'xxxxxxxxxxxxxxxxxxxxxx',
     'client_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'redirect_uri' => 'http://xxxxxxxxx.com/bakcxxxx',
    'currentUserEmail' => 'xxxxx@test.fr',
    'applicationLogFilePath' => '/xxx/xxx/',
    'sandbox' => true or false,
    'apiBaseUrl' => '',
    'apiVersion' => '',
    'access_type' => '',
    'accounts_url' => '',
    'persistence_handler_class' => '',
    'token_persistence_path' => ''
], 'Europe/Paris);

设置单元测试

有兴趣贡献?您可以轻松设置单元测试环境:阅读如何更改客户端配置 - 阅读 配置

  • phpunit.xml.dist 文件复制到 phpunit.xml
  • 更改存储的环境变量 client_secret
  • 更改存储的环境变量 redirect_uri
  • 更改存储的环境变量 currentUserEmail
  • 更改存储的环境变量 applicationLogFilePath
  • 更改存储的环境变量 persistence_handler_class
  • 更改存储的环境变量 token_persistence_path
  • 更改存储的环境变量 userid_test
  • 更改存储的环境变量 timeZone
  • 更改存储的环境变量 custom_module_singular_name
  • 更改存储的环境变量 custom_module_mandatory_field_name
  • 更改存储的环境变量 custom_module_picklist_field_name
  • 更改存储的环境变量 custom_module_picklist_field_value1
  • 更改存储的环境变量 custom_module_picklist_field_value2
  • 更改存储的环境变量 custom_module_date_field_name
  • 更改存储的环境变量 custom_module_text_field_name

待办事项

实现 searchRecords()