HigherOrderBuilderProxy.php 1015 B

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 Builder $builder
  24. * @param string $method
  25. */
  26. public function __construct(Builder $builder, $method)
  27. {
  28. $this->method = $method;
  29. $this->builder = $builder;
  30. }
  31. /**
  32. * Proxy a scope call onto the query builder.
  33. *
  34. * @param string $method
  35. * @param array $parameters
  36. * @return mixed
  37. */
  38. public function __call($method, $parameters)
  39. {
  40. return $this->builder->{$this->method}(function ($value) use ($method, $parameters) {
  41. return $value->{$method}(...$parameters);
  42. });
  43. }
  44. }