| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- /* * ********************************************************************
- * ProxmoxAddon product developed. (Mar 9, 2018)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace MGProvision\Proxmox\v2\repository;
- use \MGProvision\Proxmox\v2\ProxmoxApiException;
- use \MGProvision\Proxmox\v2\models\IpSet;
- use \MGProvision\Proxmox\v2\interfaces\VmInterface;
- /**
- * Description of IpSetRepository
- *
- * @author Pawel Kopec <pawelk@modulesgardne.com>
- */
- class IpSetRepository extends AbstractRepository
- {
- protected $path;
- public function findByPath($path)
- {
- if (!preg_match('/ipset/', $path))
- {
- throw new ProxmoxApiException(sprintf("IpSet path ('%s') is not valid", $path));
- }
- $this->path = $path;
- return $this;
- }
- public function findByVm(VmInterface $vm)
- {
- $this->findByPath($vm->getPath() . '/firewall/ipset');
- return $this;
- }
- /**
- *
- * @return IpSet[]
- * @throws ProxmoxApiException
- */
- public function fetch()
- {
- if ($this->fetch)
- {
- return $this->fetch;
- }
- if (empty($this->path))
- {
- throw new ProxmoxApiException("IpSet path is empty");
- }
- $this->fetch = [];
- $ipSet = $this->api()->get($this->path);
- krsort($ipSet);
- foreach ($ipSet as $entity)
- {
- $this->fetch[] = (new IpSet("{$this->path}/{$entity['name']}"))->setAttributes($entity);
- }
- return $this->fetch;
- }
- public function find(IpSet $ipSet)
- {
- foreach ($this->fetch() as $cIpSet)
- {
- if ($cIpSet->getName() == $ipSet->getName())
- {
- return $cIpSet;
- }
- }
- return null;
- }
- }
|