Example #1
0
 public function testSettersAndGetters()
 {
     $file = new File();
     $this->assertInstanceOf('MogileFS\\File', $file->setClass('dev'));
     $this->assertInstanceOf('MogileFS\\File', $file->setDomain('toast'));
     $this->assertInstanceOf('MogileFS\\File', $file->setFid(123));
     $this->assertInstanceOf('MogileFS\\File', $file->setFile($this->getTestFile()));
     $this->assertInstanceOf('MogileFS\\File', $file->setKey('key'));
     $this->assertInstanceOf('MogileFS\\File', $file->setMapper(new Mapper()));
     $this->assertInstanceOf('MogileFS\\File', $file->setPaths(array('http://mypath.com/123.fid')));
     $this->assertInstanceOf('MogileFS\\File', $file->setSize(321));
     $this->assertEquals('dev', $file->getClass());
     $this->assertEquals('toast', $file->getDomain());
     $this->assertEquals(123, $file->getFid());
     $this->assertEquals($this->getTestFile(), $file->getFile());
     $this->assertEquals('key', $file->getKey());
     $this->assertEquals(new Mapper(), $file->getMapper());
     $this->assertEquals(array('http://mypath.com/123.fid'), $file->getPaths());
     $this->assertEquals(321, $file->getSize());
 }
Example #2
0
 /**
  * 
  * Download file from MogileFS into a local temp file
  * @param MogileFS_File $file
  * @throws Exception
  */
 public function fetchFile(File $file)
 {
     if (!$file->isValid()) {
         throw new Exception(__METHOD__ . ' Cannot fetch file from invalid file model', Exception::INVALID_ARGUMENT);
     }
     $localFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $file->getKey();
     $fp = fopen($localFile, 'w');
     $url = $file->getPaths()[0];
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_FILE, $fp);
     curl_exec($ch);
     curl_close($ch);
     fclose($fp);
     $file->setFile($localFile);
     return $file;
 }