Skip to content

Commit

Permalink
Update documentation landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jan 11, 2025
1 parent aca3101 commit 0ed5fa3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All Notable changes to `Csv` will be documented in this file

- `Comparison::CONTAINS` must check the value is a string before calling `str_compare` [#548](https://github.com/thephpleague/csv/pull/548) by [cage-is](https://github.com/cage-is)
- Fix testing to improve Debian integration [#549](https://github.com/thephpleague/csv/pull/549) by [David Prévot and tenzap](https://github.com/tenzap)
- `Bom::tryFromSequence` and `Bom::fromSequence` supports the `Reader` and `Writer` class.

### Removed

Expand Down
6 changes: 3 additions & 3 deletions docs/_layouts/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ <h3 class="font-black text-6xl md:text-8xl tracking-tighter">Highlights</h3>

<div class="gap-6 flex flex-col my-16">

<h4 class="font-bold text-2xl">Simple API</h4>
<h4 class="font-bold text-2xl">Simple and straightforward API</h4>

<div class="bg-gradient-to-r from-csv-base to-white h-px"></div>

<h4 class="font-bold text-xl">Read and Write to CSV documents in <br />a memory efficient and scalable way</h4>
<h4 class="font-bold text-xl">Read from and Write to CSV documents<br />in a memory efficient and scalable way</h4>

<div class="bg-gradient-to-r from-csv-base to-white h-px"></div>

<h4 class="font-bold text-xl">Flexible and powerful query features and object-mapping.</h4>
<h4 class="font-bold text-xl">Flexible and powerful query features <br />and array to object-mapping.</h4>

<div class="bg-gradient-to-r from-csv-base to-white h-px"></div>

Expand Down
10 changes: 6 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ $csv->setHeaderOffset(0);

//build a statement
$stmt = Statement::create()
->select('firstname', 'lastname', 'email')
->andWhere('firstname', 'starts with', 'A')
->orderByAsc('email')
->offset(10)
->limit(25);

Expand Down Expand Up @@ -124,14 +127,13 @@ PHP stream filters can directly be used to ease manipulating CSV document

```php
use League\Csv\Reader;
use League\Csv\Bom;

$csv = Reader::createFromPath('/path/to/your/csv/file.csv', 'r');
$csv->setHeaderOffset(0);

$input_bom = $csv->getInputBOM();

if ($input_bom === Reader::BOM_UTF16_LE || $input_bom === Reader::BOM_UTF16_BE) {
$csv->addStreamFilter('convert.iconv.UTF-16/UTF-8');
if (Bom::tryFromSequence($csv)?->isUtf16() ?? false) {
$csv->appendStreamFilterOnRead('convert.iconv.UTF-16/UTF-8');
}

foreach ($csv as $record) {
Expand Down
1 change: 1 addition & 0 deletions src/Bom.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static function tryFromSequence(mixed $sequence): ?self
$sequence instanceof SplFileObject,
$sequence instanceof Stream => self::getContents($sequence, 4, 0),
is_resource($sequence) => stream_get_contents($sequence, 4, 0),
$sequence instanceof AbstractCsv => $sequence->getInputBOM(),
$sequence instanceof Stringable,
is_string($sequence) => substr((string) $sequence, 0, 4),
default => $sequence,
Expand Down
6 changes: 5 additions & 1 deletion src/BomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
final class BomTest extends TestCase
{
#[DataProvider('BomSequencesProvider')]
public function test_bom_detection_from_sequence(string $sequence, ?Bom $expected): void
public function test_bom_detection_from_sequence(string|AbstractCsv $sequence, ?Bom $expected): void
{
self::assertSame($expected, Bom::tryFromSequence($sequence));
}
Expand Down Expand Up @@ -54,6 +54,10 @@ public static function BomSequencesProvider(): array
'sequence' => chr(255).chr(254).chr(0).chr(0),
'expected' => Bom::Utf32Le,
],
'UTF32 LE BOM sequence in Reader class' => [
'sequence' => Reader::createFromString(chr(255).chr(254).chr(0).chr(0)),
'expected' => Bom::Utf32Le,
],
];
}

Expand Down

0 comments on commit 0ed5fa3

Please sign in to comment.