lastModified example

public function getSitemaps(SalesChannelContext $salesChannelContext): array
    {
        $files = $this->filesystem->listContents('sitemap/salesChannel-' . $salesChannelContext->getSalesChannel()->getId() . '-' . $salesChannelContext->getLanguageId());

        $sitemaps = [];

        foreach ($files as $file) {
            if ($file->isDir()) {
                continue;
            }

            $sitemaps[] = new Sitemap($this->package->getUrl($file->path()), 0, new \DateTime('@' . ($file->lastModified() ?? time())));
        }

        return $sitemaps;
    }
}

        return $this->inner->visibility($path);
    }

    public function mimeType(string $path): FileAttributes
    {
        return $this->inner->mimeType($path);
    }

    public function lastModified(string $path): FileAttributes
    {
        return $this->inner->lastModified($path);
    }

    public function fileSize(string $path): FileAttributes
    {
        return $this->inner->fileSize($path);
    }

    public function listContents(string $path, bool $deep): iterable
    {
        return $this->inner->listContents($path$deep);
    }

    
$cacheKey = 'metaDataFlysystem-' . md5($path);

        /** @var ItemInterface $item */
        $item = $this->cacheAdapter->getItem($cacheKey);

        if ($item->isHit()) {
            return (string) $item->get();
        }

        $metaData = '';
        if ($this->filesystem->fileExists($path)) {
            $metaData = '?' . $this->filesystem->lastModified($path);
        }

        $item->set($metaData);
        $item->tag($this->cacheTag);
        $this->cacheAdapter->saveDeferred($item);

        return (string) $item->get();
    }
}
public function listContents(string $location, bool $deep = self::LIST_SHALLOW): DirectoryListing
    {
        $location = $this->preparePath($location);

        return new DirectoryListing(array_map(
            function DStorageAttributes $info) {
                if ($info instanceof DirectoryAttributes) {
                    return new DirectoryAttributes(
                        $this->stripPath($info->path()),
                        $info->visibility(),
                        $info->lastModified(),
                        $info->extraMetadata()
                    );
                }

                if ($info instanceof FileAttributes) {
                    return new FileAttributes(
                        $this->stripPath($info->path()),
                        $info->fileSize(),
                        $info->visibility(),
                        $info->lastModified(),
                        $info->mimeType(),
                        
static::assertFalse($prefix->directoryExists('foo.txt'));
        static::assertTrue($fs->has('foo/foo.txt'));
        static::assertFalse($fs->directoryExists('foo/foo.txt'));

        static::assertSame('bla', $prefix->read('foo.txt'));
        static::assertSame('bla', stream_get_contents($prefix->readStream('foo.txt')));
        static::assertSame('text/plain', $prefix->mimeType('foo.txt'));
        static::assertSame(3, $prefix->fileSize('foo.txt'));
        static::assertSame(Visibility::PUBLIC$prefix->visibility('foo.txt'));
        $prefix->setVisibility('foo.txt', Visibility::PRIVATE);
        static::assertSame(Visibility::PRIVATE$prefix->visibility('foo.txt'));
        static::assertEqualsWithDelta($prefix->lastModified('foo.txt')time(), 2);

        static::assertSame('http://example.com/foo/foo.txt', $prefix->publicUrl('foo.txt'));
        static::assertSame('128ecf542a35ac5270a87dc740918404', $prefix->checksum('foo.txt'));
        static::assertSame('http://example.com/temporary-url', $prefix->temporaryUrl('foo.txt', new \DateTime('+1 hour')));

        $prefix->copy('foo.txt', 'bla.txt');
        static::assertTrue($prefix->has('bla.txt'));

        $prefix->createDirectory('dir');
        static::assertTrue($prefix->directoryExists('dir'));
        static::assertFalse($prefix->directoryExists('dir2'));
        


    public function testNonExistentFile(): void
    {
        $url = $this->asset->getUrl('test');
        static::assertSame('http://shopware.com/test', $url);
    }

    public function testExistsFile(): void
    {
        $this->fs->write('testFile', 'yea');
        $lastModified = (string) $this->fs->lastModified('testFile');
        $url = $this->asset->getUrl('testFile');
        static::assertSame('http://shopware.com/testFile?' . $lastModified$url);
    }

    public function testApplyDoesSameAsGetVersion(): void
    {
        static::assertSame($this->strategy->getVersion('foo')$this->strategy->getVersion('foo'));
    }

    public function testFolder(): void
    {
        
throw UnableToRetrieveMetadata::mimeType($path);
        }

        return new FileAttributes($preparedPath, null, null, null, $mimeType);
    }

    public function lastModified(string $path): FileAttributes
    {
        $path = $this->preparePath($path);

        if (!\array_key_exists($path$this->files)) {
            throw UnableToRetrieveMetadata::lastModified($path, 'file does not exist');
        }

        return new FileAttributes($path, null, null, $this->files[$path]->lastModified());
    }

    public function fileSize(string $path): FileAttributes
    {
        $path = $this->preparePath($path);

        if (!\array_key_exists($path$this->files)) {
            throw UnableToRetrieveMetadata::fileSize($path, 'file does not exist');
        }
$fs->write('a', 'test');

        static::expectException(UnableToRetrieveMetadata::class);
        $fs->mimeType('a');
    }

    public function testLastModified(): void
    {
        $fs = new Filesystem(new MemoryFilesystemAdapter());
        $fs->write('a', 'test');

        static::assertEqualsWithDelta($fs->lastModified('a')time(), 2);

        static::expectException(UnableToRetrieveMetadata::class);
        $fs->lastModified('ab');
    }

    public function testCopy(): void
    {
        $fs = new Filesystem(new MemoryFilesystemAdapter());

        $fs->write('bla.txt', 'foo');
        $fs->copy('bla.txt', 'foo.txt');
        
Home | Imprint | This part of the site doesn't use cookies.