-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor options, add stream reading support
- Loading branch information
Showing
14 changed files
with
223 additions
and
79 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LeKoala\SpreadCompat\Common; | ||
|
||
use Exception; | ||
|
||
trait Configure | ||
{ | ||
public function configure(...$opts): void | ||
{ | ||
foreach ($opts as $k => $v) { | ||
// It's an Options class | ||
if ($v instanceof Options) { | ||
$this->configure(...get_object_vars($v)); | ||
return; | ||
} | ||
// If you passed the array directly instead of ...$opts | ||
if (is_numeric($k)) { | ||
throw new Exception("Invalid key"); | ||
} | ||
// Ignore invalid properties for this adapter | ||
if (!property_exists($this, $k)) { | ||
continue; | ||
} | ||
$this->$k = $v; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LeKoala\SpreadCompat\Common; | ||
|
||
class Options | ||
{ | ||
use Configure; | ||
|
||
// Common | ||
public bool $assoc = false; | ||
/** | ||
* @var string[] | ||
*/ | ||
public array $headers = []; | ||
|
||
// Csv only | ||
public string $separator = ","; | ||
public string $enclosure = "\""; | ||
public string $escape = "\\"; | ||
public string $eol = "\n"; | ||
public ?string $inputEncoding = null; | ||
public ?string $outputEncoding = null; | ||
public bool $bom = true; | ||
|
||
// Excel only | ||
public ?string $creator = null; | ||
public ?string $autofilter = null; | ||
public ?string $freezePane = null; | ||
|
||
public function __construct(...$opts) | ||
{ | ||
if (!empty($opts)) { | ||
$this->configure(...$opts); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.