browser_id=$myIpBrowser->id; $this->browser_dir = $myIpBrowser->getDir(); $this->browser_file = $myIpBrowser->getFile(); parent::__construct( $myData ); if ( ! is_file( $this->getFile() ) ) { while ( is_dir( $this->getDir() ) ) $this->dirId++; mkdir( $this->getDir() ); file_put_contents( $this->getFile() ,serialize( $this ) ); } } public function getBrowser() : Browser { return unserialize( file_get_contents( $this->browser_file ) ); } public function writeXml( $xml ,$child ) { $xmlMyDevice = $xml->createElement( "device" ); $xmlMyDevice->setAttribute("id", $this->id ); $xmlMyDevice->appendChild( $xml->createElement( "id", $this->id ) ); $brDirLength=strlen( $this->browser_dir ); $lastSlash = strrpos( $this->browser_dir ,"/" ); $browser_dirid=substr( $this->browser_dir ,strpos( $this->browser_dir ,"-",$lastSlash )+1 ); $xmlMyDevice->appendChild( $xml->createElement( "browser_dirid" ,$browser_dirid ) ); $xmlMyDevice->setAttribute("browser_dirid" ,$browser_dirid ); $secondLastSlash = strrpos( $this->browser_dir ,"/", $lastSlash - $brDirLength - 1 ); $ip_dirid=substr( $this->browser_dir ,$secondLastSlash + 4, $lastSlash-$secondLastSlash-4 ); $xmlMyDevice->appendChild( $xml->createElement( "ip_dirid" ,$ip_dirid ) ); $xmlMyDevice->setAttribute("ip_dirid" ,$ip_dirid ); $xmlMyDevice->setAttribute("dev_dirid" ,$this->dirId ); foreach( $this->data as $key => $data ) $xmlMyDevice->appendChild( $xml->createElement( $key, $data ) ); $child->appendChild( $xmlMyDevice ); return $xmlMyDevice; } // /darkauth\db\auth\Device::listToXml( $xml ,$child ) public static function listToXml( $xml ,$child ) { $xmlDevices = $xml->createElement( "devices" ); $child->appendChild( $xmlDevices ); foreach( scandir( \darkauth\db\auth\Ip::$ipsDir ) as $anValue ) if ( $anValue=="." || $anValue==".." ) continue; elseif ( is_dir( ( $anIpDir = \darkauth\db\auth\Ip::$ipsDir."/$anValue" ) ) ) foreach( scandir( $anIpDir ) as $anOtherValue ) if ( $anOtherValue=="." || $anOtherValue==".." ) continue; elseif ( is_dir( ( $anBrowserDir = "{$anIpDir}/{$anOtherValue}" ) ) ) foreach( scandir( $anBrowserDir ) as $anLastOtherValue ) if ( $anLastOtherValue=="." || $anLastOtherValue==".." ) continue; elseif ( is_file( ( $serializedFile = "{$anBrowserDir}/{$anLastOtherValue}" ) ) ) { //echo "load:$serializedFile".\PHP_EOL; \StaticRootNameSpace::unserializeMyObj( file_get_contents( $serializedFile ),$xml ,$xmlDevices ); } return $xmlDevices; } public function getDir() { return $this->browser_dir."/device-".$this->dirId; } public function getFile() { return $this->browser_dir."/".$this->id.".dbphp"; } // \darkauth\db\Device::fromApache2( $_SERVER ); public static function fromApache2( IpBrowser $myIpBrowser ,$myServer ) : ?Device { return new Device( $myIpBrowser ,array ( "accept" => $myServer['HTTP_ACCEPT'] ) ); } } ?>