Bolt\Stack::getList PHP Method

getList() public method

Returns the list of files in the stack, filtered by type (if given).
public getList ( array $types = [] ) : Bolt\Filesystem\Handler\FileInterface[]
$types array Filter files by type. Valid types: "image", "document", "other"
return Bolt\Filesystem\Handler\FileInterface[]
    public function getList(array $types = [])
    {
        $this->initialize();
        if (empty($types)) {
            return $this->files;
        }
        $images = in_array('image', $types);
        $docs = in_array('document', $types);
        $other = in_array('other', $types);
        $files = array_filter($this->files, function (FileInterface $file) use($images, $docs, $other) {
            switch ($file->getType()) {
                case 'image':
                    return $images;
                case 'document':
                    return $docs;
                default:
                    return $other;
            }
        });
        $files = array_values($files);
        // normalize indexes
        return $files;
    }

Usage Example

Beispiel #1
0
 public function testAddNewFile()
 {
     $expectedList = ['files://h.txt', 'files://a.jpg', 'files://b.txt', 'files://c.txt', 'files://d.doc', 'files://e.mp3', 'theme://f.txt'];
     $this->users->expects($this->once())->method('saveUser')->with(['stack' => $expectedList]);
     $file = $this->stack->add('h.txt', $removed);
     $this->assertTrue($file instanceof FileInterface, 'File object should be returned from add method');
     $this->assertEquals('files://h.txt', $file->getFullPath(), 'File object should be returned from add method');
     $this->assertTrue($removed instanceof FileInterface, 'Add method should set the removed parameter to the file object removed');
     $this->assertEquals('theme://g.txt', $removed->getFullPath(), 'Removed file should be the last file on the stack before the new one was added');
     $this->assertFiles($this->stack->getList(), $expectedList, 'Adding new file should prepend it to the stack and remove the oldest file');
     $this->assertEquals($expectedList, $this->session->get('stack'), 'Adding a file to the stack should persist change to session');
 }