PHP code example of kematjaya / import-bundle
1. Go to this page and download the library: Download kematjaya/import-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kematjaya / import-bundle example snippets
// config/bundles.php
....
Kematjaya\ImportBundle\ImportBundle::class => ['all' => true]
....
// src/DataTransformer/PostDataTransformer
...
use App\Entity\Post;
use Kematjaya\ImportBundle\DataTransformer\AbstractDataTransformer;
...
class PostDataTrasnformer extends AbstractDataTransformer
{
public function fromArray(array $data)
{
$datas = $this->checkConstraints($data);
$entity = (new Post())
->setId($datas['id'])
->setUserId($datas['userId'])
->setTitle($datas['title'])
->setBody($datas['body']);
return $entity;
}
protected function getColumns(): array
{
return [
[
self::KEY_FIELD => 'id', // key in TargetObject
self::KEY_INDEX => 0, // key in array source
self::KEY_CONSTRAINT => [
self::CONSTRAINT_REQUIRED => true // for