@@ -6,6 +6,8 @@ class FileManager
6
6
{
7
7
private $ composerJsonPath = '' ;
8
8
private $ configFile = '.. ' ;
9
+ private $ extension = '.serial ' ;
10
+ private $ fileName = '' ;
9
11
private $ excludedNamespaces = [];
10
12
private $ includedNamespaces = [];
11
13
@@ -19,6 +21,8 @@ class FileManager
19
21
public function __construct (string $ composerJsonPath = '' )
20
22
{
21
23
$ this ->setComposerPath ($ composerJsonPath );
24
+ $ class = __CLASS__ ;
25
+ $ this ->fileName = substr ($ class , strrpos ($ class , '\\' ) + 1 );
22
26
}
23
27
24
28
/**
@@ -36,18 +40,38 @@ public function addNamespace(string $namespace, string $directory, bool $localGi
36
40
return $ this ;
37
41
}
38
42
43
+ /**
44
+ * Set file extension for saving index file
45
+ */
46
+ public function setExtension (string $ extension = '.serial ' ) : self
47
+ {
48
+ $ this ->extension = $ extension ;
49
+
50
+ return $ this ;
51
+ }
52
+
53
+ /**
54
+ * Set base file name for saving index file
55
+ */
56
+ public function setBaseFile (string $ fileName ) : self
57
+ {
58
+ $ this ->fileName = $ fileName ;
59
+
60
+ return $ this ;
61
+ }
62
+
39
63
/**
40
64
* Delete config files
41
65
*
42
66
* @return int number of files deleted
43
67
*/
44
- public function delete () : int
68
+ public function delete (string $ fileName = '' ) : int
45
69
{
46
70
$ count = 0 ;
47
71
48
- foreach (glob ($ this ->getSerializedName ('.* ' )) as $ filename )
72
+ foreach (glob ($ this ->getSerializedName ($ fileName , '.* ' )) as $ file )
49
73
{
50
- unlink ($ filename );
74
+ unlink ($ file );
51
75
++$ count ;
52
76
}
53
77
@@ -83,11 +107,11 @@ public function getComposerPath() : string
83
107
*
84
108
* @return true if file exists, false if generated
85
109
*/
86
- public function load () : bool
110
+ public function load (string $ fileName = '' ) : bool
87
111
{
88
112
$ returnValue = true ;
89
113
90
- if (! \PHPFUI \InstaDoc \NamespaceTree::load ($ this ->getSerializedName ()))
114
+ if (! \PHPFUI \InstaDoc \NamespaceTree::load ($ this ->getSerializedName ($ fileName )))
91
115
{
92
116
$ this ->rescan ();
93
117
$ this ->save ();
@@ -120,9 +144,9 @@ public function rescan() : FileManager
120
144
/**
121
145
* Save the current configuration
122
146
*/
123
- public function save () : bool
147
+ public function save (string $ fileName = '' ) : bool
124
148
{
125
- return \PHPFUI \InstaDoc \NamespaceTree::save ($ this ->getSerializedName ());
149
+ return \PHPFUI \InstaDoc \NamespaceTree::save ($ this ->getSerializedName ($ fileName ));
126
150
}
127
151
128
152
public function setComposerPath (string $ composerJsonPath ) : FileManager
@@ -144,7 +168,7 @@ public function setConfigName(string $dirOrFilename) : FileManager
144
168
return $ this ;
145
169
}
146
170
147
- private function getSerializedName (string $ type = '.serial ' ) : string
171
+ private function getSerializedName (string $ fileName = '' , string $ extension = ' ' ) : string
148
172
{
149
173
$ file = $ this ->configFile ;
150
174
@@ -155,13 +179,19 @@ private function getSerializedName(string $type = '.serial') : string
155
179
156
180
if (is_dir ($ file ))
157
181
{
158
- $ class = __CLASS__ ;
159
- $ class = substr ($ class , strrpos ($ class , '\\' ) + 1 );
182
+ if (empty ($ fileName ))
183
+ {
184
+ $ fileName = $ this ->fileName ;
185
+ }
160
186
161
- $ file .= '/ ' . $ class ;
187
+ $ file .= '/ ' . $ fileName ;
188
+ }
189
+ if (empty ($ extension ))
190
+ {
191
+ $ extension = $ this ->extension ;
162
192
}
163
193
164
- return $ file . $ type ;
194
+ return $ file . $ extension ;
165
195
}
166
196
167
197
/**
0 commit comments