ryanwinchester/netsuite-php 问题修复 & 功能扩展

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

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

ryanwinchester/netsuite-php

Composer 安装命令:

composer require ryanwinchester/netsuite-php

包简介

NetSuite PHP API wrapper

README 文档

README

License Packagist

A PHP API client package for NetSuite, pried from the NetSuite PHP Toolkit and made more consumable for modern PHP application development. All of the classes in the NetSuite\Classes namespace are code provided by NetSuite with a license allowing redistribution. The custom work provided by this library separates these nearly 2,000 classes out into their own files and allows the classes to be installed with composer and accessed using standard autoloading support. It allows configuration to be read from the environment, adds support to log requests and responses and provides a simplified client wrapper class (NetSuiteService).

Installation

Require with composer:

composer require ryanwinchester/netsuite-php

Quickstart:

Instantiating the NetSuiteService class:

Any of the examples herein will assume you have already instantiated a client object using token-based authentication. The method of authenticating with user credentials was dropped from support by NetSuite in 2020.

// Token-based Authentication
require 'vendor/autoload.php';

use NetSuite\NetSuiteService;

$config = [
    // required -------------------------------------
    "endpoint"       => "2021_1",
    "host"           => "https://webservices.netsuite.com",
    "account"        => "MYACCT1",
    "consumerKey"    => "0123456789ABCDEF",
    "consumerSecret" => "0123456789ABCDEF",
    "token"          => "0123456789ABCDEF",
    "tokenSecret"    => "0123456789ABCDEF",
    // optional -------------------------------------
    "signatureAlgorithm" => 'sha256', // Defaults to 'sha256'
    "logging"  => true,
    "log_path" => "/var/www/myapp/logs/netsuite",
    "log_format"     => "netsuite-php-%date-%operation",
    "log_dateformat" => "Ymd.His.u",
];
$service = new NetSuiteService($config);

You can alternatively place your config in environment variables. This is helpful in hosted environments where deployment of config files is either not desired or practical. You can find the valid keys in the included .env.example file with sample values.

Previously, instantiating the NetSuiteClient with ENV data entailed using the static method createFromEnv. This method is now marked as deprecated and if you are using it, please change your code to use the standard constructor which will extract your configuration out of the $_ENV superglobal for you.

// Allowing the client to infer configuration from $_ENV
require 'vendor/autoload.php';

use NetSuite\NetSuiteService;

$service = new NetSuiteService();

Laravel Integration

If you're implementing NetSuite web services in a Laravel application, you might want to look at the netsuite-laravel package to streamline instantiating and making the client available to your app via the service container. In that case, you'll simply need to require the netsuitephp/netsuite-laravel package in your application and then as long as the client configuration is present in the application's environment, you'll have a client instance in the container.

Account-Specific Data Center URLs

With 2021_1, this library provides support to utilize NetSuite's new account-specific data center URL detection on each request. In practice, this lookup does have a measurable overhead cost. As such, I'd suggest using this feature only if your manner of NetSuite integration is such that you make fewer connections, handling integration in batches. If your manner of integration is to instead make many frequent, brief requests from NetSuite, then you will probably prefer to provide your data center URL explicitly and remove the lookup from every session.

// Recommended: Use your own defined data center URL (or sandbox, for instance):
$config['host'] = 'https://123456789.suitetalk.api.netsuite.com';

// To allow the service to get the correct URL for your account on the fly,
// use the legacy webservices url.
$config['host'] = 'https://webservices.netsuite.com';

Examples

See EXAMPLES.md

Logging

The most common way to enable logging will be to do so at the configuration level, see the quickstart examples.

You can also set logging on or off during runtime with methods. Note that if you don't specify a logging directory in the config or at runtime, then no logs will be created. There must be a valid target location.

// Set a logging path
$service->setLogPath('/path/to/logs');

// Turn logging on
$service->logRequests(true);  // Turn logging on.

// Turn logging off
$service->logRequests(false); // Turn logging off.

If you require more flexibility in relation to logging, you can provide your own PSR-3 compatible logger (as of 2023.1.0).

Generating Classes

This repository always contains classes generated from the version of the NetSuite PHP Toolkit corresponding with the web services version denoted by the specific release. Release v2021.1.0, for instance, is the first release built against NetSuite's 2021_1 web services toolkit. If you want to generate the class files yourself, for whatever reason, there is code included with the package to do so, using the following steps:

  • Download the NetSuite PHP Toolkit
  • Unzip the contents into the ./original/ folder
  • Run ./utilities/separate_classes.php or composer generate

Roadmap

PHP Version Support

See: https://www.php.net/supported-versions.php

With official support for PHP5 gone since the end of 2018 and with PHP7 moving to security-only by the end of 2021, the versions of PHP supported by this package will start to be gradually moved forward.

For the time being, expect the following for netsuitephp/netsuite-php:

  • require "php": ">=7.1" as of the 2021_1 build
  • require "php": ">=8" as of the 2023_1 build

This will apply only to new releases of the package, so you will still be able to continue using the last supported version for your PHP release if you can't or won't update PHP.

Support

If you need help with implementation, see the resources section of the examples file for some useful links.

If you believe that your issue is a bug specific to the custom work provided by this package (and not NetSuite's own classes that are packaged therein), then you can file an issue in github. Per the issue template, please include a clear description of the problem, how it is reproduced and the logs of relevant requests/responses using the logging features of this package.

Contributing

Contributions are welcome in the form of pull requests. Please include a clear explanation of the reason for the change and try to keep changes as small as possible, which will increase the speed with which we can get them reviewed and the likelihood of being included into the master branch.

  • Make sure to respect the current required php version in composer.json
  • Avoid introducing new dependencies (no framework hooks, etc)
  • Please try to make all additions comply with PSR-12

License

Original work is Copyright © 2010-2015 NetSuite Inc. and provided "as is." Refer to the NetSuite Toolkit License Agreement file.

All additional work is licensed under the Apache 2.0 open source software license according to the included LICENSE file.

ryanwinchester/netsuite-php 适用场景与选型建议

ryanwinchester/netsuite-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.83M 次下载、GitHub Stars 达 201, 最近一次更新时间为 2016 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 ryanwinchester/netsuite-php 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.83M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 202
  • 点击次数: 10
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 201
  • Watchers: 20
  • Forks: 87
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2016-03-04