src/Decoder.php
private function decodeInteger()
    {
        $offsetOfE = strpos($this->source, "e", $this->offset);
        if (false === $offsetOfE) {
            throw new RuntimeException("Unterminated integer entity at offset $this->offset");
        }

        $currentOffset = $this->offset;
        if ("-" == $this->getChar($currentOffset)) {
            ++$currentOffset;
        }

        if ($offsetOfE === $currentOffset) {
            throw new RuntimeException("Empty integer entity at offset $this->offset");
        }

        while ($currentOffset < $offsetOfE) {
            if (!ctype_digit($this->getChar($currentOffset))) {
                throw new RuntimeException("Non-numeric character found in integer entity at offset $this->offset");
            }
            ++$currentOffset;
        }

        $value = substr($this->source, $this->offset, $offsetOfE - $this->offset);

        // One last check to make sure zero-padded integers don't slip by, as
        // they're not allowed per bencode specification.
        $absoluteValue = (string) abs($value);
        if (1 < strlen($absoluteValue) && "0" == $value[0]) {
            throw new RuntimeException("Illegal zero-padding found in integer entity at offset $this->offset");
        }

        $this->offset = $offsetOfE + 1;

        // The +0 auto-casts the chunk to either an integer or a float(in cases
        // where an integer would overrun the max limits of integer types)
        return $value + 0;
    }
private function decodeInteger()
    {
        $offsetOfE = strpos($this->source, "e", $this->offset);
        if (false === $offsetOfE) {
            throw new RuntimeException("Unterminated integer entity at offset $this->offset");
        }

        $currentOffset = $this->offset;
        if ("-" == $this->getChar($currentOffset)) {
            ++$currentOffset;
        }

        if ($offsetOfE === $currentOffset) {
            throw new RuntimeException("Empty integer entity at offset $this->offset");
        }

        while ($currentOffset < $offsetOfE) {
            if (!ctype_digit($this->getChar($currentOffset))) {
                throw new RuntimeException("Non-numeric character found in integer entity at offset $this->offset");
            }
            ++$currentOffset;
        }

        $value = substr($this->source, $this->offset, $offsetOfE - $this->offset);

        // One last check to make sure zero-padded integers don't slip by, as
        // they're not allowed per bencode specification.
        $absoluteValue = (string) abs($value);
        if (1 < strlen($absoluteValue) && "0" == $value[0]) {
            throw new RuntimeException("Illegal zero-padding found in integer entity at offset $this->offset");
        }

        $this->offset = $offsetOfE + 1;

        // The +0 auto-casts the chunk to either an integer or a float(in cases
        // where an integer would overrun the max limits of integer types)
        return $value + 0;
    }
private function decodeInteger ( ) { $ offsetOfE = strpos ( $ this -> source , "e" , $ this -> offset ) ; if ( false === $ offsetOfE ) { throw new RuntimeException ( "Unterminated integer entity at offset $this->offset" ) ; } $ currentOffset = $ this -> offset ; if ( "-" == $ this -> getChar ( $ currentOffset ) ) { ++ $ currentOffset ; } if ( $ offsetOfE === $ currentOffset ) { throw new RuntimeException ( "Empty integer entity at offset $this->offset" ) ; } while ( $ currentOffset < $ offsetOfE ) { if ( ! ctype_digit ( $ this -> getChar ( $ currentOffset ) ) ) { throw new RuntimeException ( "Non-numeric character found in integer entity at offset $this->offset" ) ; } ++ $ currentOffset ; } $ value = substr ( $ this -> source , $ this -> offset , $ offsetOfE - $ this -> offset ) ; // One last check to make sure zero-padded integers don't slip by, as // they're not allowed per bencode specification. $ absoluteValue = ( string ) abs ( $ value ) ; if ( 1 < strlen ( $ absoluteValue ) && "0" == $ value [ 0 ] ) { throw new RuntimeException ( "Illegal zero-padding found in integer entity at offset $this->offset" ) ; } $ this -> offset = $ offsetOfE + 1 ; // The +0 auto-casts the chunk to either an integer or a float(in cases // where an integer would overrun the max limits of integer types) return $ value + 0 ; }
Decode a bencode encoded integer

@return integer Returns the decoded integer.
@throws RuntimeException
Decode a bencode encoded integer