PHP code example of nikitasergeev / structure-generate

1. Go to this page and download the library: Download nikitasergeev/structure-generate 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/ */

    

nikitasergeev / structure-generate example snippets



$template = json_decode('
    {
  "settings": {
    "counts": {
      "products": 10000
    },
    "output": {
      "products": "/tmp/products.json"
    }
  },
  "keys": {
    "products": "guid",
    "categories": "guid"
  },
  "schema": {
    "categories": {
      "guid": "{uuid}",
      "name": "{word}"
    },
    "products": {
      "guid": "{uuid}",
      "category_guid": "{data.categories}",
      "sku": "{word}",
      "name": "{name}",
      "packing": "{word}",
      "link_image": "{randomElement([[\"http://nginx/uploads/image-1.jpg\",\"http://nginx/uploads/image-2.jpg\",\"http://nginx/uploads/image-3.jpg\"]])}",
      "count_packing": "{randomNumber([1])}",
      "unit": "{word}",
      "stock": "{randomNumber([1])}",
      "is_deleted": false
    }
  }
}', true);

$parserStructureJson = new \SchemaGenerate\StructureGenerate\Parsers\ParserStructureJson(Faker\Factory::create());
$outputFileJson = new \SchemaGenerate\StructureGenerate\Outputs\OutputFileJson();
$schemaJson = new \SchemaGenerate\StructureGenerate\Schemes\SchemaJson();
$schemaJson->setData($template);

$generator = new \SchemaGenerate\StructureGenerate\Generators\GeneratorService($parserStructureJson, $outputFileJson);
$result = $generator->process($schemaJson);