Query.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service
  17. * @subpackage Amazon
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Service_Amazon
  24. */
  25. require_once 'Zend/Service/Amazon.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Service
  29. * @subpackage Amazon
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Service_Amazon_Query extends Zend_Service_Amazon
  34. {
  35. /**
  36. * Search parameters
  37. *
  38. * @var array
  39. */
  40. protected $_search = array();
  41. /**
  42. * Search index
  43. *
  44. * @var string
  45. */
  46. protected $_searchIndex = null;
  47. /**
  48. * Prepares query parameters
  49. *
  50. * @param string $method
  51. * @param array $args
  52. * @throws Zend_Service_Exception
  53. * @return Zend_Service_Amazon_Query Provides a fluent interface
  54. */
  55. public function __call($method, $args)
  56. {
  57. if (strtolower($method) === 'asin') {
  58. $this->_searchIndex = 'asin';
  59. $this->_search['ItemId'] = $args[0];
  60. return $this;
  61. }
  62. if (strtolower($method) === 'category') {
  63. $this->_searchIndex = $args[0];
  64. $this->_search['SearchIndex'] = $args[0];
  65. } else if (isset($this->_search['SearchIndex']) || $this->_searchIndex !== null || $this->_searchIndex === 'asin') {
  66. $this->_search[$method] = $args[0];
  67. } else {
  68. /**
  69. * @see Zend_Service_Exception
  70. */
  71. require_once 'Zend/Service/Exception.php';
  72. throw new Zend_Service_Exception('You must set a category before setting the search parameters');
  73. }
  74. return $this;
  75. }
  76. /**
  77. * Search using the prepared query
  78. *
  79. * @return Zend_Service_Amazon_Item|Zend_Service_Amazon_ResultSet
  80. */
  81. public function search()
  82. {
  83. if ($this->_searchIndex === 'asin') {
  84. return $this->itemLookup($this->_search['ItemId'], $this->_search);
  85. }
  86. return $this->itemSearch($this->_search);
  87. }
  88. }