Exemplo n.º 1
0
 * 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);
/**
 * Attempt to send the file. This is wrapped in a try/catch as it can throw an
 * Dfp_Datafeed_Transfer_Adapter_Exception exception. If we were in a loop of
 * files, we would want this to continue if a file transfer failed.
 */
try {
    $transfer->sendFile($tmpfname);
} catch (Dfp_Datafeed_Transfer_Adapter_Exception $e) {
    echo 'Dfp_Datafeed_Transfer_Adapter_Exception Occurred with Message: ' . $e->getMessage() . PHP_EOL;
}
/**
 * All errors are saved to an array which is accessable via the getErrors() method as shown below.
 * Even when an exception is thrown, the error is recorded. This enables you to catch the exceptions
 * and continue, then grab the errors to evaluate later.
 */
if ($transfer->hasErrors()) {
    echo 'Errors: ' . print_r($transfer->getErrors(), true) . PHP_EOL;
}
echo 'End' . PHP_EOL;
/**
 * End: Example ---------------------
 */
Exemplo n.º 2
0
 public function testHasErrors()
 {
     $sut = new Dfp_Datafeed_Transfer();
     $this->assertFalse($sut->hasErrors());
     $mockAdapter = $this->getMock('Dfp_Datafeed_Transfer_Adapter_Interface');
     $mockAdapter->expects($this->once())->method('hasErrors')->will($this->returnValue(true));
     $sut->setAdapter($mockAdapter);
     $this->assertEquals(true, $sut->hasErrors());
 }