Exemple #1
0
	/**
	 * The constructor. Setup and handle the XML request.
	 */
	public function __construct($request)
	{
		if(!$request) {
			$this->BadRequest('A valid XML request to the API was not supplied.');
			return;
		}

		// Store the request XML locally
		$this->requestXML = $request;

		// Attempt to parse the XML
		try {
			if (!Interspire_Xml::validateXMLString($request, $xmlErrors)) {
				throw new Exception();
			}

			$this->request = new SimpleXMLElement($request);
		}
		catch(Exception $e) {
			$this->BadRequest('The XML supplied was not valid.');
			return;
		}

		$requiredNodes = array(
			'username',
			'usertoken',
			'requesttype',
			'requestmethod',
		);
		foreach($requiredNodes as $node) {
			if(empty($this->request->$node)) {
				$this->BadRequest('The supplied XML does not contain the '.$node.' node. This is a required field.');
				return;
			}
		}

		if(!$this->AuthenticateUser($this->request->username, $this->request->usertoken)) {
			$this->BadRequest('The supplied username and usertoken were unable to be verified. Please ensure that the details are valid and the user has API access.');
		}

		if(!$this->RouteRequest($this->request->requesttype, $this->request->requestmethod)) {
			$this->BadRequest('The supplied requesttype or requestmethod are invalid. Please check that you are calling a valid API method and try again.');
		}
	}