Clause.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /*
  8. * This file is part of the overtrue/wechat.
  9. *
  10. * (c) overtrue <i@overtrue.me>
  11. *
  12. * This source file is subject to the MIT license that is bundled
  13. * with this source code in the file LICENSE.
  14. */
  15. namespace ByteDance\Kernel\Clauses;
  16. /**
  17. * Class Clause.
  18. *
  19. * @author mingyoung <mingyoungcheung@gmail.com>
  20. */
  21. class Clause
  22. {
  23. /**
  24. * @var array
  25. */
  26. protected $clauses = [
  27. 'where' => [],
  28. ];
  29. /**
  30. * @param mixed ...$args
  31. *
  32. * @return $this
  33. */
  34. public function where(...$args)
  35. {
  36. array_push($this->clauses['where'], $args);
  37. return $this;
  38. }
  39. /**
  40. * @param mixed $payload
  41. *
  42. * @return bool
  43. */
  44. public function intercepted($payload)
  45. {
  46. return (bool) $this->interceptWhereClause($payload);
  47. }
  48. /**
  49. * @param mixed $payload
  50. *
  51. * @return bool
  52. */
  53. protected function interceptWhereClause($payload)
  54. {
  55. foreach ($this->clauses['where'] as $item) {
  56. list($key, $value) = $item;
  57. if (isset($payload[$key]) && $payload[$key] !== $value) {
  58. return true;
  59. }
  60. }
  61. }
  62. }