@@ -36,55 +36,116 @@ public function create(string $name): File
3636 {
3737 $ name = preg_replace ('/Handler$/ ' , '' , $ name );
3838
39+ $ entity = $ this ->fileSystem ->entity ($ name );
40+
3941 $ plural = Component::pluralize ($ name );
4042 if ($ this ->context ->isApi ()) {
4143 if (Input::confirm (sprintf ('Allow listing %s? ' , $ plural ))) {
4244 $ this ->component (TypeEnum::Collection)->create ($ name );
4345 $ this ->component (TypeEnum::HandlerApiGetCollection)->create ($ name );
4446 }
47+
4548 if (Input::confirm (sprintf ('Allow viewing %s? ' , $ plural ))) {
4649 $ this ->component (TypeEnum::HandlerApiGetResource)->create ($ name );
4750 }
51+
4852 if (Input::confirm (sprintf ('Allow creating %s? ' , $ plural ))) {
4953 $ this ->component (TypeEnum::HandlerApiPostResource)->create ($ name );
5054 $ this ->component (TypeEnum::InputFilterCreateResource)->create ($ name );
5155 }
56+
5257 if (Input::confirm (sprintf ('Allow deleting %s? ' , $ plural ))) {
5358 $ this ->component (TypeEnum::HandlerApiDeleteResource)->create ($ name );
5459 }
60+
5561 if (Input::confirm (sprintf ('Allow editing %s? ' , $ plural ))) {
5662 $ this ->component (TypeEnum::HandlerApiPatchResource)->create ($ name );
5763 $ this ->component (TypeEnum::InputFilterEditResource)->create ($ name );
5864 }
65+
5966 if (Input::confirm (sprintf ('Allow replacing %s? ' , $ plural ))) {
6067 $ this ->component (TypeEnum::HandlerApiPutResource)->create ($ name );
6168 $ this ->component (TypeEnum::InputFilterReplaceResource)->create ($ name );
6269 }
6370 } else {
6471 if (Input::confirm (sprintf ('Allow listing %s? ' , $ plural ))) {
6572 $ this ->component (TypeEnum::HandlerGetListResource)->create ($ name );
73+
74+ $ template = $ this ->fileSystem
75+ ->templateFile (
76+ $ entity ->getComponent ()->toKebabCase (),
77+ sprintf ('%s-list ' , $ entity ->getComponent ()->toKebabCase ())
78+ );
79+ if (! $ template ->exists ()) {
80+ $ template ->create (sprintf ('List %s template ' , $ plural ));
81+ Output::success (sprintf ('Created template file: %s ' , $ template ->getPath ()));
82+ }
6683 }
84+
6785 if (Input::confirm (sprintf ('Allow viewing %s? ' , $ plural ))) {
6886 $ this ->component (TypeEnum::HandlerGetViewResource)->create ($ name );
87+
88+ $ template = $ this ->fileSystem
89+ ->templateFile (
90+ $ entity ->getComponent ()->toKebabCase (),
91+ sprintf ('%s-view ' , $ entity ->getComponent ()->toKebabCase ())
92+ );
93+ if (! $ template ->exists ()) {
94+ $ template ->create (sprintf ('View %s template ' , $ plural ));
95+ Output::success (sprintf ('Created template file: %s ' , $ template ->getPath ()));
96+ }
6997 }
98+
7099 if (Input::confirm (sprintf ('Allow creating %s? ' , $ plural ))) {
71100 $ this ->component (TypeEnum::HandlerGetCreateResource)->create ($ name );
72101 $ this ->component (TypeEnum::HandlerPostCreateResource)->create ($ name );
73102 $ this ->component (TypeEnum::FormCreateResource)->create ($ name );
74103 $ this ->component (TypeEnum::InputFilterCreateResource)->create ($ name );
104+
105+ $ template = $ this ->fileSystem
106+ ->templateFile (
107+ $ entity ->getComponent ()->toKebabCase (),
108+ sprintf ('%s-create-form ' , $ entity ->getComponent ()->toKebabCase ())
109+ );
110+ if (! $ template ->exists ()) {
111+ $ template ->create (sprintf ('Create %s template ' , $ plural ));
112+ Output::success (sprintf ('Created template file: %s ' , $ template ->getPath ()));
113+ }
75114 }
115+
76116 if (Input::confirm (sprintf ('Allow deleting %s? ' , $ plural ))) {
77117 $ this ->component (TypeEnum::HandlerGetDeleteResource)->create ($ name );
78118 $ this ->component (TypeEnum::HandlerPostDeleteResource)->create ($ name );
79119 $ this ->component (TypeEnum::FormDeleteResource)->create ($ name );
80120 $ this ->component (TypeEnum::InputFilterDeleteResource)->create ($ name );
81121 $ this ->component (TypeEnum::Input)->create (sprintf ('%sConfirmation ' , $ name ));
122+
123+ $ template = $ this ->fileSystem
124+ ->templateFile (
125+ $ entity ->getComponent ()->toKebabCase (),
126+ sprintf ('%s-delete-form ' , $ entity ->getComponent ()->toKebabCase ())
127+ );
128+ if (! $ template ->exists ()) {
129+ $ template ->create (sprintf ('Delete %s template ' , $ plural ));
130+ Output::success (sprintf ('Created template file: %s ' , $ template ->getPath ()));
131+ }
82132 }
133+
83134 if (Input::confirm (sprintf ('Allow editing %s? ' , $ plural ))) {
84135 $ this ->component (TypeEnum::HandlerGetEditResource)->create ($ name );
85136 $ this ->component (TypeEnum::HandlerPostEditResource)->create ($ name );
86137 $ this ->component (TypeEnum::FormEditResource)->create ($ name );
87138 $ this ->component (TypeEnum::InputFilterEditResource)->create ($ name );
139+
140+ $ template = $ this ->fileSystem
141+ ->templateFile (
142+ $ entity ->getComponent ()->toKebabCase (),
143+ sprintf ('%s-edit-form ' , $ entity ->getComponent ()->toKebabCase ())
144+ );
145+ if (! $ template ->exists ()) {
146+ $ template ->create (sprintf ('Edit %s template ' , $ plural ));
147+ Output::success (sprintf ('Created template file: %s ' , $ template ->getPath ()));
148+ }
88149 }
89150 }
90151
0 commit comments