1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace IPv4Bundle\Services;
- use Doctrine\ORM\EntityManager;
- use Doctrine\ORM\EntityRepository;
- use IPv4Bundle\Entity\Pool;
- use KeaBundle\Entity\Lease4;
- class PoolService
- {
-
- /**
- * @var EntityRepository
- */
- private $poolRepository;
-
-
- /**
- * @param EntityManager $em
- */
- public function __construct(EntityManager $em)
- {
- $this->poolRepository = $em->getRepository(Pool::class);
- }
-
- /**
- * Retorna el primer pool donde se encuentra el lease
- *
- * @param Lease4 $lease
- *
- * @return Pool
- */
- public function getPoolFromLease(Lease4 $lease)
- {
- $address = ip2long($lease->getAddress());
- $pools = $this->poolRepository->findAll();
- foreach ($pools as $pool) {
- $firstIp = ip2long($pool->getFirstIp());
- $lastIp = ip2long($pool->getLastIp());
-
- if ($firstIp <= $address && $address <= $lastIp) {
- return $pool;
- }
- }
-
- return null;
- }
-
- }
|