Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Output buffering during buildFrom* functions #21

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/lib/Herrera/Box/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,16 @@ public function buildFromDirectory($dir, $regex = null)
*/
public function buildFromIterator(Traversable $iterator, $base = null)
{
$this->phar->startBuffering();

if ($base) {
$base = Path::canonical($base . DIRECTORY_SEPARATOR);
}

foreach ($iterator as $key => $value) {
if (is_string($value)) {
if (false === is_string($key)) {
$this->phar->stopBuffering();
throw UnexpectedValueException::create(
'The key returned by the iterator (%s) is not a string.',
gettype($key)
Expand All @@ -180,6 +183,7 @@ public function buildFromIterator(Traversable $iterator, $base = null)
}
} elseif ($value instanceof SplFileInfo) {
if (null === $base) {
$this->phar->stopBuffering();
throw InvalidArgumentException::create(
'The $base argument is required for SplFileInfo values.'
);
Expand All @@ -189,6 +193,7 @@ public function buildFromIterator(Traversable $iterator, $base = null)
$real = $value->getRealPath();

if (0 !== strpos($real, $base)) {
$this->phar->stopBuffering();
throw UnexpectedValueException::create(
'The file "%s" is not in the base directory.',
$real
Expand All @@ -203,12 +208,14 @@ public function buildFromIterator(Traversable $iterator, $base = null)
$this->addFile($real, $local);
}
} else {
$this->phar->stopBuffering();
throw UnexpectedValueException::create(
'The iterator value "%s" was not expected.',
gettype($value)
);
}
}
$this->phar->stopBuffering();
}

/**
Expand Down