<commit_before><?php
/**
 * P8P Framework - https://github.com/hpolaert/p8p
 *
 * @link      https://github.com/hpolaert/p8p
 * @copyright Copyright (c) 2016 <NAME>
 * @license   https://github.com/hpolaert/p8p/LICENCE.md (MIT)
 */

namespace P8P\Http;

use Psr\Http\Message\StreamInterface;

/**
 * P8P - Basic implementation of PSR-7 Stream interface
 *
 * Describes a data stream.
 *
 * Typically, an instance will wrap a PHP stream; this interface provides
 * a wrapper around the most common operations, including serialization of
 * the entire stream to a string.
 */
class Stream implements StreamInterface
{
    /**
     * P8P - Basic implementation of PSR-7 Stream interface
     *
     * Reads all data from the stream into a string, from the beginning to end.
     *
     * This method MUST attempt to seek to the beginning of the stream before
     * reading data and read the stream until the end is reached.
     *
     * Warning: This could attempt to load a large amount of data into memory.
     *
     * This method MUST NOT raise an exception in order to conform with PHP's
     * string casting operations.
     *
     * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
     * @return string
     */
    public function __toString();

    /**
     * Closes the stream and any underlying resources.
     *
     * @return void
     */
    public function close();

    /**
     * Separates any underlying resources from the stream.
     *
     * After the stream has been detached, the stream is in an unusable state.
     *
     * @return resource|null Underlying PHP stream, if any
     */
    public function detach();

    /**
     * Get the size of the stream if known.
     *
     * @return int|null Returns the size in bytes if known, or null if unknown.
     */
    public function getSize();

    /**
     * Returns the current position of the file read/write pointer
     *
     * @return int Position of the file pointer
     * @throws \RuntimeException on error.
     */
    public function tell();

    /**
     * Returns true if the stream is at the end of the stream.
     *
     * @return bool
     */
    public function eof();

    /**
     * Returns whether or not the stream is seekable.
     *
     * @return bool
     */
    public function isSeekable();

    /**
     * Seek to a position in the stream.
     *
     * @see http://www.php.net/manual/en/function.fseek.php
     *<commit_msg>Stream Interface<commit_after><?php
/**
 * P8P Framework - https://github.com/hpolaert/p8p
 *
 * @link      https://github.com/hpolaert/p8p
 * @copyright Copyright (c) 2016 <NAME>
 * @license   https://github.com/hpolaert/p8p/LICENCE.md (MIT)
 */

namespace P8P\Http;

use Psr\Http\Message\StreamInterface;

/**
 * P8P - Basic implementation of PSR-7 Stream interface
 *
 * Describes a data stream.
 *
 * Typically, an instance will wrap a PHP stream; this interface provides
 * a wrapper around the most common operations, including serialization of
 * the entire stream to a string.
 */
class Stream implements StreamInterface
{
    
	/**
	 * @var resource	Stream resource
	 */
	protected $stream;
	
    /**
     * Constructor
     * 
     * Instantiate the stream object 
     * [Not part of PSR7 Standard]
     * 
     * @param resource $stream PHP Resource object
     * 
     * @return void
     */
    public function __construct($stream){
    	if($this->isValidResource($stream, __METHOD__)){
    		$this->stream = $stream;
    	}
    }
    
    /**
     * Is Stream Attached
     *
     * Check if the current stream is a valid resource
     * [Not part of PSR7 Standard]
     *
     * @return boolean
     */
    public function isStreamAttached(){
    	return is_resource($this->stream);
    }
    
    /**
     * Attach a stream to the current object
     *
     * Check if the current stream is a valid resource
     * [Not part of PSR7 Standard]
     * 
     * @param resource $stream PHP Resource object
     *
     * @return boolean
     */
    public function attachStream($newStream){
    	if($this->isValidResource($stream, __METHOD__)){
    		if($this->isStreamAttached){
    			$this->detach($stream);
    		}
    		$this->stream = $newStream;
    	} 
    }
    
    /**
     * Is Valid Resource
     *
     * Check if the provided object is a valid resource
     * [Not part of PSR7 Standard]
     *
     * @param resource $stream PHP Resource object
     * @param string $method 
     * 
     * @throws ContainerException
     * @return boolean
     */
    public function isValidResource($stream, $method){
    	if (is_resource($stream) === false) {
    		throw new InvalidArgumentException($method . ' argument must be a valid PHP resource');
    	}
    	return true;
    }
    
    /**
     * P8P - Basic implementation of PSR-7 Stream interface
     *
     * Reads all data from the stream into a string, from the beginning to end.
     *
     * This method MUST attempt to seek to the beginning of the stream before
     * reading data and read the stream until the end is reached.
     *
     * Warning: This could attempt to load a large amount of data into memory.
     *
     * This method MUST NOT raise an exception in order to conform with PHP's
     * string casting operations.
     *
     * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
     * @return string
     */
    public function __toString();

    /**
     * Closes the stream and any underlying resources.
     *
     * @return void
     */
    public function close(){
    	if ($this->isAttached() === true) {
    		fclose($this->stream);
    	}
    	$this->detach();
    }
    

    /**
     * Separates any underlying resources from the stream.
     *
     * After the stream has been detached, the stream is in an unusable state.
     *
     * @return resource|null Underlying PHP stream, if any
     */
    public function detach(){
    	
    }

    /**
     * Get the size of the stream if known.
     *
     * @return int|null Returns the size in bytes if known, or null if unknown.
     */
    public function getSize();

    /**
     * Returns the current position of the file read/write pointer
     *
     * @return int Position of the file pointer
     * @throws \RuntimeException on error.
     */
    public function tell();

    /**
     * Returns true if the stream is at the end of the stream.
     *
     * @return bool
     */
    public function eof(){
    	return $this->isStreamAttached() ? feof($this->stream) : true;
    }

    /**
     * Returns whether or not the stream is seekable.
     *
     * @return bool
     */
    public function isSeekable();

    /**
     * Seek to a position in the stream.
     *
     * @see http://www.php.net/manual/en/function.fseek.php
     *
{'fraction_non_alphanumeric': 0.09846471803956304, 'fraction_numerical': 0.0047239444936522, 'mean_word_length': 2.1897363465160073, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '777401', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1935, 'n_words': 690}