class Import

Properties

protected string $path

Path to the directory with the import files.

Methods

__construct(string $path)

Create a new instance.

bool
filesMatch()

Check if this import matches to the given import files.

validateFiles()

Check if the files of this import are valid.

array
expectedFiles()

The files expected by this import.

array
files()

Get the basename of each file of this import.

validateFile(string $basename)

Validate a file of this import.

expectKeysInJson(string $file, array $expectation, bool $array = true)

Validates a JSON file to contain an array of objects, each of which has all the expected keys.

expectColumnsInCsv(string $file, array $expectation)

Validates a CSV file to contain the expected columns.

Collection
collectJson(string $file)

Read a JSON file containing an array and wrap it in a Laravel collection.

Details

at line 23
__construct(string $path)

Create a new instance.

Parameters

string $path

Path to the directory with the import files.

at line 33
bool filesMatch()

Check if this import matches to the given import files.

Return Value

bool

at line 48
validateFiles()

Check if the files of this import are valid.

Exceptions

Exception

at line 60
protected array expectedFiles()

The files expected by this import.

Return Value

array

at line 70
protected array files()

Get the basename of each file of this import.

Return Value

array

at line 82
protected validateFile(string $basename)

Validate a file of this import.

Parameters

string $basename

Basename of the file.

Exceptions

Exception

at line 96
protected expectKeysInJson(string $file, array $expectation, bool $array = true)

Validates a JSON file to contain an array of objects, each of which has all the expected keys.

Parameters

string $file

File name under $this->path

array $expectation

Expected keys.

bool $array

Specifies if the file to validate contains an array or not.

Exceptions

Exception

at line 122
protected expectColumnsInCsv(string $file, array $expectation)

Validates a CSV file to contain the expected columns.

Parameters

string $file

File name under $this->path

array $expectation

Expected columns.

Exceptions

Exception

at line 146
protected Collection collectJson(string $file)

Read a JSON file containing an array and wrap it in a Laravel collection.

Parameters

string $file

File name under $this->path

Return Value

Collection