OOP面向对象形式的初使化配置
init.php里:
<?php
use ElemeOpenApi\Config\Config;
define("BASE_DIR", dirname(__FILE__) . "/");
define("ROOT_DIR", dirname(__FILE__) . "/../");
require BASE_DIR . "../vendor/autoload.php";
require ROOT_DIR . "vendor/autoload.php";
//此处需要填写对应的参数
$app_key = "";
$app_secret = "";
$sandbox = true;
$scope = "all";
$callback_url = "";
$config = new Config($app_key, $app_secret, $sandbox);
Config.php里
<?php namespace ElemeOpenApi\Config; use InvalidArgumentException; class Config
{
private $app_key;
private $app_secret;
private $sandbox; private $request_url; private $log; private $default_request_url = "https://open-api.shop.ele.me";
private $default_sandbox_request_url = "https://open-api-sandbox.shop.ele.me"; public function __construct($app_key, $app_secret, $sandbox)
{
if ($sandbox == false) {
$this->request_url = $this->default_request_url;
} elseif ($sandbox == true) {
$this->request_url = $this->default_sandbox_request_url;
} else {
throw new InvalidArgumentException("the type of sandbox should be a boolean");
} if ($app_key == null || $app_key == "") {
throw new InvalidArgumentException("app_key is required");
} if ($app_secret == null || $app_secret == "") {
throw new InvalidArgumentException("app_secret is required");
} $this->app_key = $app_key;
$this->app_secret = $app_secret;
$this->sandbox = $sandbox;
} public function get_app_key()
{
return $this->app_key;
} public function get_app_secret()
{
return $this->app_secret;
} public function get_request_url()
{
return $this->request_url;
} public function set_request_url($request_url)
{
$this->request_url = $request_url;
} public function get_log()
{
return $this->log;
} public function set_log($log)
{
if (!method_exists($log, "info")) {
throw new InvalidArgumentException("logger need have method 'info(\$message)'");
}
if (!method_exists($log, "error")) {
throw new InvalidArgumentException("logger need have method 'error(\$message)'");
}
$this->log = $log;
}
}
OOP面向对象形式的初使化配置的更多相关文章
- c#构造初使化的顺序
这个很基础的知识,但我至今才意识到它.想想也很失败. 直接上代码:很简单 public class Base { ; public Base() { System.Console.WriteLine( ...
- jQuery源码学习扒一扒jQuery对象初使化
神奇的jQuery可以这样玩jQuery("#id").css()或 jQuery("#id").html() 这么玩jQuery("#id" ...
- Nhibernate初入门基本配置(一)
文章出处:http://www.cnblogs.com/GoodHelper/archive/2011/02/14/nhiberante_01.html 一.NHibernate简介 什么是?NHib ...
- SpringBoot 正式环境必不可少的外部化配置
前言 <[源码解析]凭什么?spring boot 一个 jar 就能开发 web 项目> 中有读者反应: 部署后运维很不方便,比较修改一个 IP 配置,需要重新打包. 这一点我是深有体会 ...
- 关于SpringBoot的外部化配置使用记录
关于SpringBoot的外部化配置使用记录 声明: 若有任何纰漏.错误请不吝指出! 记录下使用SpringBoot配置时遇到的一些麻烦,虽然这种麻烦是因为知识匮乏导致的. 记录下避免一段时间后自己又 ...
- Spring配置文件外部化配置及.properties的通用方法
摘要:本文深入探讨了配置化文件(即.properties)的普遍应用方式.包括了Spring.一般的.远程的三种使用方案. 关键词:.properties, Spring, Disconf, Java ...
- 使用Visual Studio Code开发Asp.Net Core WebApi学习笔记(七)-- 结构化配置
本篇将记录.Net Core里颇有特色的结构化配置的使用方法. 相比较之前通过Web.Config或者App.Config配置文件里使用xml节点定义配置内容的方式,.Net Core在配置系统上发生 ...
- 面向UI编程:ui.js 1.0 粗糙版本发布,分布式开发+容器化+组件化+配置化框架,从无到有的艰难创造
时隔第一次被UI思路激励,到现在1.0的粗糙版本发布,掐指一算整整半年了.半年之间,有些细节不断推翻重做,再推翻再重做.时隔今日,终于能先出来个东西了,这个版本很粗糙,主体功能大概能实现了,但是还是有 ...
- Dubbo 新编程模型之外部化配置
外部化配置(External Configuration) 在Dubbo 注解驱动例子中,无论是服务提供方,还是服务消费方,均需要转配相关配置Bean: @Bean public Applicatio ...
随机推荐
- npm、webpack、vue-cli 快速上手
npm+webpack+vue-cli快速上手 Node.js npm 什么是Node.js 以及npm 简单的来说 Node.js 就是运行在服务端的JavaScript,基于Chrome ...
- Codeforces 1141F2(贪心、预处理)
要点 一开始dp然后码力太辣鸡并且算法带假于是调了很久一交还WA在28-- 吐槽完毕.后来想拿栈优化dp时发现其实完全不需要dp,贪心选取即可,当前的不兼容就干脆不要它了,结果不会变差.然后想要什么就 ...
- Net Core下通过Proxy 模式
Net Core下通过Proxy 模式 NET Core下的WCF客户端也是开源的,这次发布.NET Core 2.0,同时也发布了 WCF for .NET Core 2.0.0, 本文介绍在.NE ...
- Kestrel服务器启动并处理Http请求
从Hosting开始 知识点: 1.Kestrel服务器启动并处理Http请求的过程. 2.Startup的作用. 源码飘香: 总结: asp.net core将web开发拆分为多个独立的组件,大 ...
- JavaSE---ThreadLocal
1.Java为线程安全提供了工具类,如ThreadLocal等: 2.ThreadLocal类是一个 线程局部变量 ,通过将 ”数据“ 放在ThreadLocal中,即可在每条线程中创建一个 ...
- missfresh问题记录
一.基本信息 1.登陆机器 ssh lina02@mjump.missfresh.net -p2222 二.问题 1.分页问题:job_id为空时能查询出来(笛卡尔乘积),需要加上AND res ...
- Java VisualVM添加Visual GC插件
1.访问地址:https://visualvm.github.io/pluginscenters.html,找到自己JDK版本对应的插件下载地址(我的JDK版本为1.7.0_67): 2.点击该链接进 ...
- 表单验证插件jquery.validate.js
最常使用JavaScript的场合就是表单的验证,而jQuery作为一个优秀的JavaScript库,也提供了一个优秀的表单验证插件----Validation.Validation是历史最悠久的jQ ...
- Jquery each跳出循环
Jquery each跳出循环break--return false--跳出所有循环continue--return true--跳出当前循环
- JS将人民币小写金额转换为大写
/** 数字金额大写转换(可以处理整数,小数,负数) */ function smalltoBIG(n) { var fraction = ['角', '分']; var digit = ['零', ...