| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 6 | * |
|---|
| 7 | * http://www.lockon.co.jp/ |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or |
|---|
| 10 | * modify it under the terms of the GNU General Public License |
|---|
| 11 | * as published by the Free Software Foundation; either version 2 |
|---|
| 12 | * of the License, or (at your option) any later version. |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * APIの抽象クラス |
|---|
| 26 | * |
|---|
| 27 | * @package Api |
|---|
| 28 | * @author LOCKON CO.,LTD. |
|---|
| 29 | * @version $Id$ |
|---|
| 30 | */ |
|---|
| 31 | |
|---|
| 32 | abstract class SC_Api_Abstract { |
|---|
| 33 | |
|---|
| 34 | /** 認証タイプ */ |
|---|
| 35 | const API_AUTH_TYPE_REFERER = '1'; // リファラー |
|---|
| 36 | const API_AUTH_TYPE_SESSION_TOKEN = '2'; // CSRF TOKEN |
|---|
| 37 | const API_AUTH_TYPE_API_SIGNATURE = '3'; // API 署名認証 推奨 |
|---|
| 38 | const API_AUTH_TYPE_CUSTOMER = '4'; // 会員認証 |
|---|
| 39 | const API_AUTH_TYPE_MEMBER = '5'; // 管理者認証 |
|---|
| 40 | const API_AUTH_TYPE_CUSTOMER_LOGIN_SESSION = '6'; // 顧客ログインセッションが有効 |
|---|
| 41 | const API_AUTH_TYPE_MEMBER_LOGIN_SESSION = '7'; // 管理者ログインセッションが有効 |
|---|
| 42 | const API_AUTH_TYPE_IP = '8'; // IP認証 |
|---|
| 43 | const API_AUTH_TYPE_HOST = '9'; // ホスト認証 |
|---|
| 44 | const API_AUTH_TYPE_SSL = '10'; // SSL強制 |
|---|
| 45 | const API_AUTH_TYPE_OPEN = '99'; // 完全オープン |
|---|
| 46 | |
|---|
| 47 | /** API Operation default */ |
|---|
| 48 | protected $operation_name = 'operation_name'; |
|---|
| 49 | protected $operation_description = 'operation description'; |
|---|
| 50 | protected $default_auth_types = '0'; // |区切り |
|---|
| 51 | protected $default_enable = '0'; |
|---|
| 52 | protected $default_is_log = '0'; |
|---|
| 53 | protected $default_sub_data = ''; |
|---|
| 54 | |
|---|
| 55 | protected $status = true; |
|---|
| 56 | protected $arrErr = array(); |
|---|
| 57 | |
|---|
| 58 | final public function __construct() {} |
|---|
| 59 | |
|---|
| 60 | final public function __destruct() {} |
|---|
| 61 | |
|---|
| 62 | abstract public function doAction($arrParam); |
|---|
| 63 | |
|---|
| 64 | abstract public function getResponseGroupName(); |
|---|
| 65 | |
|---|
| 66 | abstract protected function lfInitParam(&$objFormParam); |
|---|
| 67 | |
|---|
| 68 | public function getResponseArray() { |
|---|
| 69 | return $this->arrResponse; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | public function getErrorArray() { |
|---|
| 73 | return $this->arrErr; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | public function getDefaultConfig() { |
|---|
| 77 | $arrApiConfig = array(); |
|---|
| 78 | $arrApiConfig['operation_name'] = $this->operation_name; |
|---|
| 79 | $arrApiConfig['operation_description'] = $this->operation_description; |
|---|
| 80 | $arrApiConfig['auth_types'] = $this->default_auth_types; |
|---|
| 81 | $arrApiConfig['enable'] = $this->default_enable; |
|---|
| 82 | $arrApiConfig['is_log'] = $this->default_is_log; |
|---|
| 83 | $arrApiConfig['sub_data'] = $this->default_sub_data; |
|---|
| 84 | return $arrApiConfig; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | protected function setResponse($key, $data) { |
|---|
| 88 | $this->arrResponse[$key] = $data; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | protected function addError($arrErr) { |
|---|
| 92 | $this->arrErr = array_merge((array)$this->arrErr, (array)$arrErr); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | protected function isParamError() { |
|---|
| 96 | return !SC_Utils_Ex::isBlank($this->arrErr); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | protected function checkErrorExtended($arrParam) { |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | protected function doInitParam($arrParam = array()) { |
|---|
| 103 | $this->objFormParam = new SC_FormParam_Ex(); |
|---|
| 104 | $this->lfInitParam($this->objFormParam); |
|---|
| 105 | $this->objFormParam->setParam($arrParam); |
|---|
| 106 | $this->objFormParam->convParam(); |
|---|
| 107 | $this->arrErr = $this->objFormParam->checkError(false); |
|---|
| 108 | $this->arrErr = array_merge((array)$this->arrErr, (array)$this->checkErrorExtended($arrParam)); |
|---|
| 109 | return $this->objFormParam->getHashArray(); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | public function getRequestValidate() { |
|---|
| 113 | $arrParam = $this->objFormParam->getHashArray(); |
|---|
| 114 | if (!SC_Utils_Ex::isBlank($arrParam)) { |
|---|
| 115 | return $arrParam; |
|---|
| 116 | } |
|---|
| 117 | return; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | } |
|---|