IpConfigRepository.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (May 28, 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\IpConfig;
  22. /**
  23. * Description of IpConfigRepository
  24. *
  25. * @author Pawel Kopec <pawelk@modulesgardne.com>
  26. */
  27. class IpConfigRepository extends AbstractRepository
  28. {
  29. protected $path;
  30. protected $filters=[];
  31. public function findByPath($path)
  32. {
  33. if (!preg_match('/config/', $path))
  34. {
  35. throw new ProxmoxApiException(sprintf("Ipconfigt path ('%s') is not valid", $path));
  36. }
  37. $this->path = $path;
  38. return $this;
  39. }
  40. /**
  41. *
  42. * @return IpConfig[]
  43. * @throws ProxmoxApiException
  44. */
  45. public function fetch()
  46. {
  47. if ($this->fetch)
  48. {
  49. return $this->fetch;
  50. }
  51. if (empty($this->path))
  52. {
  53. throw new ProxmoxApiException("IpConfig path is empty");
  54. }
  55. $this->fetch = [];
  56. $get = $this->api()->get($this->path);
  57. krsort($get);
  58. foreach ($get as $id => $config)
  59. {
  60. if (!preg_match('/ipconfig/', $id))
  61. {
  62. continue;
  63. }
  64. $key = preg_replace("/ipconfig/","", $id);
  65. if(isset($this->filters['networkId']) && $key != $this->filters['networkId']){
  66. continue;
  67. }
  68. $this->fetch[] = new IpConfig($id, $config);
  69. }
  70. return $this->fetch;
  71. }
  72. public function findByNetworkId($networkId){
  73. $this->filters['networkId'] = preg_replace("/net/","", $networkId);
  74. return $this;
  75. }
  76. }