/** * Download module. * * /download/:module */ public function learnmoduleAction() { $module = $this->params()->fromRoute('module', ''); $compress = $this->params()->fromRoute('compress', 'zip'); $response = $this->getResponse(); if (in_array($module, $this->modulesList)) { $currDateTime = date('Y-m-dHis'); $fileToArchive = $module . '.' . ($compress == 'zip' ? 'zip' : 'bz2'); $archive = $fileToArchive . '-' . $currDateTime; $filter = new Compress(['adapter' => $compress == 'zip' ? 'Zip' : 'Bz2', 'options' => ['archive' => './data/' . $archive]]); $compressed = $filter->filter('./module/' . $module); //setting response header.... $response->getHeaders()->addHeaderLine('Content-Disposition', 'attachment; filename="' . $fileToArchive . '"'); $response->getHeaders()->addHeaderLine('Content-Length', filesize($compressed)); // set response with get content of file $response->setContent(file_get_contents($compressed)); //remove file after no need @unlink('./data/' . $archive); return $response; } return new ViewModel(); }
/** * Setting invalid method * * @return void */ public function testInvalidMethod() { $filter = new CompressFilter(); $this->setExpectedException('\\Zend\\Filter\\Exception\\BadMethodCallException', 'Unknown method'); $filter->invalidMethod(); }
/** * Setting invalid method * * @return void */ public function testInvalidMethod() { $filter = new CompressFilter(); try { $filter->invalidMethod(); $this->fail('Exception expected'); } catch (\Zend\Filter\Exception $e) { $this->assertContains('Unknown method', $e->getMessage()); } }