Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
896e708
namming
binaryk Apr 29, 2020
632a072
Apply fixes from StyleCI (#148)
binaryk Apr 29, 2020
b708b32
Valid codes
binaryk Apr 29, 2020
331941b
Generator
binaryk Apr 29, 2020
3d236d2
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk Apr 29, 2020
2d10681
Apply fixes from StyleCI (#149)
binaryk Apr 29, 2020
d6bc74f
wip
binaryk Apr 29, 2020
0ec230f
wip
binaryk Apr 29, 2020
142623d
Apply fixes from StyleCI (#150)
binaryk Apr 29, 2020
1712404
wip
binaryk Apr 29, 2020
3144583
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk Apr 29, 2020
d26b550
Apply fixes from StyleCI (#151)
binaryk Apr 29, 2020
73d80f1
Add Stub Command
binaryk May 3, 2020
1f630fb
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 3, 2020
0f36fcc
Apply fixes from StyleCI (#152)
binaryk May 3, 2020
7723876
Index Query
binaryk May 4, 2020
0bc6fc8
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 4, 2020
74ea7cb
Apply fixes from StyleCI (#153)
binaryk May 4, 2020
2df5ed4
rename
binaryk May 4, 2020
48c75b2
wip
binaryk May 4, 2020
f7e0285
Apply fixes from StyleCI (#154)
binaryk May 4, 2020
6f7f60b
With relationships
binaryk May 5, 2020
9e981b8
With relationships
binaryk May 5, 2020
44ebefc
Apply fixes from StyleCI (#155)
binaryk May 5, 2020
29cbb78
wip
binaryk May 5, 2020
c2e4bdc
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 5, 2020
389ee65
wip
binaryk May 5, 2020
c6d7b26
wip
binaryk May 5, 2020
422b6c8
Apply fixes from StyleCI (#156)
binaryk May 5, 2020
9e39bac
Field tests
binaryk May 5, 2020
ebf526d
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 5, 2020
a177873
Apply fixes from StyleCI (#157)
binaryk May 5, 2020
515a5ed
wip
binaryk May 5, 2020
de405a3
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 5, 2020
c327f72
Mergeable repositories
binaryk May 6, 2020
f1b01f7
Apply fixes from StyleCI (#158)
binaryk May 6, 2020
deb9056
Default callback. Default resolver. Computed attributes.
binaryk May 6, 2020
a652b8f
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 6, 2020
58d6d2f
Apply fixes from StyleCI (#159)
binaryk May 6, 2020
9721b95
wip
binaryk May 6, 2020
aa00ac6
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 6, 2020
84f9d0b
Apply fixes from StyleCI (#161)
binaryk May 6, 2020
714e8dd
Integration and unit tests
binaryk May 6, 2020
bbb411a
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 6, 2020
68ba91e
Apply fixes from StyleCI (#162)
binaryk May 6, 2020
bd25c74
Performance
binaryk May 6, 2020
95fe397
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 6, 2020
7970784
Show fields works
binaryk May 6, 2020
930df8a
Apply fixes from StyleCI (#163)
binaryk May 6, 2020
52d188d
wip
binaryk May 7, 2020
568a68a
wip
binaryk May 7, 2020
5401b76
wip
binaryk May 7, 2020
ae4025e
Apply fixes from StyleCI (#164)
binaryk May 7, 2020
9f0332c
wip
binaryk May 8, 2020
431dbb8
wip
binaryk May 8, 2020
97b5620
Apply fixes from StyleCI (#165)
binaryk May 8, 2020
7708bc1
wip
binaryk May 8, 2020
2efe4ea
wip
binaryk May 8, 2020
dbc8d4c
Apply fixes from StyleCI (#166)
binaryk May 8, 2020
5c91a90
wip
binaryk May 8, 2020
c0dae31
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 8, 2020
ceed1fd
Apply fixes from StyleCI (#167)
binaryk May 8, 2020
6bdefb3
Unit tests
binaryk May 8, 2020
32622a6
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 8, 2020
067b24d
Apply fixes from StyleCI (#168)
binaryk May 8, 2020
e1baa98
wip
binaryk May 8, 2020
f5ba32e
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 8, 2020
8c76f6e
Apply fixes from StyleCI (#169)
binaryk May 8, 2020
8db5f0d
After store and update fields
binaryk May 9, 2020
324d734
Clean up
binaryk May 9, 2020
7deacd8
Merge branch 'features/naming' of github.com:BinarCode/laravel-restif…
binaryk May 9, 2020
2bc458d
Apply fixes from StyleCI (#170)
binaryk May 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"require": {
"php": "^7.4",
"ext-json": "*",
"illuminate/support": "^6.0|^7.0"
"illuminate/support": "^6.0|^7.0",
"doctrine/dbal": "^2.10"
},
"require-dev": {
"mockery/mockery": "^1.3",
Expand Down
2 changes: 1 addition & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
|
*/

'base' => '/restify-api',
'base' => '/api/restify',

/*
|--------------------------------------------------------------------------
Expand Down
36 changes: 36 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix="CheckPassport.php">src/Commands</directory>
</exclude>
</whitelist>
</filter>
<!-- <logging>-->
<!-- <log type="tap" target="build/report.tap"/>-->
<!-- <log type="junit" target="build/report.junit.xml"/>-->
<!-- <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>-->
<!-- <log type="coverage-text" target="build/coverage.txt"/>-->
<!-- <log type="coverage-clover" target="build/logs/clover.xml"/>-->
<!-- </logging>-->
<php>
<env name="APP_KEY" value="base64:la8jDWcqBHfGO6PR+OA9FAZqdi0XQKuhnzqc5tUATZs="/>
<env name="MAIL_DRIVER" value="log"/>
</php>
</phpunit>
18 changes: 12 additions & 6 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<?php

Route::get('/{repository}', 'RepositoryIndexController@handle');
Route::post('/{repository}', 'RepositoryStoreController@handle');
Route::get('/{repository}/{repositoryId}', 'RepositoryShowController@handle');
Route::patch('/{repository}/{repositoryId}', 'RepositoryUpdateController@handle');
Route::put('/{repository}/{repositoryId}', 'RepositoryUpdateController@handle');
Route::delete('/{repository}/{repositoryId}', 'RepositoryDestroyController@handle');
use Binaryk\LaravelRestify\Http\Controllers\RepositoryDestroyController;
use Binaryk\LaravelRestify\Http\Controllers\RepositoryIndexController;
use Binaryk\LaravelRestify\Http\Controllers\RepositoryShowController;
use Binaryk\LaravelRestify\Http\Controllers\RepositoryStoreController;
use Binaryk\LaravelRestify\Http\Controllers\RepositoryUpdateController;

Route::get('/{repository}', '\\'.RepositoryIndexController::class);
Route::post('/{repository}', '\\'.RepositoryStoreController::class);
Route::get('/{repository}/{repositoryId}', '\\'.RepositoryShowController::class);
Route::patch('/{repository}/{repositoryId}', '\\'.RepositoryUpdateController::class);
Route::put('/{repository}/{repositoryId}', '\\'.RepositoryUpdateController::class);
Route::delete('/{repository}/{repositoryId}', '\\'.RepositoryDestroyController::class);
36 changes: 0 additions & 36 deletions src/Commands/BaseRepositoryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,24 @@

class BaseRepositoryCommand extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'restify:base-repository';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new base repository class';

/**
* Indicates whether the command should be shown in the Artisan command list.
*
* @var bool
*/
protected $hidden = true;

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Repository';

/**
* Execute the console command.
*
* @return bool|null
*/
public function handle()
{
parent::handle();
}

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__.'/stubs/base-repository.stub';
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Restify';
Expand Down
93 changes: 35 additions & 58 deletions src/Commands/PolicyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,90 +6,66 @@
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

/**
* @author Eduard Lupacescu <eduard.lupacescu@binarcode.com>
*/
class PolicyCommand extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'restify:policy';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new policy for a specific model.';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Policy';

/**
* Execute the console command.
*
* @return bool|null
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function handle()
{
parent::handle();
if (parent::handle() === false && ! $this->option('force')) {
return false;
}
}

/**
* Build the class with the given name.
*
* @param string $name
* @return string
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function buildClass($name)
{
$namespacedModel = null;
$model = $this->option('model');
$class = $this->replaceModel(parent::buildClass($name));

if (is_null($model)) {
$model = $this->argument('name');
}
$class = $this->replaceQualifiedModel($class);

if ($model && ! Str::startsWith($model, [$this->laravel->getNamespace(), '\\'])) {
$namespacedModel = $this->laravel->getNamespace().$model;
}
return $class;
}

$name .= 'Policy';
protected function replaceClass($stub, $name)
{
$class = str_replace($this->getNamespace($name).'\\', '', $this->guessPolicyName());

$rendered = str_replace(
'UseDummyModel', $namespacedModel ?? $model, parent::buildClass($name)
);
return str_replace(['{{ class }}', '{{class}}'], $class, $stub);
}

$rendered = str_replace(
'DummyModel', $model, $rendered
);
protected function replaceModel($stub)
{
return str_replace(['{{ model }}', '{{model}}'], class_basename($this->guessQualifiedModel()), $stub);
}

protected function replaceQualifiedModel($stub)
{
return str_replace('{{ modelQualified }}', $this->guessQualifiedModel(), $stub);
}

protected function guessQualifiedModel(): string
{
$model = Str::singular(class_basename(Str::beforeLast($this->getNameInput(), 'Policy')));

return $rendered;
return str_replace('/', '\\', $this->rootNamespace().'Models/'.$model);
}

public function nameWithEnd()
protected function guessPolicyName()
{
$model = $this->option('model');
$name = $this->getNameInput();

if (is_null($model)) {
$model = $this->argument('name');
if (false === Str::endsWith($name, 'Policy')) {
$name .= 'Policy';
}

return $model.'Policy';
return $name;
}

protected function getPath($name)
{
return $this->laravel['path'].'/Policies/'.$this->nameWithEnd().'.php';
return $this->laravel['path'].'/Policies/'.$this->guessPolicyName().'.php';
}

/**
Expand All @@ -105,12 +81,12 @@ protected function getStub()
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Restify';
return $rootNamespace.'\Policies';
}

/**
Expand All @@ -122,6 +98,7 @@ protected function getOptions()
{
return [
['model', 'm', InputOption::VALUE_REQUIRED, 'The model class being protected.'],
['force', null, InputOption::VALUE_NONE, 'Create the class even if the model already exists.'],
];
}
}
Loading