Esempio n. 1
0
 public function setData($data)
 {
     if (!is_string($data) || strlen($data) !== self::PAGE_SIZE) {
         throw new InvalidArgumentException("Invalid page-data '{$data}' given!");
     }
     $rawName = substr($data, 0, 64);
     $rawType = substr($data, 64, 2);
     $rawCollate = substr($data, 66, 8);
     $rawUseChecksum = $data[74];
     $rawMaxRows = substr($data, 75, 8);
     $rawMinRows = substr($data, 83, 8);
     $rawPackKeys = $data[91];
     $rawDelayKeyWrite = $data[92];
     $rawRowFormat = substr($data, 93, 2);
     $rawInsertMethod = substr($data, 95, 2);
     $name = rtrim($rawName, "");
     $type = unpack("n", $rawType)[1];
     $collate = rtrim($rawCollate, "");
     $useChecksum = ord($rawUseChecksum) === 0x0 ? false : true;
     $rawMaxRows = ltrim($rawMaxRows, "");
     $rawMinRows = ltrim($rawMinRows, "");
     $packKeys = ord($rawPackKeys) === 0x0 ? false : true;
     $delayKeyWrite = ord($rawDelayKeyWrite) === 0x0 ? false : true;
     $rowFormat = unpack("n", $rawRowFormat)[1];
     $insertMethod = unpack("n", $rawInsertMethod)[1];
     // convert any binary to integer
     $maxRows = hexdec(implode("", array_map(function ($chr) {
         return dechex(ord($chr));
     }, str_split($rawMaxRows))));
     // convert any binary to integer
     $minRows = hexdec(implode("", array_map(function ($chr) {
         return dechex(ord($chr));
     }, str_split($rawMinRows))));
     $this->setName($name);
     $this->setEngine(Engine::getByValue($type));
     $this->setCollation($collate);
     $this->setUseChecksum($useChecksum);
     $this->setMaxRows($maxRows);
     $this->setMinRows($minRows);
     $this->setPackKeys($packKeys);
     $this->setDelayKeyWrite($delayKeyWrite);
     $this->setRowFormat(RowFormat::getByValue($rowFormat));
     $this->setInsertMethod(InsertMethod::getByValue($insertMethod));
 }