Simple script that retrieves file from a URL and imports data into database
- PHP 7.0.8
- Sqlite or mysql
Directory | Remarks |
---|---|
src/demo/DownloadCommand | Command class |
src/demo/CsvReader | Read from csv and migrate |
src/demo/Entity | Model class. |
src/demo/Repository | Repository Class. |
src/demo/Downloader | Downloader Class with source url and destination path. |
src/demo/Exception | Exception Handler. |
src/demo/Transformer | Data mapper. |
tests | Test cases. |
File | Remarks |
---|---|
public/index.php | Start application file |
public/dump.sql | Database script |
public/config.php | Database configuration |
composer.json | php package configuration |
.travis.yml | CI configuration file |
public/create-csv.php | Create require number of line in csv file, for testing |
Install dev dependencies
$ composer install
- Create database and table from script
public/dump.sql
- Database configuration
public/config.php
Script to run application
$ php public/index.php app:download-file http://localhost:3000/public/quick-orders.csv
script | Remarks |
---|---|
php | Execute |
public/index.php | Start application |
app:download-file | Command |
http://localhost:3000/public/quick-orders.csv | File url |
Downloading file
Source : http://localhost:3000/public/quick-orders.csv
Total Data import: 1000
$ ./vendor/bin/phpunit
├── README.MD
├── composer.json
├── composer.lock
├── phpunit.xml
├── public
│ ├── config.php
│ ├── dump.sql
│ ├── index.php
│ └── quick-orders.csv
├── src
│ └── App
│ └── Demo
│ ├── Command
│ │ └── DownloadFileCommand.php
│ ├── CsvReader
│ │ ├── Migration.php
│ │ └── Reader.php
│ ├── DbConnection.php
│ ├── Downloader
│ │ └── StreamDownloader.php
│ ├── Entity
│ │ ├── Model.php
│ │ ├── Order.php
│ │ └── Product.php
│ ├── Exception
│ │ ├── DownloaderException.php
│ │ └── MigrationException.php
│ ├── Repository
│ │ ├── OrderRepository.php
│ │ └── ProductRepository.php
│ └── Transformer
│ └── CsvTransformer.php
└── tests
└── App
└── Demo
├── Command
│ └── DownloadFileCommandTest.php
├── CsvReader
│ └── MigrationTest.php
├── Downloader
│ └── StreamDownloaderTest.php
├── Repository
│ ├── OrderRepositoryTest.php
│ └── ProductRepositoryTest.php
└── Transformer
└── CsvTransformerTest.php