function testIsValidExtension() { $this->assertTrue(DocumentationService::is_valid_extension('md')); $this->assertTrue(DocumentationService::is_valid_extension('markdown')); $this->assertTrue(DocumentationService::is_valid_extension('MD')); $this->assertTrue(DocumentationService::is_valid_extension('MARKDOWN')); $this->assertFalse(DocumentationService::is_valid_extension('.markd')); $this->assertFalse(DocumentationService::is_valid_extension('.exe')); // require an extension as internally we check for extension, not using // one could cause issues. $this->assertFalse(DocumentationService::is_valid_extension('')); }
/** * Return the raw markdown for a given documentation page. Will throw * an error if the path isn't a file. * * Will return empty if the type is not readable * * @return string */ function getMarkdown() { try { $path = $this->getPath(true); if ($path) { $ext = $this->getExtension(); if (DocumentationService::is_valid_extension($ext)) { return file_get_contents($path); } } } catch (InvalidArgumentException $e) { } return false; }