Queue.php 3.0 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_Queue
  17. * @subpackage Custom
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: AllTests.php 13626 2009-01-14 18:24:57Z matthew $
  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 Custom
  37. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. * @version $Id: AllTests.php 13626 2009-01-14 18:24:57Z matthew $
  40. */
  41. class Custom_Queue extends Zend_Queue
  42. {
  43. /**
  44. * Constructor
  45. *
  46. * Can be called as
  47. * $queue = new Zend_Queue($config);
  48. * - or -
  49. * $queue = new Zend_Queue('array', $config);
  50. * - or -
  51. * $queue = new Zend_Queue(null, $config); // Zend_Queue->createQueue();
  52. *
  53. * @param Zend_Queue_Adapter_Abstract|string $adapter adapter object or class name
  54. * @param Zend_Config|array $config Zend_Config or an configuration array
  55. */
  56. public function __construct()
  57. {
  58. $args = func_get_args();
  59. call_user_func_array(array($this, 'parent::__construct'), $args);
  60. $this->setMessageClass('Custom_Message');
  61. $this->setMessageSetClass('Custom_Messages');
  62. $this->getLogger()->debug('Succcessfully created class: ' . get_class($this));
  63. }
  64. /**
  65. * Send a message to the queue
  66. *
  67. * @param Custom_Message|Custom_Messages $message message
  68. * @return $this
  69. * @throws Zend_Queue_Exception
  70. */
  71. public function send($message)
  72. {
  73. if (! ($message instanceof Custom_Message || $message instanceof Custom_Messages) ) {
  74. /**
  75. * @see Zend_Queue_Exception
  76. */
  77. require_once 'Zend/Queue/Exception.php';
  78. throw new Zend_Queue_Exception('$message must be an instance of Custom_Message or Custom_Messages');
  79. }
  80. if ($message instanceof Custom_Message) {
  81. $response = parent::send($message->__toString());
  82. } else {
  83. foreach($message as $i => $one) {
  84. $response = parent::send($one->__toString());
  85. }
  86. }
  87. return $this;
  88. }
  89. }