Skip to content

Commit

Permalink
File object (taken from #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Aug 30, 2016
1 parent ef71d49 commit 644aed4
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/File.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace React\Http;

use React\Stream\ReadableStreamInterface;

class File implements FileInterface
{
/**
* @var string
*/
protected $filename;

/**
* @var string
*/
protected $contentType;

/**
* @var ReadableStreamInterface
*/
protected $stream;

/**
* @param string $filename
* @param string $contentType
* @param ReadableStreamInterface $stream
*/
public function __construct($filename, $contentType, ReadableStreamInterface $stream)
{
$this->filename = $filename;
$this->contentType = $contentType;
$this->stream = $stream;
}

/**
* @return string
*/
public function getFilename()
{
return $this->filename;
}

/**
* @return string
*/
public function getContentType()
{
return $this->contentType;
}

/**
* @return ReadableStreamInterface
*/
public function getStream()
{
return $this->stream;
}
}
23 changes: 23 additions & 0 deletions src/FileInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace React\Http;

use React\Stream\ReadableStreamInterface;

interface FileInterface
{
/**
* @return string
*/
public function getFilename();

/**
* @return string
*/
public function getContentType();

/**
* @return ReadableStreamInterface
*/
public function getStream();
}
20 changes: 20 additions & 0 deletions tests/FileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace React\Tests\Http;

use React\Http\File;
use React\Stream\ThroughStream;

class FileTest extends TestCase
{
public function testGetters()
{
$filename = 'bar.txt';
$type = 'text/text';
$stream = new ThroughStream();
$file = new File($filename, $type, $stream);
$this->assertEquals($filename, $file->getFilename());
$this->assertEquals($type, $file->getContentType());
$this->assertEquals($stream, $file->getStream());
}
}

0 comments on commit 644aed4

Please sign in to comment.