nasrulhazim
1/31/2019 - 9:56 AM

Internal Network Service

Internal Network Service

<?php 

namespace App\Services\Network;

class Internal 
{
	/**
	 * Public IP Address
	 * @var string
	 */
	private $public_ip_address;

	/**
	 * Subnet Calculator
	 * @var \IPv4\SubnetCalculator
	 */
	private $subnet_calculator;

	public function __construct($public_ip_address, $cidr_mask)
	{
		$this->public_ip_address = $public_ip_address;
		$this->subnet_calculator = new \IPv4\SubnetCalculator($this->public_ip_address, $cidr_mask);
	}

	public static function make($public_ip_address, $cidr_mask)
	{
		return new self($public_ip_address, $cidr_mask);
	}

	public function subnetCalculator()
	{
		return $this->subnet_calculator;
	}

	public function setInternalSubnetMask($subnet_mask)
	{
		$this->subnet_mask = $subnet_mask;

		return $this;
	}

	public function getInternalSubnetMask()
	{
		return $this->subnet_mask;
	}

	public function isInternalNetwork()
	{
		return $this->subnetCalculator()->getSubnetMask() == $this->getInternalSubnetMask();
	}
}