/** * Override offsetSet to force the use of the relative filename. * * @param void $index * @param TableOfContents\File $newval * * @throws \InvalidArgumentException if something other than a file is provided. * * @return void */ public function offsetSet($index, $newval) { if (!$newval instanceof TableOfContents\File) { throw new \InvalidArgumentException('A table of contents may only be filled with File objects'); } $basename = basename($newval->getFilename()); if (strpos($basename, '.') !== false) { $basename = substr($basename, 0, strpos($basename, '.')); } if (strtolower($basename) === 'index') { $this->modules[] = $newval; } parent::offsetSet($newval->getFilename(), $newval); }
public function testRecognizesModule() { $file = new TableOfContents\File(); $file->setFilename('test'); $file2 = new TableOfContents\File(); $file2->setFilename('test2'); $file3 = new TableOfContents\File(); $file3->setFilename('index'); $file4 = new TableOfContents\File(); $file4->setFilename('INDEX'); $file5 = new TableOfContents\File(); $file5->setFilename('test3'); $this->object[] = $file; $this->object[] = $file2; $this->object[] = $file3; $this->object[] = $file4; $this->assertCount(2, $this->object->getModules()); $this->assertSame(array($file3, $file4), $this->object->getModules()); }