Bolt\Stack::contains PHP Method

contains() public method

Check if a given file is present on the stack.
public contains ( Bolt\Filesystem\Handler\FileInterface | string $filename ) : boolean
$filename Bolt\Filesystem\Handler\FileInterface | string
return boolean
    public function contains($filename)
    {
        $this->initialize();
        try {
            $file = $this->matcher->getFile($filename);
        } catch (FileNotFoundException $e) {
            return false;
        }
        foreach ($this->files as $item) {
            if ($item->getFullPath() === $file->getFullPath()) {
                return true;
            }
        }
        return false;
    }

Usage Example

Beispiel #1
0
 public function testContainsAndInitializeFromSession()
 {
     $this->users->expects($this->never())->method('getCurrentUser');
     $this->assertTrue($this->stack->contains('a.jpg'), 'Stack::contains should match file paths without mount points');
     $this->assertTrue($this->stack->contains('g.txt'), 'Stack::contains should match file paths without mount points');
     $this->assertTrue($this->stack->contains('files://a.jpg'), 'Stack::contains should match file paths with mount points');
     $this->assertTrue($this->stack->contains('files://c.txt'), 'Stack should initialize file paths with mount points');
     $file = $this->filesystem->getFile('files://a.jpg');
     $this->assertTrue($this->stack->contains($file), 'Stack::contains should match file objects');
     $this->assertTrue($this->stack->contains('files/a.jpg'), 'Stack should strip "files/" from start of path');
     $this->assertFalse($this->stack->contains('does_not_exist.txt'), 'Stack should not contain nonexistent files');
     $this->assertFalse($this->stack->contains('h.txt'), 'Stack should trim list to max items on initialize');
 }