HigherOrderBuilderProxy.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Illuminate\Database\Eloquent;
  3. /**
  4. * @mixin \Illuminate\Database\Eloquent\Builder
  5. */
  6. class HigherOrderBuilderProxy
  7. {
  8. /**
  9. * The collection being operated on.
  10. *
  11. * @var \Illuminate\Database\Eloquent\Builder
  12. */
  13. protected $builder;
  14. /**
  15. * The method being proxied.
  16. *
  17. * @var string
  18. */
  19. protected $method;
  20. /**
  21. * Create a new proxy instance.
  22. *
  23. * @param \Illuminate\Database\Eloquent\Builder $builder
  24. * @param string $method
  25. * @return void
  26. */
  27. public function __construct(Builder $builder, $method)
  28. {
  29. $this->method = $method;
  30. $this->builder = $builder;
  31. }
  32. /**
  33. * Proxy a scope call onto the query builder.
  34. *
  35. * @param string $method
  36. * @param array $parameters
  37. * @return mixed
  38. */
  39. public function __call($method, $parameters)
  40. {
  41. return $this->builder->{$this->method}(function ($value) use ($method, $parameters) {
  42. return $value->{$method}(...$parameters);
  43. });
  44. }
  45. }