Queue.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_Queue
  17. * @subpackage UnitTests
  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. * The adapter test class provides a universal test class for all of the
  24. * abstract methods.
  25. *
  26. * All methods marked not supported are explictly checked for for throwing
  27. * an exception.
  28. */
  29. /** Zend_Queue */
  30. require_once 'Zend/Queue.php';
  31. /** Zend_Queue */
  32. require_once 'Zend/Queue/Message.php';
  33. /**
  34. * @category Zend
  35. * @package Zend_Queue
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Custom_Queue extends Zend_Queue
  41. {
  42. /**
  43. * Constructor
  44. *
  45. * Can be called as
  46. * $queue = new Zend_Queue($config);
  47. * - or -
  48. * $queue = new Zend_Queue('array', $config);
  49. * - or -
  50. * $queue = new Zend_Queue(null, $config); // Zend_Queue->createQueue();
  51. *
  52. * @param Zend_Queue_Adapter_Abstract|string $adapter adapter object or class name
  53. * @param Zend_Config|array $config Zend_Config or an configuration array
  54. */
  55. public function __construct()
  56. {
  57. $args = func_get_args();
  58. call_user_func_array(array($this, 'parent::__construct'), $args);
  59. $this->setMessageClass('Custom_Message');
  60. $this->setMessageSetClass('Custom_Messages');
  61. }
  62. /**
  63. * Send a message to the queue
  64. *
  65. * @param Custom_Message|Custom_Messages $message message
  66. * @return $this
  67. * @throws Zend_Queue_Exception
  68. */
  69. public function send($message)
  70. {
  71. if (! ($message instanceof Custom_Message || $message instanceof Custom_Messages) ) {
  72. /**
  73. * @see Zend_Queue_Exception
  74. */
  75. require_once 'Zend/Queue/Exception.php';
  76. throw new Zend_Queue_Exception('$message must be an instance of Custom_Message or Custom_Messages');
  77. }
  78. if ($message instanceof Custom_Message) {
  79. $response = parent::send($message->__toString());
  80. } else {
  81. foreach($message as $i => $one) {
  82. $response = parent::send($one->__toString());
  83. }
  84. }
  85. return $this;
  86. }
  87. }