Skip to content

Commit

Permalink
all
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan.deng committed Aug 12, 2019
1 parent 6391c58 commit 84b7be9
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"array to json",
"array to model",
"json to class",
"dto generator
"dto generator"
],
"require": {
"illuminate/support": "~5",
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Install the package in development dependencies:
Via Composer

``` bash
composer require --dev timehunter/laravel-json-to-class-generator "~1.0"
composer require --dev timehunter/laravel-json-to-class-generator "~2.0"
```

## Installation
Expand All @@ -28,7 +28,7 @@ php artisan vendor:publish --provider="TimeHunter\LaravelJsonToClassGenerator\La
2. Add your array schema in config
3. Run artisan command:
````bash
php artisan make:jsontoclass
php artisan make:dto
````
4. Check your files under your specified file location

Expand Down
11 changes: 5 additions & 6 deletions src/Commands/JsonToClassGeneratorCommand.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

namespace TimeHunter\LaravelJsonToClassGenerator\Commands;
namespace TimeHunter\LaravelDTOGenerator\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use TimeHunter\LaravelJsonToClassGenerator\JsonGeneratorFactory;
use TimeHunter\LaravelJsonToClassGenerator\Services\JsonToClassGenerator;
use TimeHunter\LaravelDTOGenerator\DTOGeneratorFactory;

class JsonToClassGeneratorCommand extends Command
{
Expand All @@ -14,14 +13,14 @@ class JsonToClassGeneratorCommand extends Command
*
* @var string
*/
protected $signature = 'make:jsontoclass';
protected $signature = 'make:dto';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate classes based on JSON';
protected $description = 'Generate DTO based on Array schema';

/**
* Create a new command instance.
Expand All @@ -41,7 +40,7 @@ public function __construct()
public function handle()
{
try {
JsonGeneratorFactory::generate(config('jsontoclassgenerator.driver'));
DTOGeneratorFactory::generate(config('dto-generator.driver'));
$this->info('Classes generated. Please check them.');
} catch (\Exception $e) {
Log::error($e);
Expand Down
4 changes: 2 additions & 2 deletions src/JsonGeneratorFactory.php → src/DTOGeneratorFactory.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace TimeHunter\LaravelJsonToClassGenerator;
namespace TimeHunter\LaravelDTOGenerator;

use TimeHunter\LaravelJsonToClassGenerator\Services\ArrayToClassGenerator;

use Exception;
use TimeHunter\LaravelJsonToClassGenerator\Services\JsonToClassGenerator;

class JsonGeneratorFactory
class DTOGeneratorFactory
{

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace TimeHunter\LaravelJsonToClassGenerator;
namespace TimeHunter\LaravelDTOGenerator;


use Illuminate\Support\ServiceProvider;
use TimeHunter\LaravelJsonToClassGenerator\Commands\JsonToClassGeneratorCommand;
use TimeHunter\LaravelDTOGenerator\Commands\JsonToClassGeneratorCommand;

class LaravelJsonToClassGeneratorServiceProvider extends ServiceProvider
class LaravelDTOGeneratorServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
Expand Down Expand Up @@ -41,8 +41,8 @@ protected function bootForConsole()
{
// Publishing the configuration file.
$this->publishes([
__DIR__.'/../config/jsontoclassgenerator.php' => config_path('jsontoclassgenerator.php'),
], 'jsontoclassgenerator.config');
__DIR__.'/../config/dto-generator.php' => config_path('dto-generator.php'),
], 'dto-generator.config');

}
}
6 changes: 3 additions & 3 deletions src/Services/AbstractClassGenerator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace TimeHunter\LaravelJsonToClassGenerator\Services;
namespace TimeHunter\LaravelDTOGenerator\Services;


use Illuminate\Support\Facades\File;
Expand All @@ -24,7 +24,7 @@ abstract protected function getData(): array;
*/
public function generate()
{
$this->recursiveCreateFile($this->getData(), config('jsontoclassgenerator.namespace'));
$this->recursiveCreateFile($this->getData(), config('dto-generator.namespace'));
}

public function getType($value)
Expand Down Expand Up @@ -156,7 +156,7 @@ private function recursiveCreateFile($sample, $namespaceString)

$file = $className . '.php';

$location = config('jsontoclassgenerator.file_location') . '/' . $file;
$location = config('dto-generator.file_location') . '/' . $file;
File::put($location, $phpFile);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Services/ArrayToClassGenerator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace TimeHunter\LaravelJsonToClassGenerator\Services;
namespace TimeHunter\LaravelDTOGenerator\Services;


/**
Expand All @@ -15,6 +15,6 @@ class ArrayToClassGenerator extends AbstractClassGenerator
*/
public function getData(): array
{
return config('jsontoclassgenerator.array');
return config('dto-generator.array');
}
}
4 changes: 2 additions & 2 deletions src/Services/JsonToClassGenerator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace TimeHunter\LaravelJsonToClassGenerator\Services;
namespace TimeHunter\LaravelDTOGenerator\Services;


use Illuminate\Support\Facades\File;
Expand All @@ -18,7 +18,7 @@ class JsonToClassGenerator extends AbstractClassGenerator
*/
public function getData(): array
{
return json_decode(config('jsontoclassgenerator.json'),1);
return json_decode(config('dto-generator.json'),1);
}

}

0 comments on commit 84b7be9

Please sign in to comment.