-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from CPS-IT/feature/file-iterator
[!!!][FEATURE] Resolve dependency between iterator and transport
- Loading branch information
Showing
2 changed files
with
33 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,30 +21,44 @@ | |
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace CPSIT\Typo3Mailqueue\Mail\Iterator; | ||
namespace CPSIT\Typo3Mailqueue\Iterator; | ||
|
||
use CPSIT\Typo3Mailqueue\Mail; | ||
use FilterIterator; | ||
use Iterator; | ||
use SplFileInfo; | ||
use Traversable; | ||
|
||
/** | ||
* FileIterator | ||
* LimitedFileIterator | ||
* | ||
* @author Elias Häußler <[email protected]> | ||
* @license GPL-2.0-or-later | ||
* | ||
* @template-extends FilterIterator<int, SplFileInfo, Traversable<SplFileInfo>> | ||
* @extends FilterIterator<int, SplFileInfo, Traversable<SplFileInfo>> | ||
*/ | ||
final class FileIterator extends FilterIterator | ||
final class LimitedFileIterator extends FilterIterator | ||
{ | ||
/** | ||
* @param list<string> $acceptedSuffixes | ||
*/ | ||
public function __construct( | ||
Iterator $iterator, | ||
private readonly array $acceptedSuffixes, | ||
) { | ||
parent::__construct($iterator); | ||
} | ||
|
||
public function accept(): bool | ||
{ | ||
$file = $this->getInnerIterator()->current(); | ||
$path = $file->getRealPath(); | ||
|
||
return str_ends_with($path, Mail\Transport\QueueableFileTransport::FILE_SUFFIX_QUEUED) | ||
|| str_ends_with($path, Mail\Transport\QueueableFileTransport::FILE_SUFFIX_SENDING) | ||
; | ||
foreach ($this->acceptedSuffixes as $suffix) { | ||
if (str_ends_with($path, $suffix)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters