NetworkRepository.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (May 18, 2018)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace MGProvision\Proxmox\v2\repository;
  20. use \MGProvision\Proxmox\v2\ProxmoxApiException;
  21. Use \MGProvision\Proxmox\v2\models\Network;
  22. /**
  23. * Description of NetworkRepository
  24. *
  25. * @author Pawel Kopec <pawelk@modulesgardne.com>
  26. */
  27. class NetworkRepository extends AbstractRepository
  28. {
  29. protected $path;
  30. protected $filters = [];
  31. public function findByPath($path)
  32. {
  33. if (!preg_match('/network/', $path))
  34. {
  35. throw new ProxmoxApiException(sprintf(__CLASS__ . " path ('%s') is not valid", $path));
  36. }
  37. $this->path = $path;
  38. return $this;
  39. }
  40. public function findTypeBridge()
  41. {
  42. $this->filters['type'] = 'bridge';
  43. return $this;
  44. }
  45. /**
  46. *
  47. * @return Network[]
  48. * @throws ProxmoxApiException
  49. */
  50. public function fetch()
  51. {
  52. if ($this->fetch)
  53. {
  54. return $this->fetch;
  55. }
  56. if (empty($this->path))
  57. {
  58. throw new ProxmoxApiException(__CLASS__ . " path is empty");
  59. }
  60. $this->fetch = [];
  61. foreach ($this->api()->get($this->path, $this->filters) as $data)
  62. {
  63. $this->fetch[] = (new Network())->setAttributes($data)->setPath($this->path);
  64. }
  65. return $this->fetch;
  66. }
  67. }