/** * attach listeners to the scanner * * @param \OC\Files\Mount\MountPoint $mount */ protected function attachListener($mount) { $scanner = $mount->getStorage()->getScanner(); $emitter = $this; $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'scanFile', function ($path) use($mount, $emitter) { $emitter->emit('\\OC\\Files\\Utils\\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); }); $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'scanFolder', function ($path) use($mount, $emitter) { $emitter->emit('\\OC\\Files\\Utils\\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); }); // propagate etag and mtimes when files are changed or removed $propagator = $this->propagator; $propagatorListener = function ($path) use($mount, $propagator) { $fullPath = Filesystem::normalizePath($mount->getMountPoint() . $path); $propagator->addChange($fullPath); }; $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'addToCache', $propagatorListener); $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'removeFromCache', $propagatorListener); }
public function testWrapperPriority() { $instance = new \OC\Files\Storage\StorageFactory(); $mount = new MountPoint('\\OC\\Files\\Storage\\Temporary', '/foo', [[]], $instance); $instance->addStorageWrapper('dummy1', function ($mountPoint, IStorage $storage) { return new DummyWrapper(['storage' => $storage, 'data' => 1]); }, 1); $instance->addStorageWrapper('dummy2', function ($mountPoint, IStorage $storage) { return new DummyWrapper(['storage' => $storage, 'data' => 100]); }, 100); $instance->addStorageWrapper('dummy3', function ($mountPoint, IStorage $storage) { return new DummyWrapper(['storage' => $storage, 'data' => 50]); }, 50); /** @var \Test\Files\Storage\DummyWrapper $wrapped */ $wrapped = $mount->getStorage(); $this->assertInstanceOf('\\Test\\Files\\Storage\\DummyWrapper', $wrapped); $this->assertEquals(1, $wrapped->data); // lowest priority is applied last, called first $this->assertEquals(50, $wrapped->getWrapperStorage()->data); $this->assertEquals(100, $wrapped->getWrapperStorage()->getWrapperStorage()->data); }
/** * attach listeners to the scanner * * @param \OC\Files\Mount\MountPoint $mount */ protected function attachListener($mount) { $scanner = $mount->getStorage()->getScanner(); $emitter = $this; $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'scanFile', function ($path) use($mount, $emitter) { $emitter->emit('\\OC\\Files\\Utils\\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); }); $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'scanFolder', function ($path) use($mount, $emitter) { $emitter->emit('\\OC\\Files\\Utils\\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); }); $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'postScanFile', function ($path) use($mount, $emitter) { $emitter->emit('\\OC\\Files\\Utils\\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); }); $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'postScanFolder', function ($path) use($mount, $emitter) { $emitter->emit('\\OC\\Files\\Utils\\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); }); }