Source for file Response.php
Documentation is available at Response.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* Services_Yahoo Content Analysis Response
* Copyright 2005-2006 Martin Jansen
* 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.
* @package Services_Yahoo
* @author Martin Jansen <mj@php.net>
* @copyright 2005-2006 Martin Jansen
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @version CVS: $Id: Response.php,v 1.2 2006/10/02 12:53:33 mj Exp $
* @link http://pear.php.net/package/Services_Yahoo
* Services_Yahoo Content Analysis Response class
* This class provides methods for accessing the response of a content
* @package Services_Yahoo
* @author Martin Jansen <mj@php.net>
* @copyright 2005-2006 Martin Jansen
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @version CVS: $Id: Response.php,v 1.2 2006/10/02 12:53:33 mj Exp $
private $isValidIterator = true;
private $iteratorCounter = 0;
private $results = array ();
* @param object HTTP_Request Instance of HTTP_Request that was used for the request
* @throws Services_Yahoo_Exception
$this->request = $request;
if ($this->isError () == true ) {
$exception->addErrors ($this->getMessages ());
* Get number of result sets returned by the content analysis
* @return integer Number of result sets returned
return count((array) $this->xml->Result );
* Get the HTTP_Request instance that was used for the query
* Access to the HTTP_Request instance is useful for introspecting
* into the request details. (E.g. for getting the HTTP response
* @return object HTTP_Request Instance of HTTP_Request
// {{{ Iterator implementation
return (string) $this->xml->Result [$this->iteratorCounter];
$this->iteratorCounter++;
if (!isset ($this->xml->Result [$this->iteratorCounter])) {
$this->isValidIterator = false;
return $this->iteratorCounter;
$this->iteratorCounter = 0;
return $this->isValidIterator;
* Parse XML from the response
* @throws Services_Yahoo_Exception
private function parseRequest ()
if ($this->xml === false ) {
* Determine if an error was returned by the Yahoo API
* This method evaluates the HTTP response code. If it indicates
* an error, the method returns true.
* @return boolean True on error, otherwise false.
private function isError ()
return in_array($this->request->getResponseCode (), array (400 , 403 , 404 , 503 ));
* Get all error messages if the response contained an error
* Returns all errors in an numerically indexed array that were
private function getMessages ()
foreach ($this->xml->Message as $message) {
$returnValue[] = $message;
Documentation generated on Fri, 20 Apr 2007 14:30:07 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|