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\models\IpCidr; /** * Description of IpSetRepository * * @author Pawel Kopec */ class IpCidrRepository extends AbstractRepository { protected $path; public function findByPath($path) { if (!preg_match('/ipset/', $path)) { throw new ProxmoxApiException(sprintf("IpCidr path ('%s') is not valid", $path)); } $this->path = $path; return $this; } /** * * @return IpCidr[] * @throws ProxmoxApiException */ public function fetch() { if ($this->fetch) { return $this->fetch; } if (empty($this->path)) { throw new ProxmoxApiException("IpSet path is empty"); } $this->fetch = []; foreach ($this->api()->get($this->path) as $entity) { $this->fetch[] = (new IpCidr($this->path . "/" . $entity['cidr']))->setAttributes($entity); } return $this->fetch; } public function find(IpCidr $ipCidr) { foreach ($this->fetch() as $cIpCidr) { if ($cIpCidr->getCidr() == $ipCidr->getCidr()) { return $cIpCidr; } } return null; } }