WebFioriAPI ReferenceLearnDownloadContributeLearn{{result.parent_page}} > {{result.title}}{{result.title}}Classes{{result.class_name}}{{result.summary}}Methods{{result.name}}{{result.summary}}

namespace \webfiori\http

class WebServicesManager

WebServicesManager::process() must be called.'">

Class Attributes Summary

const IA constant which is used to indicate that the message that will be sent is of type error .const POST_CONTENT_TYPESAn array that contains the supported 'POST' request content types.

Class Methods Summary

public function __construct(string$version)Creates new instance of the class.public function addService(AbstractWebService$service)Adds new web service to the set of web services.public function contentTypeNotSupported(string$cType)Sends a response message to indicate that request content type is not supported by the API.public function databaseErr(JsonI|Json|string$info)Sends a response message to indicate that a database error has occur.public function getCalledServiceName()Returns the name of the service which is being called.public function getDescription()Returns the description of web services set.public function getInputs()Returns an associative array or an object of type Json of filtered request inputs.public function getInvalidParameters()Returns an array that contains the names of request parameters which have invalid values.public function getMissingParameters()Returns an array that contains the names of missing required parameters.public function getNonFiltered()Returns an associative array of non-filtered request inputs.public function getOutputStream()Returns the stream at which the output will be sent to.public function getOutputStreamPath()Returns a string that represents the path of the custom output stream.public function getServiceByName(string$serviceName)Returns a web service given its name.public function invParams()Sends a response message to indicate that a request parameter(s) have invalid values.public function missingParams()Sends a response message to indicate that a request parameter or parameters are missing.public function missingServiceName()Sends a response message to tell the front-end that the parameter 'action', 'service' or 'service-name' is missing from request body.public function notAuth()Sends a response message to indicate that a user is not authorized call a service or a resource.public function readOutputStream()Reads the content of output stream.public function removeService(string$name)Removes a service from the manager given its name.public function removeServices()Removes all added web services.public function requestMethodNotAllowed()Sends a response message to indicate that request method is not supported.public function send(string$conentType, mixed$data, int$code)Sends Back a data using specific content type and specific response code.public function sendHeaders(array$headersArr)Sends back multiple HTTP headers to the client.public function sendResponse(string$message, string$type, int$code, mixed$otherInfo)Sends a JSON response to the client.public function serviceNotImplemented()Sends a response message to indicate that web service is not implemented.public function serviceNotSupported()Sends a response message to indicate that called web service is not supported by the API.public function setDescription(sting$desc)Sets the description of the web services set.public function setInputStream(string|resource$pathOrResource)Sets the stream at which the manager will read the inputs from.public function setOutputStream(resource|string$stream, boolean$new)Sets a custom output stream.public function toJSON()Returns Json object that represents services set.

Class Attributes Details

const IA constant which is used to indicate that the message that will be sent is of type error . / const E = 'error'; / A constant which is used to indicate that the message that will be sent is of type infoconst POST_CONTENT_TYPESAn array that contains the supported 'POST' request content types. This array has the following values:
  • application/x-www-form-urlencoded
  • multipart/form-data
  • application/json

Class Methods Details

public function __construct(string$version)
Creates new instance of the class. By default, the API will have two services added to it:
  • api-info
  • request-info
The first service is used to return a JSON string which contains all needed information by the front-end to implement the API. The user can supply an optional parameter with it which is called 'version' in order to get information about specific API version. The second service is used to get basic info about the request.

Parameters:

  • string $version initial API version. Default is '1.0.0' Version number must follow the format 'X.X.X' where 'X' is a number between 0 and 9 inclusive.
public function addService(AbstractWebService$service)Adds new web service to the set of web services.

Parameters:

public function contentTypeNotSupported(string$cType)
Sends a response message to indicate that request content type is not supported by the API. This method will send back a JSON string in the following format:

{
  "message":"Content type not supported.",
  "type":"error",
  "request-content-type":"content_type"
}

In addition to the message, The response will sent HTTP code 404 - Not Found.

Parameters:

  • string $cType The value of the header 'content-type' taken from request header.
public function databaseErr(JsonI|Json|string$info)
Sends a response message to indicate that a database error has occur. This method will send back a JSON string in the following format:

{
  "message":"Database Error",
  "type":"error",
  "err-info":OTHER_DATA
}

In here, 'OTHER_DATA' can be a basic string or JSON string. Also, The response will sent HTTP code 404 - Not Found.

Parameters:

  • JsonI|Json|string $info An object of type JsonI or Json that describe the error in more details. Also it can be a simple string or JSON string.
public function getCalledServiceName()Returns the name of the service which is being called. The name of the service must be passed in the body of the request for POST and PUT request methods (e.g. 'action=do-something' or 'service-name=do-something'). In case of GET and DELETE, it must be passed as query string.Returns: type public function getDescription()Returns the description of web services set. Returns: string|nullThe description of web services set. The description is useful to describe what does the set of services can do. If the description is not set, the method will return null.public function getInputs()Returns an associative array or an object of type Json of filtered request inputs. The indices of the array will represent request parameters and the values of each index will represent the value which was set in request body. The values will be filtered and might not be exactly the same as the values passed in request body. Note that if a parameter is optional and not provided in request body, its value will be set to 'null'. Note that if request content type is 'application/json', only basic filtering will be applied. Also, parameters in this case don't apply.sReturns: array|JsonAn array of filtered request inputs. This also can be an object of type 'Json' if request content type was 'application/json'.public function getInvalidParameters()Returns an array that contains the names of request parameters which have invalid values. Returns: arrayAn array that contains the names of request parameters which have invalid values.public function getMissingParameters()Returns an array that contains the names of missing required parameters. If a parameter is optional and not provided, it will not appear in the returned array.Returns: arrayAn array that contains the names of missing required parameters.public function getNonFiltered()Returns an associative array of non-filtered request inputs. The indices of the array will represent request parameters and the values of each index will represent the value which was set in request body. The values will be exactly the same as the values passed in request body. Note that if a parameter is optional and not provided in request body, its value will be set to 'null'.Returns: arrayAn array of request parameters.public function getOutputStream()Returns the stream at which the output will be sent to. Returns: resource|nullIf a custom output stream is set using the method 'WebServicesManager::setOutputStream()', the method will return a resource. The resource will be still open. If no custom stream is set, the method will return null.public function getOutputStreamPath()Returns a string that represents the path of the custom output stream. Returns: string|nullA string that represents the path of the custom output stream. If no custom output stream is set, the method will return null.public function getServiceByName(string$serviceName)Returns a web service given its name.

Parameters:

  • string $serviceName The name of the service.
Returns: AbstractWebService|nullThe method will return an object of type 'WebService' if the service is found. If no service was found which has the given name, The method will return null.
public function invParams()
Sends a response message to indicate that a request parameter(s) have invalid values. This method will send back a JSON string in the following format:

{
  "message":"The following parameter(s) has invalid values: 'param_1', 'param_2', 'param_n'",
  "type":"error"
}

In addition to the message, The response will sent HTTP code 404 - Not Found.
public function missingParams()
Sends a response message to indicate that a request parameter or parameters are missing. This method will send back a JSON string in the following format:

{
  "message":"The following required parameter(s) where missing from the request body: 'param_1', 'param_2', 'param_n'",
  "type":"error",
}

In addition to the message, The response will sent HTTP code 404 - Not Found.
public function missingServiceName()
Sends a response message to tell the front-end that the parameter 'action', 'service' or 'service-name' is missing from request body. This method will send back a JSON string in the following format:

{
  "message":"Service name is not set.",
  "type":"error"
}

In addition to the message, The response will sent HTTP code 404 - Not Found.
public function notAuth()
Sends a response message to indicate that a user is not authorized call a service or a resource. This method will send back a JSON string in the following format:

{
  "message":"Not authorized",
  "type":"error"
}

In addition to the message, The response will sent HTTP code 401 - Not Authorized.
public function readOutputStream()Reads the content of output stream. This method is used to read the content of the custom output stream. The method will only read it if it was set using its path.Returns: string|nullIf the content was taken from the stream, the method will return it as a string. Other than that, the method will return null.public function removeService(string$name)Removes a service from the manager given its name.

Parameters:

  • string $name The name of the service.
Returns: AbstractWebService|nullIf a web service which has the given name was found and removed, the method will return an object that represent the removed service. Other than that, the method will return null.
public function removeServices()Removes all added web services. This method will simply re-initialize the arrays that holds all web services.public function requestMethodNotAllowed()
Sends a response message to indicate that request method is not supported. This method will send back a JSON string in the following format:

{
  "message":"Method Not Allowed.",
  "type":"error",
}

In addition to the message, The response will sent HTTP code 405 - Method Not Allowed.
public function send(string$conentType, mixed$data, int$code)Sends Back a data using specific content type and specific response code.

Parameters:

  • string $conentType Response content type (such as 'application/json')
  • mixed $data Any data to send back. Mostly, it will be a string.
  • int $code HTTP response code that will be used to send the data. Default is HTTP code 200 - Ok.
public function sendHeaders(array$headersArr)Sends back multiple HTTP headers to the client.

Parameters:

  • array $headersArr An associative array. The keys will act as the headers names and the value of each key will represents the value of the header.
public function sendResponse(string$message, string$type, int$code, mixed$otherInfo)
Sends a JSON response to the client. The basic format of the message will be as follows:

{
  "message":"Action is not set.",
  "type":"error"
  "http-code":404
  "more-info":EXTRA_INFO
}

Where EXTRA_INFO can be a simple string or any JSON data.

Parameters:

  • string $message The message to send back.
  • string $type A string that tells the client what is the type of the message. The developer can specify his own message types such as 'debug', 'info' or any string. If it is empty string, it will be not included in response payload.
  • int $code Response code (such as 404 or 200). Default is 200.
  • mixed $otherInfo Any other data to send back it can be a simple string, an object... . If null is given, the parameter 'more-info' will be not included in response. Default is empty string. Default is null.
public function serviceNotImplemented()
Sends a response message to indicate that web service is not implemented. This method will send back a JSON string in the following format:

{
  "message":"Service not implemented.",
  "type":"error",
}

In addition to the message, The response will sent HTTP code 404 - Not Found.
public function serviceNotSupported()
Sends a response message to indicate that called web service is not supported by the API. This method will send back a JSON string in the following format:

{
  "message":"Action not supported",
  "type":"error"
}

In addition to the message, The response will sent HTTP code 404 - Not Found.
public function setDescription(sting$desc)Sets the description of the web services set.

Parameters:

  • sting $desc Set description. Used to help front-end to identify the use of the services set.
public function setInputStream(string|resource$pathOrResource)Sets the stream at which the manager will read the inputs from. This can be used to test the services if body content type is 'application/json'.

Parameters:

  • string|resource $pathOrResource A file that contains JSON or a stream which was opened using a function like 'fopen()'.
Returns: booleanIf input stream is successfully set, the method will return true. False otherwise.
public function setOutputStream(resource|string$stream, boolean$new)Sets a custom output stream. This method is useful if the developer would like to test the output of a web service. Simply set the output stream to a custom one and read the content of the stream. Note that if the resource already exist and has content, it will be erased.

Parameters:

  • resource|string $stream A resource which was opened by 'fopen()'. Also, it can be a string that points to a file.
  • boolean $new If set to true and the resource does not exist, the method will attempt to create it.
public function toJSON()Returns Json object that represents services set. Returns: JsonAn object of type Json.
mdi-menuAll Classesmdi-chevron-leftAnchorBrCodeSnippetHTMLDocHTMLListHTMLNodeHTMLTableHeadNodeInputJsCodeLabelListItemOrderedListParagraphRadioGroupTableCellTableRowUnorderedListInvalidNodeNameExceptionTemplateNotFoundExceptionCaseConverterJsonJsonConverterJsonIJsonTypesPropertyAPIFilterAbstractWebServiceManagerInfoServiceParamTypesRequestRequestParameterResponseUriWebServicesManagerAccessAutoLoaderConfigConfigControllerDBEAbstractWebServiceExtendedWebServicesManagerFileLoggerPrivilegePrivilegesGroupThemeThemeLoaderUploadFileUploaderUserUtilWebFioriAppLanguageErrorBoxHTTPCodeViewMessageBoxServerErrViewStarterPageWebPageDatabaseSessionStorageDefaultSessionStorageMSSQLSessionDataTableMSSQLSessionsTableMySQLSessionDataTableMySQLSessionsTableSessionSessionOperationsSessionStorageSessionsManagerRouterRouterUriAbstractMiddlewareMiddlewareManagerEmailMessageSMTPAccountSMTPServerClassLoaderExceptionFileExceptionInitializationExceptionInvalidCRONExprExceptionMissingLangExceptionNoSuchThemeExceptionRoutingExceptionSMTPExceptionSessionExceptionUIExceptionAbstractJobCronCronEmailCronJobJobArgumentCronLoginViewCronTasksViewCronViewCronLoginServiceCronLogoutServiceCronServicesManagerForceCronExecutionServiceGetJobsServiceCLICLICommandInputStreamOutputStreamStdInStdOutClassWriterLangClassWriterQueryClassWriterServiceHolderThemeClassWriterWebServiceWriterCreateCLIClassHelperCreateCronJobCreateMiddlewareCreateTableCreateTableObjCreateThemeHelperCreateWebServiceAddCommandCreateCommandCronCommandHelpCommandListCronCommandListRoutesCommandListThemesCommandRunSQLQueryCommandSettingsCommandTestRouteCommandUpdateSettingsCommandUpdateTableCommandVersionCommandAbstractQueryColumnColumnFactoryConditionConnectionConnectionInfoDatabaseDatabaseExceptionDateTimeValidatorEntityMapperExpressionForeignKeyJoinTableResultSetSelectExpressionTableWhereExpressionMySQLColumnMySQLConnectionMySQLQueryMySQLTableMSSQLColumnMSSQLConnectionMSSQLQueryMSSQLTableAbstractCollectionComparableLinkedListNodeQueueStack
Powered By: WebFiori Framework, Vue and VuetifyAll Rights Reserved © 2018 - 2024