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 */ 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; } }