/** * Get relevant protections * * @return Protection[] */ protected function _getProtection() { $protections = array(); $docroot = $this->getDocumentRoot(); foreach ($this->domain->getProtection() as $protection) { /** @var $protection Protection */ if ($protection->getFullPath() == $docroot) { continue; } $protections[] = $protection; } return $protections; }
/** * Test getDirectoryOptions(). */ public function testGetDirectoryOptions() { $domain = new Domain(); $po1 = new PathOption($domain); $po2 = new PathOption($domain); $po3 = new PathOption($domain); $protection1 = new Protection($domain); $protection2 = new Protection($domain); $protection3 = new Protection($domain); $domain->setPath('/var/www/domain.de')->setWebroot('htdocs/test'); $domain->getPathoption()->add($po1); $domain->getPathoption()->add($po2); $domain->getPathoption()->add($po3); $domain->getProtection()->add($protection1); $domain->getProtection()->add($protection2); $domain->getProtection()->add($protection3); $po1->setPath('htdocs/test/subfolder'); $po2->setPath('htdocs'); $po3->setPath('htdocs/test'); $protection1->setPath('htdocs'); $protection2->setPath('htdocs/test/subfolder2'); $protection3->setPath('htdocs/test'); $vhost = new Vhost(); $vhost->setDomain($domain); $options = $vhost->getDirectoryOptions(); $this->assertCount(2, $options); $testPo = false; $testProt = false; foreach ($options as $optset) { if ($optset['pathoption'] !== null) { $this->assertEquals($po1, $optset['pathoption']); $testPo = true; } if ($optset['protection'] !== null) { $this->assertEquals($protection2, $optset['protection']); $testProt = true; } } $this->assertTrue($testPo); $this->assertTrue($testProt); }
/** * Remove obsolete auth-user files. * * @param Domain $domain */ public function removeObsoleteAuthUserFiles(Domain $domain) { $finder = new Finder(); $fs = new Filesystem(); $files = array(); $ids = array(); foreach ($domain->getProtection() as $protection) { /** @var Protection $protection */ $ids[] = $protection->getId(); } $finder->in($domain->getPath() . '/conf')->name('authuser_*.passwd')->depth(0)->files(); foreach ($finder as $file) { /** @var SplFileInfo $file */ $id = $this->getIdFromFilename($file->getFilename()); if ($id === null) { continue; } if (!in_array($id, $ids)) { // Obsolete file. $files[] = $file->getPathname(); } } if (count($files) > 0) { $fs->remove($files); } }