QueuedExportWithLocalePreferences.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Data\Stubs;
  3. use Illuminate\Contracts\Translation\HasLocalePreference;
  4. use Illuminate\Support\Collection;
  5. use Maatwebsite\Excel\Concerns\Exportable;
  6. use Maatwebsite\Excel\Concerns\FromCollection;
  7. use Maatwebsite\Excel\Tests\Data\Stubs\Database\User;
  8. use PHPUnit\Framework\Assert;
  9. class QueuedExportWithLocalePreferences implements FromCollection, HasLocalePreference
  10. {
  11. use Exportable;
  12. /**
  13. * @var string
  14. */
  15. protected $locale;
  16. /**
  17. * QueuedExportWithLocalePreferences constructor.
  18. *
  19. * @param string $locale
  20. */
  21. public function __construct(string $locale)
  22. {
  23. $this->locale = $locale;
  24. }
  25. /**
  26. * @return Collection
  27. */
  28. public function collection()
  29. {
  30. return collect([
  31. new User([
  32. 'firstname' => 'Patrick',
  33. 'lastname' => 'Brouwers',
  34. ]),
  35. ]);
  36. }
  37. /**
  38. * @return string|null
  39. */
  40. public function preferredLocale()
  41. {
  42. return $this->locale;
  43. }
  44. /**
  45. * @param iterable $rows
  46. * @return iterable
  47. */
  48. public function prepareRows($rows)
  49. {
  50. Assert::assertEquals('ru', app()->getLocale());
  51. app()->bind('queue-has-correct-locale', function () {
  52. return true;
  53. });
  54. return $rows;
  55. }
  56. }