Use autoload for \Mibew\API\* classes

This commit is contained in:
Dmitriy Simushev 2013-12-27 13:53:45 +00:00
parent 43077feb01
commit 10b8d4b2e4
15 changed files with 223 additions and 208 deletions

View File

@ -24,10 +24,6 @@ use Mibew\Style\PageStyle;
// Initialize libraries // Initialize libraries
require_once(MIBEW_FS_ROOT.'/libs/track.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_chat_interaction.php');
require_once(MIBEW_FS_ROOT.'/libs/classes/mibew_api_execution_context.php');
/** /**
* Names for chat-related cookies * Names for chat-related cookies

View File

@ -15,12 +15,14 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\API;
/** /**
* Implements Mibew API specification version 1.0 * Implements Mibew API specification version 1.0
* *
* @todo May be use regular methods instead of static one * @todo May be use regular methods instead of static one
*/ */
Class MibewAPI { class API {
/** /**
* Version of the MIBEW API protocol implemented by the class * Version of the MIBEW API protocol implemented by the class
@ -28,7 +30,7 @@ Class MibewAPI {
const PROTOCOL_VERSION = '1.0'; const PROTOCOL_VERSION = '1.0';
/** /**
* Array of MibewAPI objects * Array of \Mibew\API\API objects
* @var array * @var array
*/ */
protected static $interactions = array(); protected static $interactions = array();
@ -36,22 +38,22 @@ Class MibewAPI {
/** /**
* An object that encapsulates type of the interaction * An object that encapsulates type of the interaction
* *
* @var MibewAPIInteraction * @var \Mibew\API\Interaction
*/ */
protected $interaction = NULL; protected $interaction = NULL;
/** /**
* Returns MibewAPI object * Returns \Mibew\API\API object
* *
* @param string $class_name A name of the interaction type class * @param string $class_name A name of the interaction type class
* @return MibeAPI object * @return MibeAPI object
* @throws MibewAPIException * @throws \Mibew\API\APIException
*/ */
public static function getAPI($class_name) { public static function getAPI($class_name) {
if (! class_exists($class_name)) { if (! class_exists($class_name)) {
throw new MibewAPIException( throw new APIException(
"Wrong interaction type", "Wrong interaction type",
MibewAPIException::WRONG_INTERACTION_TYPE APIException::WRONG_INTERACTION_TYPE
); );
} }
if (empty(self::$interactions[$class_name])) { if (empty(self::$interactions[$class_name])) {
@ -63,9 +65,9 @@ Class MibewAPI {
/** /**
* Class constructor * 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; $this->interaction = $interaction;
} }
@ -74,56 +76,56 @@ Class MibewAPI {
* *
* @param array $package Package array. See Mibew API for details. * @param array $package Package array. See Mibew API for details.
* @param array $trusted_signatures Array of trusted signatures. * @param array $trusted_signatures Array of trusted signatures.
* @throws MibewAPIException * @throws \Mibew\API\APIException
*/ */
public function checkPackage($package, $trusted_signatures) { public function checkPackage($package, $trusted_signatures) {
// Check signature // Check signature
if (! isset($package['signature'])) { if (! isset($package['signature'])) {
throw new MibewAPIException( throw new APIException(
"Package signature is empty", "Package signature is empty",
MibewAPIException::EMPTY_SIGNATURE APIException::EMPTY_SIGNATURE
); );
} }
if (! in_array($package['signature'], $trusted_signatures)) { if (! in_array($package['signature'], $trusted_signatures)) {
throw new MibewAPIException( throw new APIException(
"Package signed with untrusted signature", "Package signed with untrusted signature",
MibewAPIException::UNTRUSTED_SIGNATURE APIException::UNTRUSTED_SIGNATURE
); );
} }
// Check protocol // Check protocol
if (empty($package['proto'])) { if (empty($package['proto'])) {
throw new MibewAPIException( throw new APIException(
"Package protocol is empty", "Package protocol is empty",
MibewAPIException::EMPTY_PROTOCOL APIException::EMPTY_PROTOCOL
); );
} }
if ($package['proto'] != self::PROTOCOL_VERSION) { if ($package['proto'] != self::PROTOCOL_VERSION) {
throw new MibewAPIException( throw new APIException(
"Wrong package protocol version '{$package['proto']}'", "Wrong package protocol version '{$package['proto']}'",
MibewAPIException::WRONG_PROTOCOL_VERSION APIException::WRONG_PROTOCOL_VERSION
); );
} }
// Check async flag // Check async flag
if (! isset($package['async'])) { if (! isset($package['async'])) {
throw new MibewAPIException( throw new APIException(
"'async' flag is missed", "'async' flag is missed",
MibewAPIException::ASYNC_FLAG_MISSED APIException::ASYNC_FLAG_MISSED
); );
} }
if (! is_bool($package['async'])) { if (! is_bool($package['async'])) {
throw new MibewAPIException( throw new APIException(
"Wrong 'async' flag value", "Wrong 'async' flag value",
MibewAPIException::WRONG_ASYNC_FLAG_VALUE APIException::WRONG_ASYNC_FLAG_VALUE
); );
} }
// Package must have at least one request // Package must have at least one request
if (empty($package['requests'])) { if (empty($package['requests'])) {
throw new MibewAPIException( throw new APIException(
"Empty requests set", "Empty requests set",
MibewAPIException::EMPTY_REQUESTS APIException::EMPTY_REQUESTS
); );
} }
// Check requests in package // Check requests in package
@ -136,21 +138,21 @@ Class MibewAPI {
* Validate request * Validate request
* *
* @param array $request Request array. See Mibew API for details. * @param array $request Request array. See Mibew API for details.
* @throws MibewAPIException * @throws \Mibew\API\APIException
*/ */
public function checkRequest($request) { public function checkRequest($request) {
// Check token // Check token
if (empty($request['token'])) { if (empty($request['token'])) {
throw new MibewAPIException( throw new APIException(
"Empty request token", "Empty request token",
MibewAPIException::EMPTY_TOKEN APIException::EMPTY_TOKEN
); );
} }
// Request must have at least one function // Request must have at least one function
if (empty($request['functions'])) { if (empty($request['functions'])) {
throw new MibewAPIException( throw new APIException(
"Empty functions set", "Empty functions set",
MibewAPIException::EMPTY_FUNCTIONS APIException::EMPTY_FUNCTIONS
); );
} }
// Check functions in request // Check functions in request
@ -165,14 +167,14 @@ Class MibewAPI {
* @param array $function Function array. See Mibew API for details. * @param array $function Function array. See Mibew API for details.
* @param boolean $filter_reserved_functions Determine if function name must not be in * @param boolean $filter_reserved_functions Determine if function name must not be in
* reserved list * reserved list
* @throws MibewAPIException * @throws \Mibew\API\APIException
*/ */
public function checkFunction($function, $filter_reserved_functions = false) { public function checkFunction($function, $filter_reserved_functions = false) {
// Check function name // Check function name
if (empty($function['function'])) { if (empty($function['function'])) {
throw new MibewAPIException( throw new APIException(
'Cannot call for function with empty name', 'Cannot call for function with empty name',
MibewAPIException::EMPTY_FUNCTION_NAME APIException::EMPTY_FUNCTION_NAME
); );
} }
if ($filter_reserved_functions) { if ($filter_reserved_functions) {
@ -180,23 +182,23 @@ Class MibewAPI {
$function['function'], $function['function'],
$this->interaction->reservedFunctionNames $this->interaction->reservedFunctionNames
)) { )) {
throw new MibewAPIException( throw new APIException(
"'{$function['function']}' is reserved function name", "'{$function['function']}' is reserved function name",
MibewAPIException::FUNCTION_NAME_RESERVED APIException::FUNCTION_NAME_RESERVED
); );
} }
} }
// Check function's arguments // Check function's arguments
if (empty($function['arguments'])) { if (empty($function['arguments'])) {
throw new MibewAPIException( throw new APIException(
"There are no arguments in '{$function['function']}' function", "There are no arguments in '{$function['function']}' function",
MibewAPIException::EMPTY_ARGUMENTS APIException::EMPTY_ARGUMENTS
); );
} }
if (! is_array($function['arguments'])) { if (! is_array($function['arguments'])) {
throw new MibewAPIException( throw new APIException(
"Arguments must be an array", "Arguments must be an array",
MibewAPIException::WRONG_ARGUMENTS_TYPE APIException::WRONG_ARGUMENTS_TYPE
); );
} }
$unset_arguments = array_diff( $unset_arguments = array_diff(
@ -204,9 +206,9 @@ Class MibewAPI {
array_keys($function['arguments']) array_keys($function['arguments'])
); );
if (! empty($unset_arguments)) { if (! empty($unset_arguments)) {
throw new MibewAPIException( throw new APIException(
"Arguments '" . implode("', '", $unset_arguments) . "' must be set", "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 string $package Encoded package
* @param array $trusted_signatures List of trusted signatures * @param array $trusted_signatures List of trusted signatures
* @return array Decoded package array. See Mibew API for details. * @return array Decoded package array. See Mibew API for details.
* @throws MibewAPIException * @throws \Mibew\API\APIException
*/ */
public function decodePackage($package, $trusted_signatures) { public function decodePackage($package, $trusted_signatures) {
// Try to decode package // Try to decode package
@ -245,10 +247,10 @@ Class MibewAPI {
$json_error_code = json_last_error(); $json_error_code = json_last_error();
if ($json_error_code != JSON_ERROR_NONE) { if ($json_error_code != JSON_ERROR_NONE) {
// Not valid JSON // Not valid JSON
throw new MibewAPIException( throw new APIException(
"Package have invalid json structure. " . "Package have invalid json structure. " .
"JSON error code is '" . $json_error_code . "'", "JSON error code is '" . $json_error_code . "'",
MibewAPIException::NOT_VALID_JSON APIException::NOT_VALID_JSON
); );
} }
$this->checkPackage($decoded_package, $trusted_signatures); $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 * 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 * @param array $functions_list Array of functions. See Mibew API specification
* details * for function structure details
* @param mixed $existance Control existance of the 'result' function in request. * @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 * Use boolean true if 'result' function must exists in request, boolean false if must not
* and null if it doesn't matter. * and null if it doesn't matter.
* @return mixed Function array if 'result' function found and NULL otherwise * @return mixed Function array if 'result' function found and NULL otherwise
* @throws MibewAPIException * @throws \Mibew\API\APIException
*/ */
public function getResultFunction ($functions_list, $existence = null) { public function getResultFunction ($functions_list, $existence = null) {
$result_function = null; $result_function = null;
@ -296,9 +298,9 @@ Class MibewAPI {
if ($function['function'] == 'result') { if ($function['function'] == 'result') {
if (! is_null($result_function)) { if (! is_null($result_function)) {
// Another 'result' function found // Another 'result' function found
throw new MibewAPIException( throw new APIException(
"Function 'result' already exists in request", "Function 'result' already exists in request",
MibewAPIException::RESULT_FUNCTION_ALREADY_EXISTS APIException::RESULT_FUNCTION_ALREADY_EXISTS
); );
} }
// First 'result' function found // First 'result' function found
@ -307,118 +309,20 @@ Class MibewAPI {
} }
if ($existence === true && is_null($result_function)) { if ($existence === true && is_null($result_function)) {
// 'result' function must present in request // 'result' function must present in request
throw new MibewAPIException( throw new APIException(
"There is no 'result' function in request", "There is no 'result' function in request",
MibewAPIException::NO_RESULT_FUNCTION APIException::NO_RESULT_FUNCTION
); );
} }
if ($existence === false && !is_null($result_function)) { if ($existence === false && !is_null($result_function)) {
// 'result' function must not present in request // 'result' function must not present in request
throw new MibewAPIException( throw new APIException(
"There is 'result' function in request", "There is 'result' function in request",
MibewAPIException::RESULT_FUNCTION_EXISTS APIException::RESULT_FUNCTION_EXISTS
); );
} }
return $result_function; 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;
}
?> ?>

View 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;
}
?>

View File

@ -15,10 +15,12 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\API;
/** /**
* Implements functions execution context * Implements functions execution context
*/ */
Class MibewAPIExecutionContext { class ExecutionContext {
/** /**
* Values which returns after execution of all functions in request * Values which returns after execution of all functions in request
* @var array * @var array
@ -35,7 +37,7 @@ Class MibewAPIExecutionContext {
* Returns requets results * Returns requets results
* *
* @return array Request results * @return array Request results
* @see MibewAPIExecutionContext::$return * @see \Mibew\API\ExecutionContext::$return
*/ */
public function getResults () { public function getResults () {
return $this->return; return $this->return;
@ -46,7 +48,7 @@ Class MibewAPIExecutionContext {
* *
* @param array $function Function array. See MibewAPI for details. * @param array $function Function array. See MibewAPI for details.
* @return array Arguments list * @return array Arguments list
* @throws MibewAPIException * @throws \Mibew\API\APIException
*/ */
public function getArgumentsList ($function) { public function getArgumentsList ($function) {
$arguments = $function['arguments']; $arguments = $function['arguments'];
@ -55,20 +57,20 @@ Class MibewAPIExecutionContext {
// Check target function in context // Check target function in context
if (! isset($this->functions_results[$func_num - 1])) { if (! isset($this->functions_results[$func_num - 1])) {
// Wrong function num // Wrong function num
throw new MibewAPIException( throw new APIException(
"Wrong reference in '{$function['function']}' function. " . "Wrong reference in '{$function['function']}' function. " .
"Function #{$func_num} does not call yet.", "Function #{$func_num} does not call yet.",
MibewAPIException::WRONG_FUNCTION_NUM_IN_REFERENCE APIException::WRONG_FUNCTION_NUM_IN_REFERENCE
); );
} }
// Check reference // Check reference
if (empty($arguments[$variable])) { if (empty($arguments[$variable])) {
// Empty argument that should contains reference // Empty argument that should contains reference
throw new MibewAPIException( throw new APIException(
"Wrong reference in '{$function['function']}' function. " . "Wrong reference in '{$function['function']}' function. " .
"Empty {$variable} argument.", "Empty {$variable} argument.",
MibewAPIException::EMPTY_VARIABLE_IN_REFERENCE APIException::EMPTY_VARIABLE_IN_REFERENCE
); );
} }
$reference_to = $arguments[$variable]; $reference_to = $arguments[$variable];
@ -76,11 +78,11 @@ Class MibewAPIExecutionContext {
// Check target value // Check target value
if (! isset($this->functions_results[$func_num - 1][$reference_to])) { if (! isset($this->functions_results[$func_num - 1][$reference_to])) {
// Undefined target value // Undefined target value
throw new MibewAPIException( throw new APIException(
"Wrong reference in '{$function['function']}' function. " . "Wrong reference in '{$function['function']}' function. " .
"There is no '{$reference_to}' argument in #{$func_num} " . "There is no '{$reference_to}' argument in #{$func_num} " .
"function results", "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 $function Function array. See MibewAPI for details.
* @param array $results Associative array of the function results. * @param array $results Associative array of the function results.
* @throws MibewAPIException * @throws \Mibew\API\APIException
*/ */
public function storeFunctionResults ($function, $results) { public function storeFunctionResults ($function, $results) {
// Check if function return correct results // Check if function return correct results
@ -104,10 +106,10 @@ Class MibewAPIExecutionContext {
foreach ($function['arguments']['return'] as $name => $alias) { foreach ($function['arguments']['return'] as $name => $alias) {
if (! isset($results[$name])) { if (! isset($results[$name])) {
// Value that defined in 'return' argument is undefined // Value that defined in 'return' argument is undefined
throw new MibewAPIException( throw new APIException(
"Variable with name '{$name}' is undefined in the " . "Variable with name '{$name}' is undefined in the " .
"results of the '{$function['function']}' function", "results of the '{$function['function']}' function",
MibewAPIException::VARIABLE_IS_UNDEFINED_IN_RESULT APIException::VARIABLE_IS_UNDEFINED_IN_RESULT
); );
} }
$this->return[$alias] = $results[$name]; $this->return[$alias] = $results[$name];

View File

@ -15,14 +15,16 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\API\Interaction;
/** /**
* Implements Mibew Core - Mibew Chat Window interaction * Implements Mibew Core - Mibew Chat Window interaction
*/ */
class MibewAPIChatInteraction extends MibewAPIInteraction { class ChatInteraction extends Interaction {
/** /**
* Defines obligatory arguments and default values for them * Defines obligatory arguments and default values for them
* @var array * @var array
* @see MibewAPIInteraction::$obligatoryArgumnents * @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
*/ */
protected $obligatoryArguments = array( protected $obligatoryArguments = array(
'*' => array( '*' => array(
@ -39,7 +41,7 @@ class MibewAPIChatInteraction extends MibewAPIInteraction {
/** /**
* Reserved function's names * Reserved function's names
* @var array * @var array
* @see MibewAPIInteraction::$reservedFunctionNames * @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
*/ */
public $reservedFunctionNames = array( public $reservedFunctionNames = array(
'result' 'result'

View File

@ -15,10 +15,12 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\API\Interaction;
/** /**
* Encapsulates interaction type * Encapsulates interaction type
*/ */
abstract class MibewAPIInteraction { abstract class Interaction {
/** /**
* Defines obligatory arguments and default values for them * Defines obligatory arguments and default values for them
* *

View File

@ -15,14 +15,16 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\API\Interaction;
/** /**
* Implements Mibew Core - Mibew invitation waiting window 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 * Defines obligatory arguments and default values for them
* @var array * @var array
* @see MibewAPIInteraction::$obligatoryArgumnents * @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
*/ */
protected $obligatoryArguments = array( protected $obligatoryArguments = array(
'*' => array( '*' => array(
@ -38,7 +40,7 @@ class MibewAPIInviteInteraction extends MibewAPIInteraction {
/** /**
* Reserved function's names * Reserved function's names
* @var array * @var array
* @see MibewAPIInteraction::$reservedFunctionNames * @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
*/ */
public $reservedFunctionNames = array( public $reservedFunctionNames = array(
'result' 'result'

View File

@ -15,14 +15,16 @@
* limitations under the License. * limitations under the License.
*/ */
namespace Mibew\API\Interaction;
/** /**
* Implements Mibew Core - Mibew Users list interaction * Implements Mibew Core - Mibew Users list interaction
*/ */
class MibewAPIUsersInteraction extends MibewAPIInteraction { class UsersInteraction extends Interaction {
/** /**
* Defines obligatory arguments and default values for them * Defines obligatory arguments and default values for them
* @var array * @var array
* @see MibewAPIInteraction::$obligatoryArgumnents * @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
*/ */
protected $obligatoryArguments = array( protected $obligatoryArguments = array(
'*' => array( '*' => array(
@ -41,7 +43,7 @@ class MibewAPIUsersInteraction extends MibewAPIInteraction {
/** /**
* Reserved function's names * Reserved function's names
* @var array * @var array
* @see MibewAPIInteraction::$reservedFunctionNames * @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
*/ */
public $reservedFunctionNames = array( public $reservedFunctionNames = array(
'result' 'result'

View File

@ -18,7 +18,7 @@
namespace Mibew\RequestProcessor; namespace Mibew\RequestProcessor;
// Import namespaces and classes of the core // Import namespaces and classes of the core
use \MibewAPI; use Mibew\API\API as MibewAPI;
use Mibew\RequestProcessor\Exception\InviteProcessorException; 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() { protected function getMibewAPIInstance() {
return MibewAPI::getAPI('MibewAPIInviteInteraction'); return MibewAPI::getAPI('\\Mibew\\API\\Interaction\\InviteInteraction');
} }
/** /**

View File

@ -18,7 +18,6 @@
namespace Mibew\RequestProcessor; namespace Mibew\RequestProcessor;
// Import namespaces and classes of the core // Import namespaces and classes of the core
use \MibewAPIExecutionContext;
use Mibew\Database; use Mibew\Database;
use Mibew\EventDispatcher; use Mibew\EventDispatcher;
use Mibew\RequestProcessor\Exception\RequestProcessorException; use Mibew\RequestProcessor\Exception\RequestProcessorException;
@ -97,7 +96,7 @@ abstract class Processor {
/** /**
* Instance of the MibewAPI class * Instance of the MibewAPI class
* @var \MibewAPI * @var \Mibew\API\API
*/ */
protected $mibewAPI = null; protected $mibewAPI = null;
@ -333,7 +332,7 @@ abstract class Processor {
* @return array Array of requests results. * @return array Array of requests results.
*/ */
protected function processRequest($request, $result_function = null) { protected function processRequest($request, $result_function = null) {
$context = new MibewAPIExecutionContext(); $context = new \Mibew\API\ExecutionContext();
// Get result functions // Get result functions
$result_function = $this->mibewAPI->getResultFunction( $result_function = $this->mibewAPI->getResultFunction(
@ -368,10 +367,10 @@ abstract class Processor {
* Process function * Process function
* *
* @param array $function 'Function' array. See Mibew API for details * @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. * @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 // Get function arguments with replaced references
$arguments = $context->getArgumentsList($function); $arguments = $context->getArgumentsList($function);
@ -523,9 +522,9 @@ abstract class Processor {
protected function checkFunction($function) {} 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(); protected abstract function getMibewAPIInstance();
} }

View File

@ -18,9 +18,9 @@
namespace Mibew\RequestProcessor; namespace Mibew\RequestProcessor;
// Import namespaces and classes of the core // Import namespaces and classes of the core
use \MibewAPI;
use Mibew\Settings; use Mibew\Settings;
use Mibew\Thread; use Mibew\Thread;
use Mibew\API\API as MibewAPI;
use Mibew\RequestProcessor\Exception\ThreadProcessorException; 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() { protected function getMibewAPIInstance() {
return MibewAPI::getAPI('MibewAPIChatInteraction'); return MibewAPI::getAPI('\\Mibew\\API\\Interaction\\ChatInteraction');
} }
/** /**

View File

@ -18,11 +18,11 @@
namespace Mibew\RequestProcessor; namespace Mibew\RequestProcessor;
// Import namespaces and classes of the core // Import namespaces and classes of the core
use \MibewAPI;
use Mibew\Database; use Mibew\Database;
use Mibew\EventDispatcher; use Mibew\EventDispatcher;
use Mibew\Settings; use Mibew\Settings;
use Mibew\Thread; use Mibew\Thread;
use Mibew\API\API as MibewAPI;
use Mibew\RequestProcessor\Exception\UsersProcessorException; 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() { protected function getMibewAPIInstance() {
return MibewAPI::getAPI('MibewAPIUsersInteraction'); return MibewAPI::getAPI('\\Mibew\\API\\Interaction\\UsersInteraction');
} }
/** /**

View File

@ -18,10 +18,6 @@
require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(dirname(dirname(__FILE__)).'/libs/init.php');
require_once(MIBEW_FS_ROOT.'/libs/invitation.php'); require_once(MIBEW_FS_ROOT.'/libs/invitation.php');
require_once(MIBEW_FS_ROOT.'/libs/operator.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 = \Mibew\RequestProcessor\InviteProcessor::getInstance();
$processor->receiveRequest($_POST['data']); $processor->receiveRequest($_POST['data']);

View File

@ -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/groups.php');
require_once(MIBEW_FS_ROOT.'/libs/invitation.php'); require_once(MIBEW_FS_ROOT.'/libs/invitation.php');
require_once(MIBEW_FS_ROOT.'/libs/track.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 = \Mibew\RequestProcessor\UsersProcessor::getInstance();
$processor->receiveRequest($_POST['data']); $processor->receiveRequest($_POST['data']);

View File

@ -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/groups.php');
require_once(MIBEW_FS_ROOT.'/libs/captcha.php'); require_once(MIBEW_FS_ROOT.'/libs/captcha.php');
require_once(MIBEW_FS_ROOT.'/libs/notify.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 = \Mibew\RequestProcessor\ThreadProcessor::getInstance();
$processor->receiveRequest($_POST['data']); $processor->receiveRequest($_POST['data']);