Skip to content

Commit 644aed4

Browse files
committed
File object (taken from #41)
1 parent ef71d49 commit 644aed4

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

src/File.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace React\Http;
4+
5+
use React\Stream\ReadableStreamInterface;
6+
7+
class File implements FileInterface
8+
{
9+
/**
10+
* @var string
11+
*/
12+
protected $filename;
13+
14+
/**
15+
* @var string
16+
*/
17+
protected $contentType;
18+
19+
/**
20+
* @var ReadableStreamInterface
21+
*/
22+
protected $stream;
23+
24+
/**
25+
* @param string $filename
26+
* @param string $contentType
27+
* @param ReadableStreamInterface $stream
28+
*/
29+
public function __construct($filename, $contentType, ReadableStreamInterface $stream)
30+
{
31+
$this->filename = $filename;
32+
$this->contentType = $contentType;
33+
$this->stream = $stream;
34+
}
35+
36+
/**
37+
* @return string
38+
*/
39+
public function getFilename()
40+
{
41+
return $this->filename;
42+
}
43+
44+
/**
45+
* @return string
46+
*/
47+
public function getContentType()
48+
{
49+
return $this->contentType;
50+
}
51+
52+
/**
53+
* @return ReadableStreamInterface
54+
*/
55+
public function getStream()
56+
{
57+
return $this->stream;
58+
}
59+
}

src/FileInterface.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace React\Http;
4+
5+
use React\Stream\ReadableStreamInterface;
6+
7+
interface FileInterface
8+
{
9+
/**
10+
* @return string
11+
*/
12+
public function getFilename();
13+
14+
/**
15+
* @return string
16+
*/
17+
public function getContentType();
18+
19+
/**
20+
* @return ReadableStreamInterface
21+
*/
22+
public function getStream();
23+
}

tests/FileTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace React\Tests\Http;
4+
5+
use React\Http\File;
6+
use React\Stream\ThroughStream;
7+
8+
class FileTest extends TestCase
9+
{
10+
public function testGetters()
11+
{
12+
$filename = 'bar.txt';
13+
$type = 'text/text';
14+
$stream = new ThroughStream();
15+
$file = new File($filename, $type, $stream);
16+
$this->assertEquals($filename, $file->getFilename());
17+
$this->assertEquals($type, $file->getContentType());
18+
$this->assertEquals($stream, $file->getStream());
19+
}
20+
}

0 commit comments

Comments
 (0)