BaseForm.php 913 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace backend\forms;
  3. use Yii;
  4. use yii\base\Model;
  5. use components\Exception;
  6. /**
  7. * Class BaseForm
  8. * @package backend\forms
  9. */
  10. class BaseForm extends Model
  11. {
  12. public function handleError()
  13. {
  14. $errors = $this->getFirstErrors();
  15. $result = reset($errors);
  16. if (is_numeric($result)) {
  17. throw new Exception($result, \Yii::t('error', $result));
  18. } else {
  19. throw new Exception(1003, $result);
  20. }
  21. }
  22. /**
  23. * getConnect
  24. * @author: libingke
  25. * @return \PhpAmqpLib\Connection\AMQPStreamConnection
  26. * @throws Exception
  27. */
  28. public function getConnect()
  29. {
  30. try {
  31. return new \PhpAmqpLib\Connection\AMQPStreamConnection(
  32. Yii::$app->Amqp->host,
  33. Yii::$app->Amqp->port,
  34. Yii::$app->Amqp->user,
  35. Yii::$app->Amqp->pass,
  36. Yii::$app->Amqp->vhost
  37. );
  38. } catch (\Exception $e) {
  39. throw new Exception(1001, $e->getMessage());
  40. }
  41. }
  42. }