SheetWith100Rows.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Data\Stubs;
  3. use Illuminate\Support\Collection;
  4. use Maatwebsite\Excel\Concerns\Exportable;
  5. use Maatwebsite\Excel\Concerns\FromCollection;
  6. use Maatwebsite\Excel\Concerns\RegistersEventListeners;
  7. use Maatwebsite\Excel\Concerns\ShouldAutoSize;
  8. use Maatwebsite\Excel\Concerns\WithEvents;
  9. use Maatwebsite\Excel\Concerns\WithTitle;
  10. use Maatwebsite\Excel\Events\BeforeWriting;
  11. use Maatwebsite\Excel\Tests\TestCase;
  12. use Maatwebsite\Excel\Writer;
  13. class SheetWith100Rows implements FromCollection, WithTitle, ShouldAutoSize, WithEvents
  14. {
  15. use Exportable, RegistersEventListeners;
  16. /**
  17. * @var string
  18. */
  19. private $title;
  20. /**
  21. * @param string $title
  22. */
  23. public function __construct(string $title)
  24. {
  25. $this->title = $title;
  26. }
  27. /**
  28. * @return Collection
  29. */
  30. public function collection()
  31. {
  32. $collection = new Collection;
  33. for ($i = 0; $i < 100; $i++) {
  34. $row = new Collection();
  35. for ($j = 0; $j < 5; $j++) {
  36. $row[] = $this->title() . '-' . $i . '-' . $j;
  37. }
  38. $collection->push($row);
  39. }
  40. return $collection;
  41. }
  42. /**
  43. * @return string
  44. */
  45. public function title(): string
  46. {
  47. return $this->title;
  48. }
  49. /**
  50. * @param BeforeWriting $event
  51. */
  52. public static function beforeWriting(BeforeWriting $event)
  53. {
  54. TestCase::assertInstanceOf(Writer::class, $event->writer);
  55. }
  56. }