Skip to content

Commit 982421d

Browse files
committed
Issue #21: Initialize InputFilters via init in Admin vs constructor in API
Signed-off-by: alexmerlin <alex.merlin.1985@gmail.com>
1 parent 5ccd0ca commit 982421d

5 files changed

Lines changed: 18 additions & 13 deletions

File tree

src/Type/InputFilter/CreateResourceInputFilter.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Dot\Maker\Component;
88
use Dot\Maker\Component\ClassFile;
9+
use Dot\Maker\Component\Method;
910
use Dot\Maker\Component\Method\Constructor;
1011
use Dot\Maker\Exception\BadRequestException;
1112
use Dot\Maker\Exception\DuplicateFileException;
@@ -57,7 +58,8 @@ public function render(string $name, Component $inputFilter): string
5758
*/
5859
COMM);
5960

60-
$init = (new Constructor())
61+
$init = (new Method('init'))
62+
->setReturnType('self')
6163
->setBody(<<<BODY
6264
// chain inputs below
6365
@@ -81,11 +83,11 @@ public function renderApi(string $name, Component $inputFilter): string
8183
*/
8284
COMM);
8385

84-
$init = (new Constructor())
86+
$constructor = (new Constructor())
8587
->setBody(<<<BODY
8688
// chain inputs here
8789
BODY);
88-
$class->addMethod($init);
90+
$class->addMethod($constructor);
8991

9092
return $class->render();
9193
}

src/Type/InputFilter/DeleteResourceInputFilter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Dot\Maker\Component;
88
use Dot\Maker\Component\ClassFile;
9-
use Dot\Maker\Component\Method\Constructor;
9+
use Dot\Maker\Component\Method;
1010
use Dot\Maker\Exception\BadRequestException;
1111
use Dot\Maker\Exception\DuplicateFileException;
1212
use Dot\Maker\Exception\RuntimeException;
@@ -58,7 +58,8 @@ public function render(string $name, Component $inputFilter, Component $input):
5858
*/
5959
COMM);
6060

61-
$init = (new Constructor())
61+
$init = (new Method('init'))
62+
->setReturnType('self')
6263
->setBody(<<<BODY
6364
// chain inputs below
6465

src/Type/InputFilter/EditResourceInputFilter.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Dot\Maker\Component;
88
use Dot\Maker\Component\ClassFile;
9+
use Dot\Maker\Component\Method;
910
use Dot\Maker\Component\Method\Constructor;
1011
use Dot\Maker\Exception\BadRequestException;
1112
use Dot\Maker\Exception\DuplicateFileException;
@@ -57,7 +58,8 @@ public function render(string $name, Component $inputFilter): string
5758
*/
5859
COMM);
5960

60-
$init = (new Constructor())
61+
$init = (new Method('init'))
62+
->setReturnType('self')
6163
->setBody(<<<BODY
6264
// chain inputs below
6365
@@ -81,11 +83,11 @@ public function renderApi(string $name, Component $inputFilter): string
8183
*/
8284
COMM);
8385

84-
$init = (new Constructor())
86+
$constructor = (new Constructor())
8587
->setBody(<<<BODY
8688
// chain inputs here
8789
BODY);
88-
$class->addMethod($init);
90+
$class->addMethod($constructor);
8991

9092
return $class->render();
9193
}

src/Type/InputFilter/ReplaceResourceInputFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public function render(string $name, Component $inputFilter): string
5252
*/
5353
COMM);
5454

55-
$init = (new Constructor())
55+
$constructor = (new Constructor())
5656
->setBody(<<<BODY
5757
// chain inputs here
5858
BODY);
59-
$class->addMethod($init);
59+
$class->addMethod($constructor);
6060

6161
return $class->render();
6262
}

test/Type/InputFilterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ private function dataProviderCreateResourceInputFilter(): string
477477
*/
478478
class CreateBookStoreInputFilter extends AbstractInputFilter
479479
{
480-
public function __construct()
480+
public function init(): self
481481
{
482482
// chain inputs below
483483
@@ -510,7 +510,7 @@ private function dataProviderDeleteResourceInputFilter(): string
510510
*/
511511
class DeleteBookStoreInputFilter extends AbstractInputFilter
512512
{
513-
public function __construct()
513+
public function init(): self
514514
{
515515
// chain inputs below
516516
@@ -541,7 +541,7 @@ private function dataProviderEditResourceInputFilter(): string
541541
*/
542542
class EditBookStoreInputFilter extends AbstractInputFilter
543543
{
544-
public function __construct()
544+
public function init(): self
545545
{
546546
// chain inputs below
547547

0 commit comments

Comments
 (0)