Пример #1
0
 public function testFile()
 {
     $path = __DIR__ . '/../resources/one/a.php';
     $file = new File($path);
     $newContent = time();
     $this->assertEquals($path, $file->getPath());
     $file->update($newContent);
     $this->assertEquals($newContent, $file->getContents());
     $file->append(' appended');
     $this->assertEquals($newContent . ' appended', $file->getContents());
     $this->assertTrue($file->exists());
     $nonExisting = new File(__DIR__ . '/file.txt');
     $this->assertFalse($nonExisting->exists());
     $file->update('seven b');
     $this->assertEquals(7, $file->getSize());
     $now = time();
     $file->copyTo(__DIR__ . '/../resources/newPlace.txt');
     $this->assertTrue(file_exists(__DIR__ . '/../resources/newPlace.txt'));
     $deleteThis = new File(__DIR__ . '/../resources/newPlace.txt');
     $this->assertEquals($now, $deleteThis->getCreatedTime());
     $deleteThis->moveTo('otherPlace');
     $this->assertFalse(file_exists(__DIR__ . '/../resources/newPlace.txt'));
     $this->assertTrue(file_exists(__DIR__ . '/../resources/otherPlace.txt'));
     $deleteThis->delete();
     $this->assertFalse(file_exists(__DIR__ . '/../resources/otherPlace.txt'));
     $this->assertInternalType('string', $file->getMimeType());
     $this->assertEquals('file', $file->getType());
     $this->assertInternalType('int', $file->getAccessTime());
     $this->assertInternalType('int', $file->getModifiedTime());
 }
Пример #2
0
 public function __construct(FileObject $file, $name = null)
 {
     if (($file->exists() and $contents = $file->getContents()) === false or empty($contents)) {
         throw new InvalidArgumentException('EMA-006: The file does not exists, not readable or empty.');
     }
     if ($name === null) {
         $name = pathinfo($file->getPath(), PATHINFO_BASENAME);
     }
     $this->file = $file;
     parent::__construct($name, $contents, $file->getMime());
 }
Пример #3
0
 /**
  * @param string $file
  * @param string $mime
  * @param array  $headers
  */
 public function __construct(\Fuel\FileSystem\File $file, array $headers = [])
 {
     // process the passed data
     if (!$file->exists()) {
         throw new NotFound();
     }
     if (!$file->isReadable()) {
         throw new Forbidden();
     }
     $this->setContentType($file->getMimeType());
     parent::__construct($file, 200, $headers);
 }