| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?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\models\IpCidr;
- /**
- * Description of IpSetRepository
- *
- * @author Pawel Kopec <pawelk@modulesgardne.com>
- */
- 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;
- }
- }
|