Skip to content

Commit 37ab64f

Browse files
committed
Merge pull request BenMenking#2 from scottchiefbaker/master
Add a destructor method to disconnect on close
2 parents af25efd + 624c924 commit 37ab64f

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

routeros_api.class.php

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function is_iterable($var)
3737
|| $var instanceof IteratorAggregate
3838
);
3939
}
40-
40+
4141
/**
4242
* Print text for debug purposes
4343
*
@@ -50,10 +50,10 @@ function debug($text)
5050
if ($this->debug)
5151
echo $text . "\n";
5252
}
53-
54-
53+
54+
5555
/**
56-
*
56+
*
5757
*
5858
* @param string $length
5959
*
@@ -76,8 +76,8 @@ function encode_length($length)
7676
$length = chr(0xF0) . chr(($length >> 24) & 0xFF) . chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
7777
return $length;
7878
}
79-
80-
79+
80+
8181
/**
8282
* Login to RouterOS
8383
*
@@ -122,8 +122,8 @@ function connect($ip, $login, $password)
122122
$this->debug('Error...');
123123
return $this->connected;
124124
}
125-
126-
125+
126+
127127
/**
128128
* Disconnect from RouterOS
129129
*
@@ -135,8 +135,8 @@ function disconnect()
135135
$this->connected = false;
136136
$this->debug('Disconnected...');
137137
}
138-
139-
138+
139+
140140
/**
141141
* Parse response from Router OS
142142
*
@@ -166,8 +166,8 @@ function parse_response($response)
166166
if ($MATCHES[0][0] == 'ret') {
167167
$singlevalue = $MATCHES[0][1];
168168
}
169-
$CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
170-
}
169+
$CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
170+
}
171171
}
172172
}
173173
if (empty($PARSED) && !is_null($singlevalue)) {
@@ -177,8 +177,8 @@ function parse_response($response)
177177
} else
178178
return array();
179179
}
180-
181-
180+
181+
182182
/**
183183
* Parse response from Router OS
184184
*
@@ -209,7 +209,7 @@ function parse_response4smarty($response)
209209
$singlevalue = $MATCHES[0][1];
210210
}
211211
$CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
212-
}
212+
}
213213
}
214214
}
215215
foreach ($PARSED as $key => $value) {
@@ -223,8 +223,8 @@ function parse_response4smarty($response)
223223
return array();
224224
}
225225
}
226-
227-
226+
227+
228228
/**
229229
* Change "-" and "/" from array key to "_"
230230
*
@@ -249,8 +249,8 @@ function array_change_key_name(&$array)
249249
return $array;
250250
}
251251
}
252-
253-
252+
253+
254254
/**
255255
* Read data from Router OS
256256
*
@@ -295,9 +295,9 @@ function read($parse = true)
295295
} else {
296296
$LENGTH = $BYTE;
297297
}
298-
299-
$_ = "";
300-
298+
299+
$_ = "";
300+
301301
// If we have got more characters to read, read them in.
302302
if ($LENGTH > 0) {
303303
$_ = "";
@@ -323,8 +323,8 @@ function read($parse = true)
323323
$RESPONSE = $this->parse_response($RESPONSE);
324324
return $RESPONSE;
325325
}
326-
327-
326+
327+
328328
/**
329329
* Write (send) data to Router OS
330330
*
@@ -354,8 +354,8 @@ function write($command, $param2 = true)
354354
} else
355355
return false;
356356
}
357-
358-
357+
358+
359359
/**
360360
* Write (send) data to Router OS
361361
*
@@ -389,5 +389,15 @@ function comm($com, $arr = array())
389389
}
390390
return $this->read();
391391
}
392+
393+
/**
394+
* Standard destructor
395+
*
396+
* @return void
397+
*/
398+
function __destruct()
399+
{
400+
$this->disconnect();
401+
}
392402
}
393403
?>

0 commit comments

Comments
 (0)