alexdebril/feed-io

View on GitHub
src/FeedIo/Adapter/FileSystem/Client.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
<?php

declare(strict_types=1);

namespace FeedIo\Adapter\FileSystem;

use DateTime;
use FeedIo\Adapter\ClientInterface;
use FeedIo\Adapter\NotFoundException;
use FeedIo\Adapter\ResponseInterface;

/**
 * Filesystem client
 */
class Client implements ClientInterface
{
    /**
     * @param  string                            $path
     * @param  \DateTime                         $modifiedSince
     * @return \FeedIo\Adapter\ResponseInterface
     *@throws \FeedIo\Adapter\NotFoundException
     */
    public function getResponse(string $path, DateTime $modifiedSince = null): ResponseInterface
    {
        if (file_exists($path)) {
            return new Response(
                file_get_contents($path),
                new DateTime('@'.filemtime($path))
            );
        }

        throw new NotFoundException();
    }
}