$clientOptions = array('stream_context' => stream_context_create(array('ssl' => array('verify_peer' => true, 'cafile' => __DIR__ . '/ais-ca-ssl.crt', 'peer_name' => 'ais.swisscom.com'))), 'local_cert' => $cert, 'passphrase' => $passphrase);
// create a re-usable array of filenames (in/out)
$files = array(array('in' => 'files/tektown/Laboratory-Report.pdf', 'out' => 'output/tektown-signed-on-demand.pdf'), array('in' => 'files/lenstown/Laboratory-Report.pdf', 'out' => 'output/lenstown-signed-on-demand.pdf'), array('in' => 'files/etown/Laboratory-Report.pdf', 'out' => 'output/etown-signed-on-demand.pdf'), array('in' => 'files/camtown/Laboratory-Report.pdf', 'out' => 'output/camtown-signed-on-demand.pdf'));
// create document instances by the filenames
$documents = array();
foreach ($files as $file) {
    $documents[] = SetaPDF_Core_Document::loadByFilename($file['in'], new SetaPDF_Core_Writer_File($file['out']));
}
// initiate a batch instance
$batch = new SetaPDF_Signer_SwisscomAIS_Batch($customerId, $clientOptions);
// let's add PADES revoke information to the resulting signatures
$batch->setAddRevokeInformation('PADES');
// the signatures should include a timestamp, too
$batch->setAddTimestamp(true);
// set on-demand options
$batch->setOnDemandOptions($signerDn);
if ($approvalNo !== '') {
    $batch->setOnDemandOptions($signerDn, $approvalNo, $approvalMsg, $approvalLang, $approvalSn);
}
try {
    // sign the documents and add the revoke information to the DSS of the documents
    $batch->sign($documents, true);
} catch (SetaPDF_Signer_SwisscomAIS_Exception $e) {
    echo 'Error in SwisscomAIS: ' . $e->getMessage() . ' with code ' . $e->getCode() . '<br />';
    /* Get the AIS Error details */
    echo "<pre>";
    var_dump($e->getResultMajor());
    var_dump($e->getResultMinor());
    echo "</pre>";
    die;
}