src/Subnet.php
public function load($objectID) {
        $category = new CMDBCategory($this->api);
        $netInfo = $category->read($objectID, 'C__CATS__NET');

        if (count($netInfo) !== 1 ||
            !array_key_exists(0, $netInfo) ||
            !is_array($netInfo[0])) {
            throw new RuntimeException(sprintf(
                'Nothing found for object identifier %s',
                $objectID
            ));
        }

        if (!array_key_exists('type', $netInfo[0]) ||
            !is_array($netInfo[0]['type']) ||
            !array_key_exists('const', $netInfo[0]['type']) ||
            !is_string($netInfo[0]['type']['const']) ||
            $netInfo[0]['type']['const'] !== 'C__CATS_NET_TYPE__IPV4') {
            throw new RuntimeException('Works only for IPv4');
        }

        if (!array_key_exists('range_from', $netInfo[0]) ||
            !is_string($netInfo[0]['range_from']) ||
            !array_key_exists('range_to', $netInfo[0]) ||
            !is_string($netInfo[0]['range_to'])) {
            throw new RuntimeException(sprintf(
                'Subnet #%s has no IP address range',
                $objectID
            ));
        }

        $this->first = $this->convertIPv4Address($netInfo[0]['range_from']);
        $this->last = $this->convertIPv4Address($netInfo[0]['range_to']);

        $takenIPAddresses = $category->read($objectID, 'C__CATS__NET_IP_ADDRESSES');

        foreach ($takenIPAddresses as $takenIPAddress) {
            $this->taken[] = $takenIPAddress['title'];
        }

        $this->current = $this->first;

        return $this;
    }
public function load($objectID) {
        $category = new CMDBCategory($this->api);
        $netInfo = $category->read($objectID, 'C__CATS__NET');

        if (count($netInfo) !== 1 ||
            !array_key_exists(0, $netInfo) ||
            !is_array($netInfo[0])) {
            throw new RuntimeException(sprintf(
                'Nothing found for object identifier %s',
                $objectID
            ));
        }

        if (!array_key_exists('type', $netInfo[0]) ||
            !is_array($netInfo[0]['type']) ||
            !array_key_exists('const', $netInfo[0]['type']) ||
            !is_string($netInfo[0]['type']['const']) ||
            $netInfo[0]['type']['const'] !== 'C__CATS_NET_TYPE__IPV4') {
            throw new RuntimeException('Works only for IPv4');
        }

        if (!array_key_exists('range_from', $netInfo[0]) ||
            !is_string($netInfo[0]['range_from']) ||
            !array_key_exists('range_to', $netInfo[0]) ||
            !is_string($netInfo[0]['range_to'])) {
            throw new RuntimeException(sprintf(
                'Subnet #%s has no IP address range',
                $objectID
            ));
        }

        $this->first = $this->convertIPv4Address($netInfo[0]['range_from']);
        $this->last = $this->convertIPv4Address($netInfo[0]['range_to']);

        $takenIPAddresses = $category->read($objectID, 'C__CATS__NET_IP_ADDRESSES');

        foreach ($takenIPAddresses as $takenIPAddress) {
            $this->taken[] = $takenIPAddress['title'];
        }

        $this->current = $this->first;

        return $this;
    }
public function load ( $ objectID ) { $ category = new CMDBCategory ( $ this -> api ) ; $ netInfo = $ category -> read ( $ objectID , 'C__CATS__NET' ) ; if ( count ( $ netInfo ) !== 1 || ! array_key_exists ( 0 , $ netInfo ) || ! is_array ( $ netInfo [ 0 ] ) ) { throw new RuntimeException ( sprintf ( 'Nothing found for object identifier %s' , $ objectID ) ) ; } if ( ! array_key_exists ( 'type' , $ netInfo [ 0 ] ) || ! is_array ( $ netInfo [ 0 ] [ 'type' ] ) || ! array_key_exists ( 'const' , $ netInfo [ 0 ] [ 'type' ] ) || ! is_string ( $ netInfo [ 0 ] [ 'type' ] [ 'const' ] ) || $ netInfo [ 0 ] [ 'type' ] [ 'const' ] !== 'C__CATS_NET_TYPE__IPV4' ) { throw new RuntimeException ( 'Works only for IPv4' ) ; } if ( ! array_key_exists ( 'range_from' , $ netInfo [ 0 ] ) || ! is_string ( $ netInfo [ 0 ] [ 'range_from' ] ) || ! array_key_exists ( 'range_to' , $ netInfo [ 0 ] ) || ! is_string ( $ netInfo [ 0 ] [ 'range_to' ] ) ) { throw new RuntimeException ( sprintf ( 'Subnet #%s has no IP address range' , $ objectID ) ) ; } $ this -> first = $ this -> convertIPv4Address ( $ netInfo [ 0 ] [ 'range_from' ] ) ; $ this -> last = $ this -> convertIPv4Address ( $ netInfo [ 0 ] [ 'range_to' ] ) ; $ takenIPAddresses = $ category -> read ( $ objectID , 'C__CATS__NET_IP_ADDRESSES' ) ; foreach ( $ takenIPAddresses as $ takenIPAddress ) { $ this -> taken [ ] = $ takenIPAddress [ 'title' ] ; } $ this -> current = $ this -> first ; return $ this ; }
Fetches some information about subnet object

@param int $objectID Object identifier

@return self Returns itself

@throws Exception on error
Fetches some information about subnet object