@ -119,27 +119,47 @@ class Ponvif {
/*
Public functions ( basic initialization method and other collaterals )
*/
/*
Errors here must be Exceptions : the callers use try { initialize () } catch ( Exception $e ) .
Before , a camera answering GetVideoSources with an HTML page ( e . g . HTTP 401 ) or with no
< VideoSources > made PHP 8 throw an Error / TypeError ( $xml -> getName () on false , count ( null ))
that went past catch ( Exception ) and ended the whole request .
*/
public function initialize () {
$this -> mediauri = 'http://' . $this -> ipaddress . '/onvif/device_service' ;
try {
$datetime = $this -> core_GetSystemDateAndTime ();
$timestamp = mktime ( $datetime [ 'Time' ][ 'Hour' ], $datetime [ 'Time' ][ 'Minute' ], $datetime [ 'Time' ][ 'Second' ],
$datetime [ 'Date' ][ 'Month' ], $datetime [ 'Date' ][ 'Day' ], $datetime [ 'Date' ][ 'Year' ]);
$this -> deltatime = time () - $timestamp - 5 ;
} catch ( Exception $e ) {}
if ( is_array ( $datetime ) && isset ( $datetime [ 'Time' ]) && isset ( $datetime [ 'Date' ])) {
$timestamp = mktime ( $datetime [ 'Time' ][ 'Hour' ], $datetime [ 'Time' ][ 'Minute' ], $datetime [ 'Time' ][ 'Second' ],
$datetime [ 'Date' ][ 'Month' ], $datetime [ 'Date' ][ 'Day' ], $datetime [ 'Date' ][ 'Year' ]);
$this -> deltatime = time () - $timestamp - 5 ;
}
} catch ( Throwable $e ) {}
$this -> capabilities = $this -> core_GetCapabilities ();
$onvifVersion = $this -> _getOnvifVersion ( $this -> capabilities );
$this -> mediauri = $onvifVersion [ 'media' ];
$this -> deviceuri = $onvifVersion [ 'device' ];
$this -> ptzuri = $onvifVersion [ 'ptz' ];
preg_match ( " /^http(.*)onvif \ // " , $this -> mediauri , $matches );
$this -> baseuri = $matches [ 0 ];
$this -> onvifversion = array ( 'major' => $onvifVersion [ 'major' ], 'minor' => $onvifVersion [ 'minor' ]);
$this -> videosources = $this -> media_GetVideoSources ();
$this -> profiles = $this -> media_GetProfiles ();
$this -> sources = $this -> _getActiveSources ( $this -> videosources , $this -> profiles );
try {
$this -> capabilities = $this -> core_GetCapabilities ();
if ( ! is_array ( $this -> capabilities ) || ! isset ( $this -> capabilities [ 'Media' ][ 'XAddr' ]))
throw new Exception ( 'GetCapabilities: no media service in the reply' );
$onvifVersion = $this -> _getOnvifVersion ( $this -> capabilities );
$this -> mediauri = $onvifVersion [ 'media' ];
$this -> deviceuri = $onvifVersion [ 'device' ];
$this -> ptzuri = $onvifVersion [ 'ptz' ];
preg_match ( " /^http(.*)onvif \ // " , $this -> mediauri , $matches );
$this -> baseuri = isset ( $matches [ 0 ]) ? $matches [ 0 ] : '' ;
$this -> onvifversion = array ( 'major' => $onvifVersion [ 'major' ], 'minor' => $onvifVersion [ 'minor' ]);
$this -> videosources = $this -> media_GetVideoSources ();
if ( ! is_array ( $this -> videosources ) || count ( $this -> videosources ) == 0 )
throw new Exception ( 'GetVideoSources: no video source in the reply' );
$this -> profiles = $this -> media_GetProfiles ();
if ( ! is_array ( $this -> profiles ) || count ( $this -> profiles ) == 0 )
throw new Exception ( 'GetProfiles: no media profile in the reply' );
$this -> sources = $this -> _getActiveSources ( $this -> videosources , $this -> profiles );
} catch ( Exception $e ) {
throw $e ;
} catch ( Throwable $e ) {
throw new Exception ( 'ONVIF initialize: ' . $e -> getMessage (), 0 , $e );
}
}
public function isFault ( $response ) { // Useful to check if response contains a fault
@ -160,7 +180,7 @@ class Ponvif {
public function core_GetSystemDateAndTime () {
$post_string = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"/></s:Body></s:Envelope>' ;
if ( $this -> isFault ( $response = $this -> _send_request ( $this -> mediauri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GetSystemDateAndTime: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GetSystemDateAndTime: Communication error' . $this -> _faultText () );
} else {
return $response [ 'Envelope' ][ 'Body' ][ 'GetSystemDateAndTimeResponse' ][ 'SystemDateAndTime' ][ 'UTCDateTime' ];
}
@ -179,7 +199,7 @@ class Ponvif {
$REQ [ 'TIMESTAMP' ])),
$post_string );
if ( $this -> isFault ( $response = $this -> _send_request ( $this -> mediauri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GetCapabilities: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GetCapabilities: Communication error' . $this -> _faultText () );
}
else
return $response [ 'Envelope' ][ 'Body' ][ 'GetCapabilitiesResponse' ][ 'Capabilities' ];
@ -199,11 +219,11 @@ class Ponvif {
$post_string );
//echo "POST STRING:" . $post_string . "\n\n";
if ( $this -> isFault ( $response = $this -> _send_request ( $this -> mediauri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GetVideoSources: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GetVideoSources: Communication error' . $this -> _faultText () );
}
else
// var_dump( $response );
return $response [ 'Envelope' ][ 'Body' ][ 'GetVideoSourcesResponse' ][ 'VideoSources' ];
return isset ( $response [ 'Envelope' ][ 'Body' ][ 'GetVideoSourcesResponse' ][ 'VideoSources' ]) ? $response [ 'Envelope' ][ 'Body' ][ 'GetVideoSourcesResponse' ][ 'VideoSources' ] : null ;
}
public function media_GetProfiles () {
@ -219,7 +239,7 @@ class Ponvif {
$REQ [ 'TIMESTAMP' ])),
$post_string );
if ( $this -> isFault ( $response = $this -> _send_request ( $this -> mediauri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GetProfiles: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GetProfiles: Communication error' . $this -> _faultText () );
}
else
return $response [ 'Envelope' ][ 'Body' ][ 'GetProfilesResponse' ][ 'Profiles' ];
@ -238,7 +258,7 @@ class Ponvif {
$REQ [ 'TIMESTAMP' ])),
$post_string );
if ( $this -> isFault ( $this -> _send_request ( $this -> mediauri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GetServices: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GetServices: Communication error' . $this -> _faultText () );
}
}
@ -255,7 +275,7 @@ class Ponvif {
$REQ [ 'TIMESTAMP' ])),
$post_string );
if ( $this -> isFault ( $response = $this -> _send_request ( $this -> mediauri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GetDeviceInformation: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GetDeviceInformation: Communication error' . $this -> _faultText () );
}
else
return $response [ 'Envelope' ][ 'Body' ][ 'GetDeviceInformationResponse' ];
@ -282,7 +302,7 @@ class Ponvif {
$post_string
);
if ( $this -> isFault ( $response = $this -> _send_request ( $this -> mediauri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GetStreamUri: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GetStreamUri: Communication error' . $this -> _faultText () );
}
else
return $response [ 'Envelope' ][ 'Body' ][ 'GetStreamUriResponse' ][ 'MediaUri' ][ 'Uri' ];
@ -303,7 +323,7 @@ class Ponvif {
$profileToken )),
$post_string );
if ( $this -> isFault ( $response = $this -> _send_request ( $this -> mediauri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GetSnapshotUri: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GetSnapshotUri: Communication error' . $this -> _faultText () );
var_dump ( $response );
}
else
@ -326,7 +346,7 @@ class Ponvif {
$profileToken )),
$post_string );
if ( $this -> isFault ( $response = $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GetPresets: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GetPresets: Communication error' . $this -> _faultText () );
}
else {
$getpresetsresponse = $response [ 'Envelope' ][ 'Body' ][ 'GetPresetsResponse' ][ 'Preset' ];
@ -356,7 +376,7 @@ class Ponvif {
$ptzNodeToken )),
$post_string );
if ( $this -> isFault ( $response = $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GetNode: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GetNode: Communication error' . $this -> _faultText () );
}
else
return $response [ 'Envelope' ][ 'Body' ][ 'GetNodeResponse' ];
@ -386,7 +406,7 @@ class Ponvif {
$speed_zoom_x )),
$post_string );
if ( $this -> isFault ( $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'GotoPreset: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'GotoPreset: Communication error' . $this -> _faultText () );
}
}
@ -408,7 +428,7 @@ class Ponvif {
$presetToken )),
$post_string );
if ( $this -> isFault ( $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'RemovePreset: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'RemovePreset: Communication error' . $this -> _faultText () );
}
}
@ -430,7 +450,7 @@ class Ponvif {
$presetName )),
$post_string );
if ( $this -> isFault ( $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'SetPreset: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'SetPreset: Communication error' . $this -> _faultText () );
}
}
@ -458,7 +478,7 @@ class Ponvif {
$speed_pantilt_y )),
$post_string );
if ( $this -> isFault ( $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'RelativeMove: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'RelativeMove: Communication error' . $this -> _faultText () );
}
}
@ -482,7 +502,7 @@ class Ponvif {
$zoom )),
$post_string );
if ( $this -> isFault ( $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'RelativeMoveZoom: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'RelativeMoveZoom: Communication error' . $this -> _faultText () );
}
}
@ -537,7 +557,7 @@ class Ponvif {
$ZSpeed )),
$post_string );
if ( $this -> isFault ( $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'AbsoluteMove: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'AbsoluteMove: Communication error' . $this -> _faultText () );
}
}
@ -561,7 +581,7 @@ class Ponvif {
$velocity_pantilt_y )),
$post_string );
if ( $this -> isFault ( $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'ContinuousMove: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'ContinuousMove: Communication error' . $this -> _faultText () );
}
}
@ -583,7 +603,7 @@ class Ponvif {
$zoom )),
$post_string );
if ( $this -> isFault ( $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'ContinuousMoveZoom: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'ContinuousMoveZoom: Communication error' . $this -> _faultText () );
}
}
@ -607,7 +627,7 @@ class Ponvif {
$zoom )),
$post_string );
if ( $this -> isFault ( $this -> _send_request ( $this -> ptzuri , $post_string ))) {
if ( $this -> intransingent ) throw new Exception ( 'Stop: Communication error' );
if ( $this -> intransingent ) throw new Exception ( 'Stop: Communication error' . $this -> _faultText () );
}
}
@ -620,30 +640,49 @@ class Ponvif {
}
protected function _getOnvifVersion ( $capabilities ) {
$version = array ();
if ( isset ( $capabilities [ 'Device' ][ 'System' ][ 'SupportedVersions' ][ 'Major' ])) {
// NVT supports a specific onvif version
$version [ 'major' ] = $capabilities [ 'Device' ][ 'System' ][ 'SupportedVersions' ][ 'Major' ];
$version [ 'minor' ] = $capabilities [ 'Device' ][ 'System' ][ 'SupportedVersions' ][ 'Min or' ];
} else {
// NVT supports more onvif versions
$currentma = 0 ;
$currentmi = 0 ;
foreach ( $capabilities [ 'Device' ][ 'System' ][ 'SupportedVersions' ] as $cver ) {
if ( $cver [ 'Major' ] > $currentma ) { $currentma = $cver [ 'Major' ]; $currentmi = $cver [ 'Minor' ]; }
}
$version [ 'major' ] = $currentma ;
$version [ 'minor' ] = $currentmi ;
$version = array ( 'major' => 0 , 'minor' => 0 );
$sv = isset ( $capabilities [ 'Device' ][ 'System' ][ 'SupportedVersions' ]) ? $capabilities [ 'Device' ][ 'System' ][ 'SupportedVersions' ] : null ;
if ( is_array ( $sv ) && isset ( $sv [ 'Major' ])) {
// NVT supports a specific onvif version
$version [ 'major' ] = $sv [ 'Maj or' ];
$version [ 'minor' ] = isset ( $sv [ 'Minor' ]) ? $sv [ 'Minor' ] : 0 ;
} elseif ( is_array ( $sv )) {
// NVT supports more onvif versions
foreach ( $sv as $cver ) {
if ( is_array ( $cver ) && isset ( $cver [ 'Major' ]) && $cver [ 'Major' ] > $version [ 'major' ] ) {
$version [ 'major' ] = $cver [ 'Major' ];
$version [ 'minor' ] = isset ( $cver [ 'Minor' ]) ? $cver [ 'Minor' ] : 0 ;
}
}
}
$version [ 'media' ] = $capabilities [ 'Media' ][ 'XAddr' ];
$version [ 'device' ] = $capabilities [ 'Device' ][ 'XAddr' ];
$version [ 'event' ] = $capabilities [ 'Events' ][ 'XAddr' ];
if ( isset ( $capabilities [ 'PTZ' ][ 'XAddr' ])) $version [ 'ptz' ] = $capabilities [ 'PTZ' ][ 'XAddr' ]; else $version [ 'ptz' ] = '' ;
$version [ 'media' ] = isset ( $capabilities [ 'Media' ][ 'XAddr' ]) ? $capabilities [ 'Media' ][ 'XAddr' ] : '' ;
$version [ 'device' ] = isset ( $capabilities [ 'Device' ][ 'XAddr' ]) ? $capabilities [ 'Device' ][ 'XAddr' ] : '' ;
$version [ 'event' ] = isset ( $capabilities [ 'Events' ][ 'XAddr' ]) ? $capabilities [ 'Events' ][ 'XAddr' ] : '' ;
$version [ 'ptz' ] = isset ( $capabilities [ 'PTZ' ][ 'XAddr' ]) ? $capabilities [ 'PTZ' ][ 'XAddr' ] : '' ;
return $version ;
}
// Why the last request failed: " (HTTP 401: reply is not a SOAP envelope)" or the SOAP Fault reason
protected function _faultText () {
$r = $this -> lastresponse ;
if ( is_array ( $r ) && isset ( $r [ 'Fault' ]) && is_string ( $r [ 'Fault' ])) return ' (' . $r [ 'Fault' ] . ')' ;
if ( is_array ( $r ) && isset ( $r [ 'Envelope' ][ 'Body' ][ 'Fault' ][ 'Reason' ][ 'Text' ])) {
$t = $r [ 'Envelope' ][ 'Body' ][ 'Fault' ][ 'Reason' ][ 'Text' ];
if ( is_string ( $t )) return ' (' . $t . ')' ;
}
return '' ;
}
// One XML element decodes to an associative array, several to a list: always return a list
protected function _asList ( $v ) {
if ( ! is_array ( $v )) return array ();
if ( isset ( $v [ '@attributes' ]) || ! array_key_exists ( 0 , $v )) return array ( $v );
return $v ;
}
protected function _getActiveSources ( $videoSources , $profiles ) {
$sources = array ();
if ( ! is_array ( $videoSources )) return $sources ;
if ( isset ( $videoSources [ '@attributes' ])) {
// NVT is a camera
@ -652,8 +691,9 @@ class Ponvif {
}
else {
// NVT is an encoder
$videoSources = $this -> _asList ( $videoSources );
for ( $i = 0 ; $i < count ( $videoSources ); $i ++ ) {
if ( strtolower ( $videoSources [ $i ][ '@attributes' ][ 'SignalActive' ]) == 'true' ) {
if ( isset ( $videoSources [ $i ][ '@attributes' ][ 'SignalActive' ]) && strtolower ( $videoSources [ $i ][ '@attributes' ][ 'SignalActive' ]) == 'true' ) {
$sources [ $i ][ 'sourcetoken' ] = $videoSources [ $i ][ '@attributes' ][ 'token' ];
$this -> _getProfileData ( $sources , $i , $profiles );
}
@ -665,16 +705,20 @@ class Ponvif {
protected function _getProfileData ( & $sources , $i , $profiles ) {
$inprofile = 0 ;
// A camera with ONE profile: count() counted the fields of that profile, no source was found
$profiles = $this -> _asList ( $profiles );
for ( $y = 0 ; $y < count ( $profiles ); $y ++ ) {
if ( $profiles [ $y ][ 'VideoSourceConfiguration' ][ 'SourceToken' ] == $sources [ $i ][ 'sourcetoken' ]) {
if ( isset ( $profiles [ $y ][ 'VideoSourceConfiguration' ][ 'SourceToken' ]) && $profiles [ $y ][ 'VideoSourceConfiguration' ][ 'SourceToken' ] == $sources [ $i ][ 'sourcetoken' ]) {
$sources [ $i ][ $inprofile ][ 'profilename' ] = $profiles [ $y ][ 'Name' ];
$sources [ $i ][ $inprofile ][ 'profiletoken' ] = $profiles [ $y ][ '@attributes' ][ 'token' ];
if ( isset ( $profiles [ $y ][ 'VideoEncoderConfiguration' ])) {
$sources [ $i ][ $inprofile ][ 'encoding' ] = $profiles [ $y ][ 'VideoEncoderConfiguration' ][ 'Encoding' ];
$sources [ $i ][ $inprofile ][ 'width' ] = $profiles [ $y ][ 'VideoEncoderConfiguration' ][ 'Resolution' ][ 'Width' ];
$sources [ $i ][ $inprofile ][ 'height' ] = $profiles [ $y ][ 'VideoEncoderConfiguration' ][ 'Resolution' ][ 'Height' ];
$sources [ $i ][ $inprofile ][ 'fps' ] = $profiles [ $y ][ 'VideoEncoderConfiguration' ][ 'RateControl' ][ 'FrameRateLimit' ];
$sources [ $i ][ $inprofile ][ 'bitrate' ] = $profiles [ $y ][ 'VideoEncoderConfiguration' ][ 'RateControl' ][ 'BitrateLimit' ];
// RateControl (and in theory Resolution) are optional in ONVIF
$vec = $profiles [ $y ][ 'VideoEncoderConfiguration' ];
$sources [ $i ][ $inprofile ][ 'encoding' ] = isset ( $vec [ 'Encoding' ]) ? $vec [ 'Encoding' ] : '' ;
$sources [ $i ][ $inprofile ][ 'width' ] = isset ( $vec [ 'Resolution' ][ 'Width' ]) ? $vec [ 'Resolution' ][ 'Width' ] : 0 ;
$sources [ $i ][ $inprofile ][ 'height' ] = isset ( $vec [ 'Resolution' ][ 'Height' ]) ? $vec [ 'Resolution' ][ 'Height' ] : 0 ;
$sources [ $i ][ $inprofile ][ 'fps' ] = isset ( $vec [ 'RateControl' ][ 'FrameRateLimit' ]) ? $vec [ 'RateControl' ][ 'FrameRateLimit' ] : 0 ;
$sources [ $i ][ $inprofile ][ 'bitrate' ] = isset ( $vec [ 'RateControl' ][ 'BitrateLimit' ]) ? $vec [ 'RateControl' ][ 'BitrateLimit' ] : 0 ;
}
if ( isset ( $profiles [ $y ][ 'PTZConfiguration' ])) {
$sources [ $i ][ $inprofile ][ 'ptz' ][ 'name' ] = $profiles [ $y ][ 'PTZConfiguration' ][ 'Name' ];
@ -685,26 +729,35 @@ class Ponvif {
}
}
// Not SOAP XML (empty, HTML error page ...): a Fault instead of a PHP Error / Exception
protected function _xml2array ( $response ) {
//$FD = fopen( "TEST.xml", "a+" );
//fprintf( $FD, $response );
//fclose( $FD );
$sxe = new SimpleXMLElement ( $response );
$dom_sxe = dom_import_simplexml ( $sxe );
$dom = new DOMDocument ( '1.0' );
$dom_sxe = $dom -> importNode ( $dom_sxe , true );
$dom_sxe = $dom -> appendChild ( $dom_sxe );
$element = $dom -> childNodes -> item ( 0 );
foreach ( $sxe -> getDocNamespaces () as $name => $uri ) {
$element -> removeAttributeNS ( $uri , $name );
try {
if ( ! is_string ( $response ) || trim ( $response ) == '' ) return array ( 'Fault' => 'empty reply' );
$prev = libxml_use_internal_errors ( true );
$sxe = new SimpleXMLElement ( $response );
$dom_sxe = dom_import_simplexml ( $sxe );
$dom = new DOMDocument ( '1.0' );
$dom_sxe = $dom -> importNode ( $dom_sxe , true );
$dom_sxe = $dom -> appendChild ( $dom_sxe );
$element = $dom -> childNodes -> item ( 0 );
foreach ( $sxe -> getDocNamespaces () as $name => $uri ) {
$element -> removeAttributeNS ( $uri , $name );
}
$xmldata = $dom -> saveXML ();
$b = strpos ( $xmldata , " <Envelope> " );
$e = strpos ( $xmldata , " </Envelope> " );
if ( $b === false || $e === false ) { libxml_use_internal_errors ( $prev ); return array ( 'Fault' => 'reply is not a SOAP envelope' ); }
$xmldata = substr ( $xmldata , $b , $e + strlen ( " </Envelope> " ) - $b );
$xml = simplexml_load_string ( $xmldata );
libxml_use_internal_errors ( $prev );
if ( $xml === false ) return array ( 'Fault' => 'reply is not valid XML' );
$data = json_decode ( json_encode (( array ) $xml ), 1 );
$data = array ( $xml -> getName () => $data );
return $data ;
} catch ( Throwable $e ) {
if ( isset ( $prev )) libxml_use_internal_errors ( $prev );
return array ( 'Fault' => 'reply is not XML: ' . $e -> getMessage ());
}
$xmldata = $dom -> saveXML ();
$xmldata = substr ( $xmldata , strpos ( $xmldata , " <Envelope> " ));
$xmldata = substr ( $xmldata , 0 , strpos ( $xmldata , " </Envelope> " ) + strlen ( " </Envelope> " ));
$xml = simplexml_load_string ( $xmldata );
$data = json_decode ( json_encode (( array ) $xml ), 1 );
$data = array ( $xml -> getName () => $data );
return $data ;
}
/*
@ -778,6 +831,10 @@ class Ponvif {
//echo "\n~~~~~~~~~~~~~~~~~~\n";
//var_dump( $result );
$this -> lastresponse = $this -> _xml2array ( $result );
if ( isset ( $this -> lastresponse [ 'Fault' ]) && is_string ( $this -> lastresponse [ 'Fault' ])) {
$code = curl_getinfo ( $soap_do , CURLINFO_HTTP_CODE );
$this -> lastresponse [ 'Fault' ] = 'HTTP ' . $code . ': ' . $this -> lastresponse [ 'Fault' ]; // e.g. "HTTP 401: reply is not a SOAP envelope"
}
}
return $this -> lastresponse ;
}