Tools.php 1011 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Dcat\Admin\Tree;
  3. use Dcat\Admin\Support\Helper;
  4. use Dcat\Admin\Tree;
  5. use Illuminate\Contracts\Support\Htmlable;
  6. use Illuminate\Contracts\Support\Renderable;
  7. use Illuminate\Support\Collection;
  8. class Tools implements Renderable
  9. {
  10. /**
  11. * Parent tree.
  12. *
  13. * @var Tree
  14. */
  15. protected $tree;
  16. /**
  17. * Collection of tools.
  18. *
  19. * @var Collection
  20. */
  21. protected $tools;
  22. /**
  23. * Create a new Tools instance.
  24. *
  25. */
  26. public function __construct(Tree $tree)
  27. {
  28. $this->tree = $tree;
  29. $this->tools = new Collection();
  30. }
  31. /**
  32. * Prepend a tool.
  33. *
  34. * @param string $tool
  35. *
  36. * @return $this
  37. */
  38. public function add($tool)
  39. {
  40. $this->tools->push($tool);
  41. return $this;
  42. }
  43. /**
  44. * Render header tools bar.
  45. *
  46. * @return string
  47. */
  48. public function render()
  49. {
  50. return $this->tools->map([Helper::class, 'render'])->implode(' ');
  51. }
  52. }