Skip to content

Commit

Permalink
Merge pull request #218 from alexdebril/issue/214
Browse files Browse the repository at this point in the history
DateBuilder provided through dependency injection
  • Loading branch information
alexdebril authored Apr 19, 2019
2 parents d1f9d28 + fd8a59d commit e805f34
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/FeedIo/FeedIo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use FeedIo\Reader\FixerSet;
use FeedIo\Reader\FixerAbstract;
use FeedIo\Rule\DateTimeBuilder;
use FeedIo\Rule\DateTimeBuilderInterface;
use FeedIo\Adapter\ClientInterface;
use FeedIo\Standard\Loader;
use FeedIo\Async\Reader as AsyncReader;
Expand Down Expand Up @@ -109,11 +110,11 @@ class FeedIo
* @param \FeedIo\Adapter\ClientInterface $client
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(ClientInterface $client, LoggerInterface $logger)
public function __construct(ClientInterface $client, LoggerInterface $logger, DateTimeBuilderInterface $dateTimeBuilder = null)
{
$this->client = $client;
$this->logger = $logger;
$this->dateTimeBuilder = new DateTimeBuilder($logger);
$this->dateTimeBuilder = $dateTimeBuilder ?? new DateTimeBuilder($logger);
$this->setReader(new Reader($client, $logger));
$this->loadCommonStandards();
$this->loadFixerSet();
Expand Down
7 changes: 3 additions & 4 deletions src/FeedIo/Rule/DateTimeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

class DateTimeBuilder
class DateTimeBuilder implements DateTimeBuilderInterface
{
/**
* Supported date formats
Expand Down Expand Up @@ -72,7 +72,7 @@ public function __construct(LoggerInterface $logger = null)
* @param $dateFormat
* @return DateTimeBuilder
*/
public function addDateFormat(string $dateFormat) : DateTimeBuilder
public function addDateFormat(string $dateFormat) : DateTimeBuilderInterface
{
$this->dateFormats[] = $dateFormat;

Expand All @@ -83,7 +83,7 @@ public function addDateFormat(string $dateFormat) : DateTimeBuilder
* @param array $dateFormats
* @return $this
*/
public function setDateFormats(array $dateFormats) : DateTimeBuilder
public function setDateFormats(array $dateFormats) : DateTimeBuilderInterface
{
$this->dateFormats = $dateFormats;

Expand Down Expand Up @@ -214,7 +214,6 @@ public function setTimezone(\DateTimeZone $timezone) : void
$this->setServerTimezone($timezone);
}


/**
* @param $format
* @param $string
Expand Down
64 changes: 64 additions & 0 deletions src/FeedIo/Rule/DateTimeBuilderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php declare(strict_types=1);
/*
* This file is part of the feed-io package.
*
* (c) Alexandre Debril <alex.debril@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FeedIo\Rule;

interface DateTimeBuilderInterface
{

/**
* @param $dateFormat
* @return DateTimeBuilderInterface
*/
public function addDateFormat(string $dateFormat) : DateTimeBuilderInterface;

/**
* @param array $dateFormats
* @return DateTimeBuilderInterface
*/
public function setDateFormats(array $dateFormats) : DateTimeBuilderInterface;

/**
* @return string
*/
public function getLastGuessedFormat() : string;

/**
* Tries to guess the date's format from the list
* @param string $date
* @return string|null date Format
*/
public function guessDateFormat(string $date) : ? string;

/**
* Creates a DateTime instance for the given string. Default format is RFC2822
* @param string $string
* @return \DateTime
*/
public function convertToDateTime(string $string) : \DateTime;

/**
* @return \DateTimeZone
*/
public function getFeedTimezone() : ? \DateTimeZone;

/**
* Specifies the feed's timezone. Do this it the timezone is missing
*
* @param \DateTimeZone $timezone
*/
public function setFeedTimezone(\DateTimeZone $timezone) : void;

/**
* Resets feedTimezone to null.
*/
public function resetFeedTimezone() : void;
}

0 comments on commit e805f34

Please sign in to comment.