Skip to content

Commit

Permalink
Moved some code from sections controller to base controller
Browse files Browse the repository at this point in the history
Added subnet controller -> not full yet
  • Loading branch information
Oliver Wycisk committed Jan 7, 2018
1 parent 6d89458 commit 75503f7
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 25 deletions.
24 changes: 24 additions & 0 deletions src/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,28 @@ protected function _deleteStatic(array $identifier = array(), array $params = ar
return phpipamConnection()->call('delete', static::$controllerName, $identifier, $params);
}

/**
* Sets the parameter of the section from array
*
* @param array $params
*/
protected function setParams(array $params)
{
foreach ($params as $key => $value)
{
$this->$key = $value;
}
}

/**
* Gets all parameter in a array
* @return array
*/
protected function getParams()
{
$params = get_object_vars($this);
unset($params['controllerName']);

return $params;
}
}
25 changes: 0 additions & 25 deletions src/Controller/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,31 +213,6 @@ public function delete()
return parent::_delete([], ['id' => $this->getId()])->isSuccess();
}

/**
* Sets the parameter of the section from array
*
* @param array $params
*/
protected function setParams(array $params)
{
foreach ($params as $key => $value)
{
$this->$key = $value;
}
}

/**
* Gets all parameter in a array
* @return array
*/
protected function getParams()
{
$params = get_object_vars($this);
unset($params['controllerName']);

return $params;
}

/**
* @return int
*/
Expand Down
113 changes: 113 additions & 0 deletions src/Controller/Subnet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Created by PhpStorm.
* User: Oliver
* Date: 07.01.2018
* Time: 22:18
*/

namespace colq2\PhpIPAMClient\Controller;


class Subnet extends BaseController
{

protected static $controllerName = 'subnets';

protected $id;
protected $subnet;
protected $mask;
protected $description;
protected $sectionId;
protected $linked_subnet;
protected $vlanId;
protected $vrfId;
protected $masterSubnetId;
protected $nameserverId;
protected $showName;
protected $permissions;
protected $DNSrecursive;
protected $DNSrecords;
protected $allowRequests;
protected $scanAgent;
protected $pingSubnet;
protected $discoverSubnet;
protected $isFolder;
protected $isFull;
protected $state;
protected $threshold;
protected $location;
protected $editDate;


public function __construct(array $params = array())
{
$this->setParams($params);
}

public static function getByID(int $id)
{
$response = self::_getStatic([$id]);

return new Subnet($response->getData());
}

public static function getCIDR(string $subnet)
{
//TODO implement
}

public function getUsage()
{
return self::_getStatic([$this->id, 'usage'])->getData();
}

public function getFirstFree()
{
return $this->_get([$this->id, 'first_free'])->getData();
}

public function getSlaves()
{
//TODO: return objects
return $this->_get([$this->id, 'slaves'])->getData();
}

public function getSlavesRecursive()
{
//TODO: return objects
return $this->_get([$this->id, 'slaves_recursive'])->getData();
}

public function getAddresses()
{
return $this->_get([$this->id, 'addresses'])->getData();
}

public function getAddressesIP(string $ip)
{
return $this->_get([$this->id, 'addresses', $ip])->getData();
}

public function getFirstSubnet(int $mask)
{
return $this->_get([$this->id, 'first_subnet', $mask])->getData();
}

public function getAllSubnets(int $mask)
{
return $this->_get([$this->id, 'all_subnets', $mask])->getData();
}

public function getCustomFields()
{
return $this->_get(['custom_fields']);
}

public function getSearch(string $subnet)
{

}


}

0 comments on commit 75503f7

Please sign in to comment.