Example #1
0
echo 'Temporary File Path: ' . $tempPath . PHP_EOL;
$tmpfpath = tempnam($tempPath, "dfp");
$tmpfname = trim(str_replace($tempPath, '', $tmpfpath), DIRECTORY_SEPARATOR);
echo 'File name: ' . $tmpfname . PHP_EOL;
echo 'File path: ' . $tmpfpath . PHP_EOL;
$fp = fopen($tmpfpath, "w");
fwrite($fp, "This is some demo text.");
fclose($fp);
/**
 * End: Make a temporary file and write some data ---------------------
 */
/**
 * Start: Example ---------------------
 */
$transfer = new Dfp_Datafeed_Transfer();
$adapter = new Dfp_Datafeed_Transfer_Adapter_Ftp();
/**
 * Options can either be set using the key in this array or using setters.
 */
$adapter->setOptions(array('username' => '<your-ftp-username>', 'password' => '<your-ftp-password>', 'host' => '<your-ftp-host>', 'timeout' => 120, 'basePath' => $tempPath, 'passive' => true));
/**
 * Alternatively, all options can be set using setters. For example:
 *
 * @example $adapter->setBasePath($tempPath);
 * @example $adapter->setPassive(true);
 */
/**
 * Add the FTP adapter to the transfer component
 */
$transfer->setAdapter($adapter);
/**
Example #2
0
 /**
  * @dataProvider setOptionsProvider
  */
 public function testSetOptions($var, $valid, $invalid, $message, $method)
 {
     $options[$var] = $invalid;
     $sut = new Dfp_Datafeed_Transfer_Adapter_Ftp();
     $passed = false;
     try {
         $sut->setOptions($options);
     } catch (Dfp_Datafeed_Transfer_Exception $e) {
         if ($e->getMessage = $message) {
             $passed = True;
         }
     }
     $this->assertTrue($passed, 'Exception not thrown');
     $options[$var] = $valid;
     $sut->setOptions($options);
     $this->assertEquals($valid, $sut->{'get' . $method}());
 }