src/CFPropertyList/CFBinaryPropertyList.php
protected function uniqueAndCountValues($value)
    {
      // no uniquing for other types than CFString and CFData
        if ($value instanceof CFNumber) {
            $val = $value->getValue();
            if (intval($val) == $val && !is_float($val) && strpos($val, '.') === false) {
                $this->intSize += self::bytesInt($val);
            } else {
                $this->miscSize += 9; // 9 bytes (8 + marker byte) for real
            }
            $this->countObjects++;
            return;
        } elseif ($value instanceof CFDate) {
            $this->miscSize += 9; // since date in plist is real, we need 9 byte (8 + marker byte)
            $this->countObjects++;
            return;
        } elseif ($value instanceof CFBoolean) {
            $this->countObjects++;
            $this->miscSize += 1;
            return;
        } elseif ($value instanceof CFArray) {
            $cnt = 0;
            foreach ($value as $v) {
                ++$cnt;
                $this->uniqueAndCountValues($v);
                $this->objectRefs++; // each array member is a ref
            }

            $this->countObjects++;
            $this->intSize += self::bytesSizeInt($cnt);
            $this->miscSize++; // marker byte for array
            return;
        } elseif ($value instanceof CFDictionary) {
            $cnt = 0;
            foreach ($value as $k => $v) {
                ++$cnt;
                if (!isset($this->uniqueTable[$k])) {
                    $this->uniqueTable[$k] = 0;
                    $len = self::binaryStrlen($k);
                    $this->stringSize += $len + 1;
                    $this->intSize += self::bytesSizeInt(self::charsetStrlen($k, 'UTF-8'));
                }

                $this->objectRefs += 2; // both, key and value, are refs
                $this->uniqueTable[$k]++;
                $this->uniqueAndCountValues($v);
            }

            $this->countObjects++;
            $this->miscSize++; // marker byte for dict
            $this->intSize += self::bytesSizeInt($cnt);
            return;
        } elseif ($value instanceof CFData) {
            $val = $value->getValue();
            $len = strlen($val);
            $this->intSize += self::bytesSizeInt($len);
            $this->miscSize += $len + 1;
            $this->countObjects++;
            return;
        } else {
            $val = $value->getValue();
        }

        if (!isset($this->uniqueTable[$val])) {
            $this->uniqueTable[$val] = 0;
            $len = self::binaryStrlen($val);
            $this->stringSize += $len + 1;
            $this->intSize += self::bytesSizeInt(self::charsetStrlen($val, 'UTF-8'));
        }
        $this->uniqueTable[$val]++;
    }
protected function uniqueAndCountValues($value)
    {
      // no uniquing for other types than CFString and CFData
        if ($value instanceof CFNumber) {
            $val = $value->getValue();
            if (intval($val) == $val && !is_float($val) && strpos($val, '.') === false) {
                $this->intSize += self::bytesInt($val);
            } else {
                $this->miscSize += 9; // 9 bytes (8 + marker byte) for real
            }
            $this->countObjects++;
            return;
        } elseif ($value instanceof CFDate) {
            $this->miscSize += 9; // since date in plist is real, we need 9 byte (8 + marker byte)
            $this->countObjects++;
            return;
        } elseif ($value instanceof CFBoolean) {
            $this->countObjects++;
            $this->miscSize += 1;
            return;
        } elseif ($value instanceof CFArray) {
            $cnt = 0;
            foreach ($value as $v) {
                ++$cnt;
                $this->uniqueAndCountValues($v);
                $this->objectRefs++; // each array member is a ref
            }

            $this->countObjects++;
            $this->intSize += self::bytesSizeInt($cnt);
            $this->miscSize++; // marker byte for array
            return;
        } elseif ($value instanceof CFDictionary) {
            $cnt = 0;
            foreach ($value as $k => $v) {
                ++$cnt;
                if (!isset($this->uniqueTable[$k])) {
                    $this->uniqueTable[$k] = 0;
                    $len = self::binaryStrlen($k);
                    $this->stringSize += $len + 1;
                    $this->intSize += self::bytesSizeInt(self::charsetStrlen($k, 'UTF-8'));
                }

                $this->objectRefs += 2; // both, key and value, are refs
                $this->uniqueTable[$k]++;
                $this->uniqueAndCountValues($v);
            }

            $this->countObjects++;
            $this->miscSize++; // marker byte for dict
            $this->intSize += self::bytesSizeInt($cnt);
            return;
        } elseif ($value instanceof CFData) {
            $val = $value->getValue();
            $len = strlen($val);
            $this->intSize += self::bytesSizeInt($len);
            $this->miscSize += $len + 1;
            $this->countObjects++;
            return;
        } else {
            $val = $value->getValue();
        }

        if (!isset($this->uniqueTable[$val])) {
            $this->uniqueTable[$val] = 0;
            $len = self::binaryStrlen($val);
            $this->stringSize += $len + 1;
            $this->intSize += self::bytesSizeInt(self::charsetStrlen($val, 'UTF-8'));
        }
        $this->uniqueTable[$val]++;
    }
protected function uniqueAndCountValues ( $ value ) { // no uniquing for other types than CFString and CFData if ( $ value instanceof CFNumber ) { $ val = $ value -> getValue ( ) ; if ( intval ( $ val ) == $ val && ! is_float ( $ val ) && strpos ( $ val , '.' ) === false ) { $ this -> intSize += self :: bytesInt ( $ val ) ; } else { $ this -> miscSize += 9 ; // 9 bytes (8 + marker byte) for real } $ this -> countObjects ++ ; return ; } elseif ( $ value instanceof CFDate ) { $ this -> miscSize += 9 ; // since date in plist is real, we need 9 byte (8 + marker byte) $ this -> countObjects ++ ; return ; } elseif ( $ value instanceof CFBoolean ) { $ this -> countObjects ++ ; $ this -> miscSize += 1 ; return ; } elseif ( $ value instanceof CFArray ) { $ cnt = 0 ; foreach ( $ value as $ v ) { ++ $ cnt ; $ this -> uniqueAndCountValues ( $ v ) ; $ this -> objectRefs ++ ; // each array member is a ref } $ this -> countObjects ++ ; $ this -> intSize += self :: bytesSizeInt ( $ cnt ) ; $ this -> miscSize ++ ; // marker byte for array return ; } elseif ( $ value instanceof CFDictionary ) { $ cnt = 0 ; foreach ( $ value as $ k => $ v ) { ++ $ cnt ; if ( ! isset ( $ this -> uniqueTable [ $ k ] ) ) { $ this -> uniqueTable [ $ k ] = 0 ; $ len = self :: binaryStrlen ( $ k ) ; $ this -> stringSize += $ len + 1 ; $ this -> intSize += self :: bytesSizeInt ( self :: charsetStrlen ( $ k , 'UTF-8' ) ) ; } $ this -> objectRefs += 2 ; // both, key and value, are refs $ this -> uniqueTable [ $ k ] ++ ; $ this -> uniqueAndCountValues ( $ v ) ; } $ this -> countObjects ++ ; $ this -> miscSize ++ ; // marker byte for dict $ this -> intSize += self :: bytesSizeInt ( $ cnt ) ; return ; } elseif ( $ value instanceof CFData ) { $ val = $ value -> getValue ( ) ; $ len = strlen ( $ val ) ; $ this -> intSize += self :: bytesSizeInt ( $ len ) ; $ this -> miscSize += $ len + 1 ; $ this -> countObjects ++ ; return ; } else { $ val = $ value -> getValue ( ) ; } if ( ! isset ( $ this -> uniqueTable [ $ val ] ) ) { $ this -> uniqueTable [ $ val ] = 0 ; $ len = self :: binaryStrlen ( $ val ) ; $ this -> stringSize += $ len + 1 ; $ this -> intSize += self :: bytesSizeInt ( self :: charsetStrlen ( $ val , 'UTF-8' ) ) ; } $ this -> uniqueTable [ $ val ] ++ ; }
Count number of objects and create a unique table for strings
@param $value The value to count and unique
@return void
Count number of objects and create a unique table for strings