PEAR2_Net_RouterOS
1.0.0b1
A MikroTik RouterOS client
|
00001 <?php 00002 00022 namespace PEAR2\Net\RouterOS; 00023 00027 use PEAR2\Net\Transmitter as T; 00028 00038 abstract class Message 00039 { 00040 00045 protected $arguments = array(); 00046 00050 private $_tag = null; 00051 00059 public static function sanitizeArgumentName($name) 00060 { 00061 $name = (string) $name; 00062 if ((empty($name) && $name !== '0') 00063 || !preg_match('/[^=\s]/s', $name) 00064 ) { 00065 throw new InvalidArgumentException( 00066 'Invalid name of argument supplied.', 200 00067 ); 00068 } 00069 return $name; 00070 } 00071 00079 public static function sanitizeArgumentValue($value) 00080 { 00081 if (T\StreamTransmitter::isStream($value)) { 00082 $meta = stream_get_meta_data($value); 00083 if ($meta['seekable']) { 00084 return $value; 00085 } 00086 throw new InvalidArgumentException( 00087 'The stream must be seekable.', 201 00088 ); 00089 } else { 00090 return (string) $value; 00091 } 00092 } 00093 00100 public function getTag() 00101 { 00102 return $this->_tag; 00103 } 00104 00116 protected function setTag($tag) 00117 { 00118 $this->_tag = (null === $tag) ? null : (string) $tag; 00119 return $this; 00120 } 00121 00131 public function getArgument($name) 00132 { 00133 $name = self::sanitizeArgumentName($name); 00134 if (array_key_exists($name, $this->arguments)) { 00135 return $this->arguments[$name]; 00136 } 00137 return null; 00138 } 00139 00148 public function getAllArguments() 00149 { 00150 return $this->arguments; 00151 } 00152 00163 protected function setArgument($name, $value = null) 00164 { 00165 if (null === $value) { 00166 unset($this->arguments[self::sanitizeArgumentName($name)]); 00167 } else { 00168 $this->arguments[self::sanitizeArgumentName($name)] 00169 = self::sanitizeArgumentValue($value); 00170 } 00171 return $this; 00172 } 00173 00179 protected function removeAllArguments() 00180 { 00181 $this->arguments = array(); 00182 return $this; 00183 } 00184 00185 }