Bolt\Stack::add PHP Метод

add() публичный Метод

Add a file to the stack.
public add ( Bolt\Filesystem\Handler\FileInterface | string $filename, Bolt\Filesystem\Handler\FileInterface &$removed = null ) : Bolt\Filesystem\Handler\FileInterface
$filename Bolt\Filesystem\Handler\FileInterface | string The file to add.
$removed Bolt\Filesystem\Handler\FileInterface Returns the removed file, if one was removed.
Результат Bolt\Filesystem\Handler\FileInterface If filename cannot be matched to filesystem.
    public function add($filename, FileInterface &$removed = null)
    {
        $this->initialize();
        $file = $this->matcher->getFile($filename);
        if (!$this->isStackable($file)) {
            throw new FileNotStackableException($file);
        }
        array_unshift($this->files, $file);
        if (count($this) > static::MAX_ITEMS) {
            $removed = array_pop($this->files);
        }
        $this->persist();
        return $file;
    }

Usage Example

Пример #1
0
 public function testListFilter()
 {
     $app = $this->makeApp();
     $app['resources']->setPath('files', PHPUNIT_ROOT . '/resources/stack');
     $app->initialize();
     $users = $this->getMock('Bolt\\Users', array('getCurrentUser', 'saveUser'), array($app));
     $app['users'] = $users;
     $stack = new Stack($app);
     $stack->add('files/testing.md');
     $stack->add('files/testing.txt');
     $stack->add('files/test.jpg');
     $stack->add('files/test2.jpg');
     $items = $stack->listItems(100, 'image');
     $this->assertEquals(2, count($items));
     $items = $stack->listItems(100, 'document');
     $this->assertEquals(2, count($items));
 }
All Usage Examples Of Bolt\Stack::add