mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-01 05:44:41 +03:00
Use autoload for \Mibew\API\* classes
This commit is contained in:
parent
43077feb01
commit
10b8d4b2e4
@ -24,10 +24,6 @@ use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(MIBEW_FS_ROOT.'/libs/track.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_chat_interaction.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php');
|
||||
|
||||
/**
|
||||
* Names for chat-related cookies
|
||||
|
@ -15,12 +15,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Mibew\API;
|
||||
|
||||
/**
|
||||
* Implements Mibew API specification version 1.0
|
||||
*
|
||||
* @todo May be use regular methods instead of static one
|
||||
*/
|
||||
Class MibewAPI {
|
||||
class API {
|
||||
|
||||
/**
|
||||
* Version of the MIBEW API protocol implemented by the class
|
||||
@ -28,7 +30,7 @@ Class MibewAPI {
|
||||
const PROTOCOL_VERSION = '1.0';
|
||||
|
||||
/**
|
||||
* Array of MibewAPI objects
|
||||
* Array of \Mibew\API\API objects
|
||||
* @var array
|
||||
*/
|
||||
protected static $interactions = array();
|
||||
@ -36,22 +38,22 @@ Class MibewAPI {
|
||||
/**
|
||||
* An object that encapsulates type of the interaction
|
||||
*
|
||||
* @var MibewAPIInteraction
|
||||
* @var \Mibew\API\Interaction
|
||||
*/
|
||||
protected $interaction = NULL;
|
||||
|
||||
/**
|
||||
* Returns MibewAPI object
|
||||
* Returns \Mibew\API\API object
|
||||
*
|
||||
* @param string $class_name A name of the interaction type class
|
||||
* @return MibeAPI object
|
||||
* @throws MibewAPIException
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public static function getAPI($class_name) {
|
||||
if (! class_exists($class_name)) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Wrong interaction type",
|
||||
MibewAPIException::WRONG_INTERACTION_TYPE
|
||||
APIException::WRONG_INTERACTION_TYPE
|
||||
);
|
||||
}
|
||||
if (empty(self::$interactions[$class_name])) {
|
||||
@ -63,9 +65,9 @@ Class MibewAPI {
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param MibewAPIInteraction $interaction Interaction type object
|
||||
* @param \Mibew\API\Interaction $interaction Interaction type object
|
||||
*/
|
||||
protected function __construct(MibewAPIInteraction $interaction) {
|
||||
protected function __construct(Interaction\Interaction $interaction) {
|
||||
$this->interaction = $interaction;
|
||||
}
|
||||
|
||||
@ -74,56 +76,56 @@ Class MibewAPI {
|
||||
*
|
||||
* @param array $package Package array. See Mibew API for details.
|
||||
* @param array $trusted_signatures Array of trusted signatures.
|
||||
* @throws MibewAPIException
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function checkPackage($package, $trusted_signatures) {
|
||||
// Check signature
|
||||
if (! isset($package['signature'])) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Package signature is empty",
|
||||
MibewAPIException::EMPTY_SIGNATURE
|
||||
APIException::EMPTY_SIGNATURE
|
||||
);
|
||||
}
|
||||
if (! in_array($package['signature'], $trusted_signatures)) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Package signed with untrusted signature",
|
||||
MibewAPIException::UNTRUSTED_SIGNATURE
|
||||
APIException::UNTRUSTED_SIGNATURE
|
||||
);
|
||||
}
|
||||
|
||||
// Check protocol
|
||||
if (empty($package['proto'])) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Package protocol is empty",
|
||||
MibewAPIException::EMPTY_PROTOCOL
|
||||
APIException::EMPTY_PROTOCOL
|
||||
);
|
||||
}
|
||||
if ($package['proto'] != self::PROTOCOL_VERSION) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Wrong package protocol version '{$package['proto']}'",
|
||||
MibewAPIException::WRONG_PROTOCOL_VERSION
|
||||
APIException::WRONG_PROTOCOL_VERSION
|
||||
);
|
||||
}
|
||||
|
||||
// Check async flag
|
||||
if (! isset($package['async'])) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"'async' flag is missed",
|
||||
MibewAPIException::ASYNC_FLAG_MISSED
|
||||
APIException::ASYNC_FLAG_MISSED
|
||||
);
|
||||
}
|
||||
if (! is_bool($package['async'])) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Wrong 'async' flag value",
|
||||
MibewAPIException::WRONG_ASYNC_FLAG_VALUE
|
||||
APIException::WRONG_ASYNC_FLAG_VALUE
|
||||
);
|
||||
}
|
||||
|
||||
// Package must have at least one request
|
||||
if (empty($package['requests'])) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Empty requests set",
|
||||
MibewAPIException::EMPTY_REQUESTS
|
||||
APIException::EMPTY_REQUESTS
|
||||
);
|
||||
}
|
||||
// Check requests in package
|
||||
@ -136,21 +138,21 @@ Class MibewAPI {
|
||||
* Validate request
|
||||
*
|
||||
* @param array $request Request array. See Mibew API for details.
|
||||
* @throws MibewAPIException
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function checkRequest($request) {
|
||||
// Check token
|
||||
if (empty($request['token'])) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Empty request token",
|
||||
MibewAPIException::EMPTY_TOKEN
|
||||
APIException::EMPTY_TOKEN
|
||||
);
|
||||
}
|
||||
// Request must have at least one function
|
||||
if (empty($request['functions'])) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Empty functions set",
|
||||
MibewAPIException::EMPTY_FUNCTIONS
|
||||
APIException::EMPTY_FUNCTIONS
|
||||
);
|
||||
}
|
||||
// Check functions in request
|
||||
@ -165,14 +167,14 @@ Class MibewAPI {
|
||||
* @param array $function Function array. See Mibew API for details.
|
||||
* @param boolean $filter_reserved_functions Determine if function name must not be in
|
||||
* reserved list
|
||||
* @throws MibewAPIException
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function checkFunction($function, $filter_reserved_functions = false) {
|
||||
// Check function name
|
||||
if (empty($function['function'])) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
'Cannot call for function with empty name',
|
||||
MibewAPIException::EMPTY_FUNCTION_NAME
|
||||
APIException::EMPTY_FUNCTION_NAME
|
||||
);
|
||||
}
|
||||
if ($filter_reserved_functions) {
|
||||
@ -180,23 +182,23 @@ Class MibewAPI {
|
||||
$function['function'],
|
||||
$this->interaction->reservedFunctionNames
|
||||
)) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"'{$function['function']}' is reserved function name",
|
||||
MibewAPIException::FUNCTION_NAME_RESERVED
|
||||
APIException::FUNCTION_NAME_RESERVED
|
||||
);
|
||||
}
|
||||
}
|
||||
// Check function's arguments
|
||||
if (empty($function['arguments'])) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"There are no arguments in '{$function['function']}' function",
|
||||
MibewAPIException::EMPTY_ARGUMENTS
|
||||
APIException::EMPTY_ARGUMENTS
|
||||
);
|
||||
}
|
||||
if (! is_array($function['arguments'])) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Arguments must be an array",
|
||||
MibewAPIException::WRONG_ARGUMENTS_TYPE
|
||||
APIException::WRONG_ARGUMENTS_TYPE
|
||||
);
|
||||
}
|
||||
$unset_arguments = array_diff(
|
||||
@ -204,9 +206,9 @@ Class MibewAPI {
|
||||
array_keys($function['arguments'])
|
||||
);
|
||||
if (! empty($unset_arguments)) {
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Arguments '" . implode("', '", $unset_arguments) . "' must be set",
|
||||
MibewAPIException::OBLIGATORY_ARGUMENTS_MISSED
|
||||
APIException::OBLIGATORY_ARGUMENTS_MISSED
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -234,7 +236,7 @@ Class MibewAPI {
|
||||
* @param string $package Encoded package
|
||||
* @param array $trusted_signatures List of trusted signatures
|
||||
* @return array Decoded package array. See Mibew API for details.
|
||||
* @throws MibewAPIException
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function decodePackage($package, $trusted_signatures) {
|
||||
// Try to decode package
|
||||
@ -245,10 +247,10 @@ Class MibewAPI {
|
||||
$json_error_code = json_last_error();
|
||||
if ($json_error_code != JSON_ERROR_NONE) {
|
||||
// Not valid JSON
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Package have invalid json structure. " .
|
||||
"JSON error code is '" . $json_error_code . "'",
|
||||
MibewAPIException::NOT_VALID_JSON
|
||||
APIException::NOT_VALID_JSON
|
||||
);
|
||||
}
|
||||
$this->checkPackage($decoded_package, $trusted_signatures);
|
||||
@ -279,15 +281,15 @@ Class MibewAPI {
|
||||
|
||||
/**
|
||||
* Search 'result' function in $function_list. If request contains more than one result
|
||||
* functions throws an MibewAPIException
|
||||
* functions throws an \Mibew\API\APIException
|
||||
*
|
||||
* @param array $functions_list Array of functions. See MibewAPI for function structure
|
||||
* details
|
||||
* @param array $functions_list Array of functions. See Mibew API specification
|
||||
* for function structure details
|
||||
* @param mixed $existance Control existance of the 'result' function in request.
|
||||
* Use boolean true if 'result' function must exists in request, boolean false if must not
|
||||
* and null if it doesn't matter.
|
||||
* @return mixed Function array if 'result' function found and NULL otherwise
|
||||
* @throws MibewAPIException
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function getResultFunction ($functions_list, $existence = null) {
|
||||
$result_function = null;
|
||||
@ -296,9 +298,9 @@ Class MibewAPI {
|
||||
if ($function['function'] == 'result') {
|
||||
if (! is_null($result_function)) {
|
||||
// Another 'result' function found
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Function 'result' already exists in request",
|
||||
MibewAPIException::RESULT_FUNCTION_ALREADY_EXISTS
|
||||
APIException::RESULT_FUNCTION_ALREADY_EXISTS
|
||||
);
|
||||
}
|
||||
// First 'result' function found
|
||||
@ -307,118 +309,20 @@ Class MibewAPI {
|
||||
}
|
||||
if ($existence === true && is_null($result_function)) {
|
||||
// 'result' function must present in request
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"There is no 'result' function in request",
|
||||
MibewAPIException::NO_RESULT_FUNCTION
|
||||
APIException::NO_RESULT_FUNCTION
|
||||
);
|
||||
}
|
||||
if ($existence === false && !is_null($result_function)) {
|
||||
// 'result' function must not present in request
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"There is 'result' function in request",
|
||||
MibewAPIException::RESULT_FUNCTION_EXISTS
|
||||
APIException::RESULT_FUNCTION_EXISTS
|
||||
);
|
||||
}
|
||||
return $result_function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mibew API Exception class.
|
||||
*/
|
||||
class MibewAPIException extends Exception {
|
||||
/**
|
||||
* Async flag is missed.
|
||||
*/
|
||||
const ASYNC_FLAG_MISSED = 1;
|
||||
/**
|
||||
* There are no arguments in function
|
||||
*/
|
||||
const EMPTY_ARGUMENTS = 2;
|
||||
/**
|
||||
* Cannot call for function with empty name
|
||||
*/
|
||||
const EMPTY_FUNCTION_NAME = 3;
|
||||
/**
|
||||
* Functions set is empty
|
||||
*/
|
||||
const EMPTY_FUNCTIONS = 4;
|
||||
/**
|
||||
* Package protocol is empty
|
||||
*/
|
||||
const EMPTY_PROTOCOL = 5;
|
||||
/**
|
||||
* Requests set is empty
|
||||
*/
|
||||
const EMPTY_REQUESTS = 6;
|
||||
/**
|
||||
* Package signature is empty
|
||||
*/
|
||||
const EMPTY_SIGNATURE = 7;
|
||||
/**
|
||||
* Request token is empty
|
||||
*/
|
||||
const EMPTY_TOKEN = 8;
|
||||
/**
|
||||
* Wrong reference. Reference variable is empty
|
||||
*/
|
||||
const EMPTY_VARIABLE_IN_REFERENCE = 9;
|
||||
/**
|
||||
* This function name is reserved
|
||||
*/
|
||||
const FUNCTION_NAME_RESERVED = 10;
|
||||
/**
|
||||
* There is no result function
|
||||
*/
|
||||
const NO_RESULT_FUNCTION = 11;
|
||||
/**
|
||||
* Package have not valid JSON structure
|
||||
*/
|
||||
const NOT_VALID_JSON = 12;
|
||||
/**
|
||||
* Some of the function's obligatory arguments are missed
|
||||
*/
|
||||
const OBLIGATORY_ARGUMENTS_MISSED = 13;
|
||||
/**
|
||||
* Request contains more than one result functions
|
||||
*/
|
||||
const RESULT_FUNCTION_ALREADY_EXISTS = 14;
|
||||
/**
|
||||
* There is 'result' function in request
|
||||
*/
|
||||
const RESULT_FUNCTION_EXISTS = 15;
|
||||
/**
|
||||
* Package signed with untrusted signature
|
||||
*/
|
||||
const UNTRUSTED_SIGNATURE = 16;
|
||||
/**
|
||||
* Wrong reference. Variable is undefined in functions results
|
||||
*/
|
||||
const VARIABLE_IS_UNDEFINED_IN_REFERENCE = 17;
|
||||
/**
|
||||
* Variable is undefined in function's results
|
||||
*/
|
||||
const VARIABLE_IS_UNDEFINED_IN_RESULT = 18;
|
||||
/**
|
||||
* Arguments must be an array
|
||||
*/
|
||||
const WRONG_ARGUMENTS_TYPE = 19;
|
||||
/**
|
||||
* Async flag value is wrong
|
||||
*/
|
||||
const WRONG_ASYNC_FLAG_VALUE = 20;
|
||||
/**
|
||||
* Wrong reference. Function with this number does not call yet
|
||||
*/
|
||||
const WRONG_FUNCTION_NUM_IN_REFERENCE = 21;
|
||||
/**
|
||||
* Wrong interaction type
|
||||
*/
|
||||
const WRONG_INTERACTION_TYPE = 22;
|
||||
/**
|
||||
* Wrong package protocol version
|
||||
*/
|
||||
const WRONG_PROTOCOL_VERSION = 23;
|
||||
}
|
||||
|
||||
?>
|
118
src/mibew/libs/classes/Mibew/API/APIException.php
Normal file
118
src/mibew/libs/classes/Mibew/API/APIException.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Mibew\API;
|
||||
|
||||
/**
|
||||
* Mibew API Exception class.
|
||||
*/
|
||||
class APIException extends \Exception {
|
||||
/**
|
||||
* Async flag is missed.
|
||||
*/
|
||||
const ASYNC_FLAG_MISSED = 1;
|
||||
/**
|
||||
* There are no arguments in function
|
||||
*/
|
||||
const EMPTY_ARGUMENTS = 2;
|
||||
/**
|
||||
* Cannot call for function with empty name
|
||||
*/
|
||||
const EMPTY_FUNCTION_NAME = 3;
|
||||
/**
|
||||
* Functions set is empty
|
||||
*/
|
||||
const EMPTY_FUNCTIONS = 4;
|
||||
/**
|
||||
* Package protocol is empty
|
||||
*/
|
||||
const EMPTY_PROTOCOL = 5;
|
||||
/**
|
||||
* Requests set is empty
|
||||
*/
|
||||
const EMPTY_REQUESTS = 6;
|
||||
/**
|
||||
* Package signature is empty
|
||||
*/
|
||||
const EMPTY_SIGNATURE = 7;
|
||||
/**
|
||||
* Request token is empty
|
||||
*/
|
||||
const EMPTY_TOKEN = 8;
|
||||
/**
|
||||
* Wrong reference. Reference variable is empty
|
||||
*/
|
||||
const EMPTY_VARIABLE_IN_REFERENCE = 9;
|
||||
/**
|
||||
* This function name is reserved
|
||||
*/
|
||||
const FUNCTION_NAME_RESERVED = 10;
|
||||
/**
|
||||
* There is no result function
|
||||
*/
|
||||
const NO_RESULT_FUNCTION = 11;
|
||||
/**
|
||||
* Package have not valid JSON structure
|
||||
*/
|
||||
const NOT_VALID_JSON = 12;
|
||||
/**
|
||||
* Some of the function's obligatory arguments are missed
|
||||
*/
|
||||
const OBLIGATORY_ARGUMENTS_MISSED = 13;
|
||||
/**
|
||||
* Request contains more than one result functions
|
||||
*/
|
||||
const RESULT_FUNCTION_ALREADY_EXISTS = 14;
|
||||
/**
|
||||
* There is 'result' function in request
|
||||
*/
|
||||
const RESULT_FUNCTION_EXISTS = 15;
|
||||
/**
|
||||
* Package signed with untrusted signature
|
||||
*/
|
||||
const UNTRUSTED_SIGNATURE = 16;
|
||||
/**
|
||||
* Wrong reference. Variable is undefined in functions results
|
||||
*/
|
||||
const VARIABLE_IS_UNDEFINED_IN_REFERENCE = 17;
|
||||
/**
|
||||
* Variable is undefined in function's results
|
||||
*/
|
||||
const VARIABLE_IS_UNDEFINED_IN_RESULT = 18;
|
||||
/**
|
||||
* Arguments must be an array
|
||||
*/
|
||||
const WRONG_ARGUMENTS_TYPE = 19;
|
||||
/**
|
||||
* Async flag value is wrong
|
||||
*/
|
||||
const WRONG_ASYNC_FLAG_VALUE = 20;
|
||||
/**
|
||||
* Wrong reference. Function with this number does not call yet
|
||||
*/
|
||||
const WRONG_FUNCTION_NUM_IN_REFERENCE = 21;
|
||||
/**
|
||||
* Wrong interaction type
|
||||
*/
|
||||
const WRONG_INTERACTION_TYPE = 22;
|
||||
/**
|
||||
* Wrong package protocol version
|
||||
*/
|
||||
const WRONG_PROTOCOL_VERSION = 23;
|
||||
}
|
||||
|
||||
?>
|
@ -15,10 +15,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Mibew\API;
|
||||
|
||||
/**
|
||||
* Implements functions execution context
|
||||
*/
|
||||
Class MibewAPIExecutionContext {
|
||||
class ExecutionContext {
|
||||
/**
|
||||
* Values which returns after execution of all functions in request
|
||||
* @var array
|
||||
@ -35,7 +37,7 @@ Class MibewAPIExecutionContext {
|
||||
* Returns requets results
|
||||
*
|
||||
* @return array Request results
|
||||
* @see MibewAPIExecutionContext::$return
|
||||
* @see \Mibew\API\ExecutionContext::$return
|
||||
*/
|
||||
public function getResults () {
|
||||
return $this->return;
|
||||
@ -46,7 +48,7 @@ Class MibewAPIExecutionContext {
|
||||
*
|
||||
* @param array $function Function array. See MibewAPI for details.
|
||||
* @return array Arguments list
|
||||
* @throws MibewAPIException
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function getArgumentsList ($function) {
|
||||
$arguments = $function['arguments'];
|
||||
@ -55,20 +57,20 @@ Class MibewAPIExecutionContext {
|
||||
// Check target function in context
|
||||
if (! isset($this->functions_results[$func_num - 1])) {
|
||||
// Wrong function num
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Wrong reference in '{$function['function']}' function. " .
|
||||
"Function #{$func_num} does not call yet.",
|
||||
MibewAPIException::WRONG_FUNCTION_NUM_IN_REFERENCE
|
||||
APIException::WRONG_FUNCTION_NUM_IN_REFERENCE
|
||||
);
|
||||
}
|
||||
|
||||
// Check reference
|
||||
if (empty($arguments[$variable])) {
|
||||
// Empty argument that should contains reference
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Wrong reference in '{$function['function']}' function. " .
|
||||
"Empty {$variable} argument.",
|
||||
MibewAPIException::EMPTY_VARIABLE_IN_REFERENCE
|
||||
APIException::EMPTY_VARIABLE_IN_REFERENCE
|
||||
);
|
||||
}
|
||||
$reference_to = $arguments[$variable];
|
||||
@ -76,11 +78,11 @@ Class MibewAPIExecutionContext {
|
||||
// Check target value
|
||||
if (! isset($this->functions_results[$func_num - 1][$reference_to])) {
|
||||
// Undefined target value
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Wrong reference in '{$function['function']}' function. " .
|
||||
"There is no '{$reference_to}' argument in #{$func_num} " .
|
||||
"function results",
|
||||
MibewAPIException::VARIABLE_IS_UNDEFINED_IN_REFERENCE
|
||||
APIException::VARIABLE_IS_UNDEFINED_IN_REFERENCE
|
||||
);
|
||||
}
|
||||
|
||||
@ -95,7 +97,7 @@ Class MibewAPIExecutionContext {
|
||||
*
|
||||
* @param array $function Function array. See MibewAPI for details.
|
||||
* @param array $results Associative array of the function results.
|
||||
* @throws MibewAPIException
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function storeFunctionResults ($function, $results) {
|
||||
// Check if function return correct results
|
||||
@ -104,10 +106,10 @@ Class MibewAPIExecutionContext {
|
||||
foreach ($function['arguments']['return'] as $name => $alias) {
|
||||
if (! isset($results[$name])) {
|
||||
// Value that defined in 'return' argument is undefined
|
||||
throw new MibewAPIException(
|
||||
throw new APIException(
|
||||
"Variable with name '{$name}' is undefined in the " .
|
||||
"results of the '{$function['function']}' function",
|
||||
MibewAPIException::VARIABLE_IS_UNDEFINED_IN_RESULT
|
||||
APIException::VARIABLE_IS_UNDEFINED_IN_RESULT
|
||||
);
|
||||
}
|
||||
$this->return[$alias] = $results[$name];
|
@ -15,14 +15,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Mibew\API\Interaction;
|
||||
|
||||
/**
|
||||
* Implements Mibew Core - Mibew Chat Window interaction
|
||||
*/
|
||||
class MibewAPIChatInteraction extends MibewAPIInteraction {
|
||||
class ChatInteraction extends Interaction {
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
* @var array
|
||||
* @see MibewAPIInteraction::$obligatoryArgumnents
|
||||
* @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
|
||||
*/
|
||||
protected $obligatoryArguments = array(
|
||||
'*' => array(
|
||||
@ -39,7 +41,7 @@ class MibewAPIChatInteraction extends MibewAPIInteraction {
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see MibewAPIInteraction::$reservedFunctionNames
|
||||
* @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result'
|
@ -15,10 +15,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Mibew\API\Interaction;
|
||||
|
||||
/**
|
||||
* Encapsulates interaction type
|
||||
*/
|
||||
abstract class MibewAPIInteraction {
|
||||
abstract class Interaction {
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
*
|
@ -15,14 +15,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Mibew\API\Interaction;
|
||||
|
||||
/**
|
||||
* Implements Mibew Core - Mibew invitation waiting window interaction
|
||||
*/
|
||||
class MibewAPIInviteInteraction extends MibewAPIInteraction {
|
||||
class InviteInteraction extends Interaction {
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
* @var array
|
||||
* @see MibewAPIInteraction::$obligatoryArgumnents
|
||||
* @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
|
||||
*/
|
||||
protected $obligatoryArguments = array(
|
||||
'*' => array(
|
||||
@ -38,7 +40,7 @@ class MibewAPIInviteInteraction extends MibewAPIInteraction {
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see MibewAPIInteraction::$reservedFunctionNames
|
||||
* @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result'
|
@ -15,14 +15,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Mibew\API\Interaction;
|
||||
|
||||
/**
|
||||
* Implements Mibew Core - Mibew Users list interaction
|
||||
*/
|
||||
class MibewAPIUsersInteraction extends MibewAPIInteraction {
|
||||
class UsersInteraction extends Interaction {
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
* @var array
|
||||
* @see MibewAPIInteraction::$obligatoryArgumnents
|
||||
* @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
|
||||
*/
|
||||
protected $obligatoryArguments = array(
|
||||
'*' => array(
|
||||
@ -41,7 +43,7 @@ class MibewAPIUsersInteraction extends MibewAPIInteraction {
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see MibewAPIInteraction::$reservedFunctionNames
|
||||
* @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result'
|
@ -18,7 +18,7 @@
|
||||
namespace Mibew\RequestProcessor;
|
||||
|
||||
// Import namespaces and classes of the core
|
||||
use \MibewAPI;
|
||||
use Mibew\API\API as MibewAPI;
|
||||
use Mibew\RequestProcessor\Exception\InviteProcessorException;
|
||||
|
||||
/**
|
||||
@ -68,12 +68,12 @@ class InviteProcessor extends ClientSideProcessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an instance of the MibewAPI class.
|
||||
* Creates and returns an instance of the \Mibew\API\API class.
|
||||
*
|
||||
* @return MibewAPI
|
||||
* @return \Mibew\API\API
|
||||
*/
|
||||
protected function getMibewAPIInstance() {
|
||||
return MibewAPI::getAPI('MibewAPIInviteInteraction');
|
||||
return MibewAPI::getAPI('\\Mibew\\API\\Interaction\\InviteInteraction');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,6 @@
|
||||
namespace Mibew\RequestProcessor;
|
||||
|
||||
// Import namespaces and classes of the core
|
||||
use \MibewAPIExecutionContext;
|
||||
use Mibew\Database;
|
||||
use Mibew\EventDispatcher;
|
||||
use Mibew\RequestProcessor\Exception\RequestProcessorException;
|
||||
@ -97,7 +96,7 @@ abstract class Processor {
|
||||
|
||||
/**
|
||||
* Instance of the MibewAPI class
|
||||
* @var \MibewAPI
|
||||
* @var \Mibew\API\API
|
||||
*/
|
||||
protected $mibewAPI = null;
|
||||
|
||||
@ -333,7 +332,7 @@ abstract class Processor {
|
||||
* @return array Array of requests results.
|
||||
*/
|
||||
protected function processRequest($request, $result_function = null) {
|
||||
$context = new MibewAPIExecutionContext();
|
||||
$context = new \Mibew\API\ExecutionContext();
|
||||
|
||||
// Get result functions
|
||||
$result_function = $this->mibewAPI->getResultFunction(
|
||||
@ -368,10 +367,10 @@ abstract class Processor {
|
||||
* Process function
|
||||
*
|
||||
* @param array $function 'Function' array. See Mibew API for details
|
||||
* @param MibewAPIExecutionContext &$context Execution context
|
||||
* @param \Mibew\API\ExecutionContext &$context Execution context
|
||||
* @return boolean lase if function returns errorCode and errorCode differs from 0.
|
||||
*/
|
||||
protected function processFunction($function, MibewAPIExecutionContext &$context) {
|
||||
protected function processFunction($function, \Mibew\API\ExecutionContext &$context) {
|
||||
// Get function arguments with replaced references
|
||||
$arguments = $context->getArgumentsList($function);
|
||||
|
||||
@ -523,9 +522,9 @@ abstract class Processor {
|
||||
protected function checkFunction($function) {}
|
||||
|
||||
/**
|
||||
* Creates and returns an instance of the MibewAPI class.
|
||||
* Creates and returns an instance of the \Mibew\API\API class.
|
||||
*
|
||||
* @return MibewAPI
|
||||
* @return \Mibew\API\API
|
||||
*/
|
||||
protected abstract function getMibewAPIInstance();
|
||||
}
|
||||
|
@ -18,9 +18,9 @@
|
||||
namespace Mibew\RequestProcessor;
|
||||
|
||||
// Import namespaces and classes of the core
|
||||
use \MibewAPI;
|
||||
use Mibew\Settings;
|
||||
use Mibew\Thread;
|
||||
use Mibew\API\API as MibewAPI;
|
||||
use Mibew\RequestProcessor\Exception\ThreadProcessorException;
|
||||
|
||||
/**
|
||||
@ -134,12 +134,12 @@ class ThreadProcessor extends ClientSideProcessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an instance of the MibewAPI class.
|
||||
* Creates and returns an instance of the \Mibew\API\API class.
|
||||
*
|
||||
* @return \MibewAPI
|
||||
* @return \Mibew\API\API
|
||||
*/
|
||||
protected function getMibewAPIInstance() {
|
||||
return MibewAPI::getAPI('MibewAPIChatInteraction');
|
||||
return MibewAPI::getAPI('\\Mibew\\API\\Interaction\\ChatInteraction');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,11 +18,11 @@
|
||||
namespace Mibew\RequestProcessor;
|
||||
|
||||
// Import namespaces and classes of the core
|
||||
use \MibewAPI;
|
||||
use Mibew\Database;
|
||||
use Mibew\EventDispatcher;
|
||||
use Mibew\Settings;
|
||||
use Mibew\Thread;
|
||||
use Mibew\API\API as MibewAPI;
|
||||
use Mibew\RequestProcessor\Exception\UsersProcessorException;
|
||||
|
||||
/**
|
||||
@ -76,12 +76,12 @@ class UsersProcessor extends ClientSideProcessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an instance of the MibewAPI class.
|
||||
* Creates and returns an instance of the \Mibew\API\API class.
|
||||
*
|
||||
* @return \MibewAPI
|
||||
* @return \Mibew\API\API
|
||||
*/
|
||||
protected function getMibewAPIInstance() {
|
||||
return MibewAPI::getAPI('MibewAPIUsersInteraction');
|
||||
return MibewAPI::getAPI('\\Mibew\\API\\Interaction\\UsersInteraction');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,10 +18,6 @@
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/invitation.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_invite_interaction.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php');
|
||||
|
||||
$processor = \Mibew\RequestProcessor\InviteProcessor::getInstance();
|
||||
$processor->receiveRequest($_POST['data']);
|
||||
|
@ -22,10 +22,6 @@ require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/invitation.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/track.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_users_interaction.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php');
|
||||
|
||||
$processor = \Mibew\RequestProcessor\UsersProcessor::getInstance();
|
||||
$processor->receiveRequest($_POST['data']);
|
||||
|
@ -22,10 +22,6 @@ require_once(MIBEW_FS_ROOT.'/libs/invitation.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/captcha.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/notify.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_interaction.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_chat_interaction.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php');
|
||||
|
||||
$processor = \Mibew\RequestProcessor\ThreadProcessor::getInstance();
|
||||
$processor->receiveRequest($_POST['data']);
|
||||
|
Loading…
Reference in New Issue
Block a user