コード例 #1
0
ファイル: FileBagTest.php プロジェクト: JanHuang/http
 public function testFileBag()
 {
     $fileBag = new FileBag(['file' => ['name' => 'test.html', 'type' => 'text/html', 'tmp_name' => '/tmp/b', 'error' => UPLOAD_ERR_OK, 'size' => 123]]);
     $files = $fileBag->all();
     $this->assertEquals(['file' => new UploadedFile('test.html', 'text/html', '/tmp/b', 0, 123)], $files);
     $fileBag = new FileBag(['file' => ['name' => 'test.html', 'type' => 'text/html', 'tmp_name' => '/tmp/a', 'error' => UPLOAD_ERR_OK, 'size' => 123], 'name' => ['name' => 'test.html', 'type' => 'text/html', 'tmp_name' => '/tmp/b', 'error' => UPLOAD_ERR_OK, 'size' => 123]]);
     $this->assertEquals(['file' => new UploadedFile('test.html', 'text/html', '/tmp/a', 0, 123), 'name' => new UploadedFile('test.html', 'text/html', '/tmp/b', 0, 123)], $fileBag->all());
     $fileBag = new FileBag(['files' => ['name' => ['test.html', 'test2.html'], 'type' => ['text/html', 'text/html'], 'tmp_name' => ['/tmp/a', '/tmp/b'], 'error' => [UPLOAD_ERR_OK, UPLOAD_ERR_OK], 'size' => [123, 123]]]);
     $this->assertEquals(['files' => [new UploadedFile('test.html', 'text/html', '/tmp/a', 0, 123), new UploadedFile('test2.html', 'text/html', '/tmp/b', 0, 123)]], $fileBag->all());
     $fileBag = new FileBag(['files' => ['test' => ['test2' => ['name' => ['test.html', 'test2.html'], 'type' => ['text/html', 'text/html'], 'tmp_name' => ['/tmp/a', '/tmp/b'], 'error' => [UPLOAD_ERR_OK, UPLOAD_ERR_OK], 'size' => [123, 123]]]]]);
     $this->assertEquals($fileBag->all(), ['files' => ['test' => ['test2' => [new UploadedFile('test.html', 'text/html', '/tmp/a', 0, 123), new UploadedFile('test2.html', 'text/html', '/tmp/b', 0, 123)]]]]);
     $fileBag = new FileBag(['files' => ['test' => ['name' => ['test.html', 'test2.html'], 'type' => ['text/html', 'text/html'], 'tmp_name' => ['/tmp/a', '/tmp/b'], 'error' => [UPLOAD_ERR_OK, UPLOAD_ERR_OK], 'size' => [123, 123]]]]);
     $this->assertEquals($fileBag->all(), ['files' => ['test' => [new UploadedFile('test.html', 'text/html', '/tmp/a', 0, 123), new UploadedFile('test2.html', 'text/html', '/tmp/b', 0, 123)]]]);
 }
コード例 #2
0
ファイル: ServerRequest.php プロジェクト: JanHuang/http
 /**
  * Retrieve normalized file upload data.
  *
  * This method returns upload metadata in a normalized tree, with each leaf
  * an instance of Psr\Http\Message\UploadedFileInterface.
  *
  * These values MAY be prepared from $_FILES or the message body during
  * instantiation, or MAY be injected via withUploadedFiles().
  *
  * @return array An array tree of UploadedFileInterface instances; an empty
  *     array MUST be returned if no data is present.
  */
 public function getUploadedFiles()
 {
     return $this->file->all();
 }