File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,8 +44,36 @@ public function __invoke($type, $classname)
4444 }
4545
4646 $ migration_path = $ this ->config ->item ('migration_path ' );
47+
48+ $ classname = ucfirst (strtolower ($ classname ));
49+
4750 $ file_path = $ migration_path . date ('YmdHis ' ) . '_ ' . $ classname . '.php ' ;
4851
52+ //check file exist
53+ if (file_exists ($ file_path )) {
54+ $ this ->stdio ->errln (
55+ "<<red>>The file \"$ file_path \" already exists<<reset>> "
56+ );
57+ return Status::FAILURE ;
58+ }
59+
60+ //check class exist
61+ foreach (glob ($ migration_path .'*_*.php ' ) as $ file )
62+ {
63+ $ name = basename ($ file , '.php ' );
64+
65+ //use date('YmdHis') so...
66+ if (preg_match ('/^\d{14}_(\w+)$/ ' , $ name , $ match ))
67+ {
68+ if ($ match [1 ] === $ classname ) {
69+ $ this ->stdio ->errln (
70+ "<<red>>The Class \"$ classname \" already exists<<reset>> "
71+ );
72+ return Status::FAILURE ;
73+ }
74+ }
75+ }
76+
4977 $ template = file_get_contents (__DIR__ . '/templates/Migration.txt ' );
5078 $ search = [
5179 '@@classname@@ ' ,
You can’t perform that action at this time.
0 commit comments