Skip to content

Commit 712fc0a

Browse files
author
ryan.deng
committed
updated
0 parents  commit 712fc0a

File tree

11 files changed

+365
-0
lines changed

11 files changed

+365
-0
lines changed

.styleci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: laravel

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
All notable changes to `LaravelJsonToClassGenerator` will be documented in this file.
4+
5+
## Version 1.0
6+
7+
### Added
8+
- Everything

composer.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "timehunter/laraveljsontoclassgenerator",
3+
"description": ":description",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Ryan Deng",
8+
"email": "[email protected]",
9+
"homepage": "https://github.com/RyanDaDeng"
10+
}
11+
],
12+
"homepage": "https://github.com/timehunter/laraveljsontoclassgenerator",
13+
"keywords": ["Laravel", "LaravelJsonToClassGenerator"],
14+
"require": {
15+
"illuminate/support": "~5"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "~7.0",
19+
"mockery/mockery": "^1.1",
20+
"orchestra/testbench": "~3.0",
21+
"sempro/phpunit-pretty-print": "^1.0"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"TimeHunter\\LaravelJsonToClassGenerator\\": "src/"
26+
}
27+
},
28+
"autoload-dev": {
29+
"psr-4": {
30+
"TimeHunter\\LaravelJsonToClassGenerator\\Tests\\": "tests"
31+
}
32+
},
33+
"extra": {
34+
"laravel": {
35+
"providers": [
36+
"TimeHunter\\LaravelJsonToClassGenerator\\LaravelJsonToClassGeneratorServiceProvider"
37+
],
38+
"aliases": {
39+
"LaravelJsonToClassGenerator": "TimeHunter\\LaravelJsonToClassGenerator\\Facades\\LaravelJsonToClassGenerator"
40+
}
41+
}
42+
}
43+
}

config/jsontoclassgenerator.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
return [
4+
'namespace' => 'App\Test',
5+
'file_location' => app_path(),
6+
'data' => [
7+
'message' => [
8+
'author' => [
9+
'first_name' => '',
10+
'last_name' => '',
11+
],
12+
'text' => '',
13+
'date' => '2019-01-01'
14+
]
15+
]
16+
];

contributing.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Contributing
2+
3+
Contributions are welcome and will be fully credited.
4+
5+
Contributions are accepted via Pull Requests on [Github](https://github.com/timehunter/laraveljsontoclassgenerator).
6+
7+
# Things you could do
8+
If you want to contribute but do not know where to start, this list provides some starting points.
9+
- Add license text
10+
- Remove rewriteRules.php
11+
- Set up TravisCI, StyleCI, ScrutinizerCI
12+
- Write a comprehensive ReadMe
13+
14+
## Pull Requests
15+
16+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
17+
18+
- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.
19+
20+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
21+
22+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
23+
24+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
25+
26+
27+
**Happy coding**!

license.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# The license
2+
3+
MIT License
4+
5+
Copyright (c) 2019 RyanDaDeng
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.

phpunit.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Package">
14+
<directory suffix=".php">./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory>src/</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

readme.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Laravel JSON to Class Generator
2+
3+
4+
## Installation
5+
6+
Install the package in development dependencies:
7+
8+
Via Composer
9+
10+
``` bash
11+
$ composer require-dev timehunter/laraveljsontoclassgenerator
12+
```
13+
14+
## Usage
15+
16+
1. Create your local config file
17+
````bash
18+
php artisan vendor:publish --provider="TimeHunter\LaravelJsonToClassGenerator\LaravelJsonToClassGeneratorServiceProvider"
19+
````
20+
2. Add your JSON array in config
21+
3. Run artisan command:
22+
````bash
23+
$ php artisan make:jsontoclass
24+
````
25+
4. Check your files under your specified file location
26+
27+
## Change log
28+
29+
Please see the [changelog](changelog.md) for more information on what has changed recently.
30+
31+
32+
## Contributing
33+
34+
Please see [contributing.md](contributing.md) for details and a todolist.
35+
36+
## Security
37+
38+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
39+
40+
41+
42+
## License
43+
44+
MIT. Please see the [license file](license.md) for more information.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace TimeHunter\LaravelJsonToClassGenerator\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Log;
7+
use TimeHunter\LaravelJsonToClassGenerator\Services\JsonToClassGenerator;
8+
9+
class JsonToClassGeneratorCommand extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'make:jsontoclass';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Generate classes based on JSON';
24+
25+
/**
26+
* Create a new command instance.
27+
*
28+
* @return void
29+
*/
30+
public function __construct()
31+
{
32+
parent::__construct();
33+
}
34+
35+
/**
36+
* Execute the console command.
37+
*
38+
* @return mixed
39+
*/
40+
public function handle()
41+
{
42+
try{
43+
JsonToClassGenerator::generate(config('jsontoclassgenerator.data'));
44+
$this->info('Classes generated. Please check them.');
45+
}catch(\Exception $e){
46+
Log::error($e);
47+
$this->warn('Error happens, please check log file.');
48+
}
49+
}
50+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace TimeHunter\LaravelJsonToClassGenerator;
4+
5+
6+
use Illuminate\Support\ServiceProvider;
7+
use TimeHunter\LaravelJsonToClassGenerator\Commands\JsonToClassGeneratorCommand;
8+
9+
class LaravelJsonToClassGeneratorServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* Perform post-registration booting of services.
13+
*
14+
* @return void
15+
*/
16+
public function boot()
17+
{
18+
if ($this->app->runningInConsole()) {
19+
$this->bootForConsole();
20+
$this->commands([
21+
JsonToClassGeneratorCommand::class,
22+
]);
23+
}
24+
}
25+
26+
/**
27+
* Register any package services.
28+
*
29+
* @return void
30+
*/
31+
public function register()
32+
{
33+
}
34+
35+
/**
36+
* Console-specific booting.
37+
*
38+
* @return void
39+
*/
40+
protected function bootForConsole()
41+
{
42+
// Publishing the configuration file.
43+
$this->publishes([
44+
__DIR__.'/../config/jsontoclassgenerator.php' => config_path('jsontoclassgenerator.php'),
45+
], 'jsontoclassgenerator.config');
46+
47+
}
48+
}

0 commit comments

Comments
 (0)