Skip to content

Commit

Permalink
Merge pull request BenMenking#2 from scottchiefbaker/master
Browse files Browse the repository at this point in the history
Add a destructor method to disconnect on close
  • Loading branch information
BenMenking committed Aug 31, 2015
2 parents af25efd + 624c924 commit 37ab64f
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions routeros_api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function is_iterable($var)
|| $var instanceof IteratorAggregate
);
}

/**
* Print text for debug purposes
*
Expand All @@ -50,10 +50,10 @@ function debug($text)
if ($this->debug)
echo $text . "\n";
}


/**
*
*
*
* @param string $length
*
Expand All @@ -76,8 +76,8 @@ function encode_length($length)
$length = chr(0xF0) . chr(($length >> 24) & 0xFF) . chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
return $length;
}


/**
* Login to RouterOS
*
Expand Down Expand Up @@ -122,8 +122,8 @@ function connect($ip, $login, $password)
$this->debug('Error...');
return $this->connected;
}


/**
* Disconnect from RouterOS
*
Expand All @@ -135,8 +135,8 @@ function disconnect()
$this->connected = false;
$this->debug('Disconnected...');
}


/**
* Parse response from Router OS
*
Expand Down Expand Up @@ -166,8 +166,8 @@ function parse_response($response)
if ($MATCHES[0][0] == 'ret') {
$singlevalue = $MATCHES[0][1];
}
$CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
}
$CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
}
}
}
if (empty($PARSED) && !is_null($singlevalue)) {
Expand All @@ -177,8 +177,8 @@ function parse_response($response)
} else
return array();
}


/**
* Parse response from Router OS
*
Expand Down Expand Up @@ -209,7 +209,7 @@ function parse_response4smarty($response)
$singlevalue = $MATCHES[0][1];
}
$CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
}
}
}
}
foreach ($PARSED as $key => $value) {
Expand All @@ -223,8 +223,8 @@ function parse_response4smarty($response)
return array();
}
}


/**
* Change "-" and "/" from array key to "_"
*
Expand All @@ -249,8 +249,8 @@ function array_change_key_name(&$array)
return $array;
}
}


/**
* Read data from Router OS
*
Expand Down Expand Up @@ -295,9 +295,9 @@ function read($parse = true)
} else {
$LENGTH = $BYTE;
}
$_ = "";

$_ = "";

// If we have got more characters to read, read them in.
if ($LENGTH > 0) {
$_ = "";
Expand All @@ -323,8 +323,8 @@ function read($parse = true)
$RESPONSE = $this->parse_response($RESPONSE);
return $RESPONSE;
}


/**
* Write (send) data to Router OS
*
Expand Down Expand Up @@ -354,8 +354,8 @@ function write($command, $param2 = true)
} else
return false;
}


/**
* Write (send) data to Router OS
*
Expand Down Expand Up @@ -389,5 +389,15 @@ function comm($com, $arr = array())
}
return $this->read();
}

/**
* Standard destructor
*
* @return void
*/
function __destruct()
{
$this->disconnect();
}
}
?>

0 comments on commit 37ab64f

Please sign in to comment.