note 108558 added to ref.snmp

From: Date: Mon, 07 May 2012 00:49:00 +0000
Subject: note 108558 added to ref.snmp
Groups: php.notes 
Request: Send a blank email to php-notes+get-187496@lists.php.net to get a copy of this message
I wrote a wrapper class that should work with all versions of the available snmp protocols. It's extremely light weight and tries to follow the Zend conventions. Here you go: <?php class SNMP_Wrapper { protected $_host; protected $_community; protected $_version; public function __construct($host='localhost',$community='public',$version=1) { $this->_host = $host; $this->_community = $community; switch ($version) { case 2: $this->_version = '2'; break; case 3: $this->_version = '3'; default: $this->_version = ''; break; } } public function __call($func,$args) { $func = strtolower(preg_replace('/([A-Z])/', '_$1', $func)); $function = 'snmp' . $this->_version . (empty($this->_version) ? '' : '_') . $func; if (function_exists($function)) { return call_user_func_array($function, array_merge(array($this->_host,$this->_community),$args)); } } } // Testing it $snmp = new SNMP_Wrapper('localhost','public','2'); print_r($snmp->realWalk('IF')); ?> That's all :) ---- Server IP: 87.106.1.137 Probable Submitter: 93.218.94.51 ---- Manual Page -- http://www.php.net/manual/en/ref.snmp.php Edit -- https://master.php.net/note/edit/108558 Del: integrated -- https://master.php.net/note/delete/108558/integrated Del: useless -- https://master.php.net/note/delete/108558/useless Del: bad code -- https://master.php.net/note/delete/108558/bad+code Del: spam -- https://master.php.net/note/delete/108558/spam Del: non-english -- https://master.php.net/note/delete/108558/non-english Del: in docs -- https://master.php.net/note/delete/108558/in+docs Del: other reasons-- https://master.php.net/note/delete/108558 Reject -- https://master.php.net/note/reject/108558 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187496) next »