File indexing completed on 2024-06-16 05:30:24

0001 <?php
0002 
0003 /**
0004  * Zend Framework
0005  *
0006  * LICENSE
0007  *
0008  * This source file is subject to the new BSD license that is bundled
0009  * with this package in the file LICENSE.txt.
0010  * It is also available through the world-wide-web at this URL:
0011  * http://framework.zend.com/license/new-bsd
0012  * If you did not receive a copy of the license and are unable to
0013  * obtain it through the world-wide-web, please send an email
0014  * to license@zend.com so we can send you a copy immediately.
0015  *
0016  * @category   Zend
0017  * @package    Zend_Service
0018  * @subpackage Amazon
0019  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0020  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0021  * @version    $Id$
0022  */
0023 
0024 
0025 /**
0026  * @see Zend_Service_Amazon
0027  */
0028 // require_once 'Zend/Service/Amazon.php';
0029 
0030 
0031 /**
0032  * @category   Zend
0033  * @package    Zend_Service
0034  * @subpackage Amazon
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  */
0038 class Zend_Service_Amazon_Query extends Zend_Service_Amazon
0039 {
0040     /**
0041      * Search parameters
0042      *
0043      * @var array
0044      */
0045     protected $_search = array();
0046 
0047     /**
0048      * Search index
0049      *
0050      * @var string
0051      */
0052     protected $_searchIndex = null;
0053 
0054     /**
0055      * Prepares query parameters
0056      *
0057      * @param  string $method
0058      * @param  array  $args
0059      * @throws Zend_Service_Exception
0060      * @return Zend_Service_Amazon_Query Provides a fluent interface
0061      */
0062     public function __call($method, $args)
0063     {
0064         if (strtolower($method) === 'asin') {
0065             $this->_searchIndex = 'asin';
0066             $this->_search['ItemId'] = $args[0];
0067             return $this;
0068         }
0069 
0070         if (strtolower($method) === 'category') {
0071             $this->_searchIndex = $args[0];
0072             $this->_search['SearchIndex'] = $args[0];
0073         } else if (isset($this->_search['SearchIndex']) || $this->_searchIndex !== null || $this->_searchIndex === 'asin') {
0074             $this->_search[$method] = $args[0];
0075         } else {
0076             /**
0077              * @see Zend_Service_Exception
0078              */
0079             // require_once 'Zend/Service/Exception.php';
0080             throw new Zend_Service_Exception('You must set a category before setting the search parameters');
0081         }
0082 
0083         return $this;
0084     }
0085 
0086     /**
0087      * Search using the prepared query
0088      *
0089      * @return Zend_Service_Amazon_Item|Zend_Service_Amazon_ResultSet
0090      */
0091     public function search()
0092     {
0093         if ($this->_searchIndex === 'asin') {
0094             return $this->itemLookup($this->_search['ItemId'], $this->_search);
0095         }
0096         return $this->itemSearch($this->_search);
0097     }
0098 }