| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* League.Csv (https://csv.thephpleague.com) |
| 5 |
* |
| 6 |
* (c) Ignace Nyamagana Butera <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
declare(strict_types=1); |
| 13 |
|
| 14 |
namespace League\Csv; |
| 15 |
|
| 16 |
/** |
| 17 |
* Thrown when a data is not added to the Csv Document. |
| 18 |
*/ |
| 19 |
class CannotInsertRecord extends Exception |
| 20 |
{ |
| 21 |
/** The record submitted for insertion. */ |
| 22 |
protected array $record; |
| 23 |
/** Validator which did not validated the data. */ |
| 24 |
protected string $name = ''; |
| 25 |
|
| 26 |
/** |
| 27 |
* Create an Exception from a record insertion into a stream. |
| 28 |
*/ |
| 29 |
public static function triggerOnInsertion(array $record): self |
| 30 |
{ |
| 31 |
$exception = new self('Unable to write record to the CSV document'); |
| 32 |
$exception->record = $record; |
| 33 |
|
| 34 |
return $exception; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Create an Exception from a Record Validation. |
| 39 |
*/ |
| 40 |
public static function triggerOnValidation(string $name, array $record): self |
| 41 |
{ |
| 42 |
$exception = new self('Record validation failed'); |
| 43 |
$exception->name = $name; |
| 44 |
$exception->record = $record; |
| 45 |
|
| 46 |
return $exception; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* return the validator name. |
| 51 |
* |
| 52 |
*/ |
| 53 |
public function getName(): string |
| 54 |
{ |
| 55 |
return $this->name; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* return the invalid data submitted. |
| 60 |
* |
| 61 |
*/ |
| 62 |
public function getRecord(): array |
| 63 |
{ |
| 64 |
return $this->record; |
| 65 |
} |
| 66 |
} |
| 67 |
|