Skip to content

Commit 2bf42c0

Browse files
committed
Set base file name for FileManager
1 parent b0effc6 commit 2bf42c0

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ You may want users to get back into your system easily. Clicking on the top left
8989
$controller->setHomeUrl('/');
9090
```
9191

92+
### Breakup Your Documentation Into Sections
93+
If you have a lot of source code, you might want to break it into sections, so you will need a separate file to store the index in per section:
94+
```php
95+
$fileManager->setBaseFile('SubProject');
96+
```
97+
9298
### Generate Static Files
9399
Just the doc and file pages, no git!
94100
```php

src/PHPFUI/InstaDoc/FileManager.php

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class FileManager
66
{
77
private $composerJsonPath = '';
88
private $configFile = '..';
9+
private $extension = '.serial';
10+
private $fileName = '';
911
private $excludedNamespaces = [];
1012
private $includedNamespaces = [];
1113

@@ -19,6 +21,8 @@ class FileManager
1921
public function __construct(string $composerJsonPath = '')
2022
{
2123
$this->setComposerPath($composerJsonPath);
24+
$class = __CLASS__;
25+
$this->fileName = substr($class, strrpos($class, '\\') + 1);
2226
}
2327

2428
/**
@@ -36,18 +40,38 @@ public function addNamespace(string $namespace, string $directory, bool $localGi
3640
return $this;
3741
}
3842

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+
3963
/**
4064
* Delete config files
4165
*
4266
* @return int number of files deleted
4367
*/
44-
public function delete() : int
68+
public function delete(string $fileName = '') : int
4569
{
4670
$count = 0;
4771

48-
foreach (glob($this->getSerializedName('.*')) as $filename)
72+
foreach (glob($this->getSerializedName($fileName, '.*')) as $file)
4973
{
50-
unlink($filename);
74+
unlink($file);
5175
++$count;
5276
}
5377

@@ -83,11 +107,11 @@ public function getComposerPath() : string
83107
*
84108
* @return true if file exists, false if generated
85109
*/
86-
public function load() : bool
110+
public function load(string $fileName = '') : bool
87111
{
88112
$returnValue = true;
89113

90-
if (! \PHPFUI\InstaDoc\NamespaceTree::load($this->getSerializedName()))
114+
if (! \PHPFUI\InstaDoc\NamespaceTree::load($this->getSerializedName($fileName)))
91115
{
92116
$this->rescan();
93117
$this->save();
@@ -120,9 +144,9 @@ public function rescan() : FileManager
120144
/**
121145
* Save the current configuration
122146
*/
123-
public function save() : bool
147+
public function save(string $fileName = '') : bool
124148
{
125-
return \PHPFUI\InstaDoc\NamespaceTree::save($this->getSerializedName());
149+
return \PHPFUI\InstaDoc\NamespaceTree::save($this->getSerializedName($fileName));
126150
}
127151

128152
public function setComposerPath(string $composerJsonPath) : FileManager
@@ -144,7 +168,7 @@ public function setConfigName(string $dirOrFilename) : FileManager
144168
return $this;
145169
}
146170

147-
private function getSerializedName(string $type = '.serial') : string
171+
private function getSerializedName(string $fileName = '', string $extension = '') : string
148172
{
149173
$file = $this->configFile;
150174

@@ -155,13 +179,19 @@ private function getSerializedName(string $type = '.serial') : string
155179

156180
if (is_dir($file))
157181
{
158-
$class = __CLASS__;
159-
$class = substr($class, strrpos($class, '\\') + 1);
182+
if (empty($fileName))
183+
{
184+
$fileName = $this->fileName;
185+
}
160186

161-
$file .= '/' . $class;
187+
$file .= '/' . $fileName;
188+
}
189+
if (empty($extension))
190+
{
191+
$extension = $this->extension;
162192
}
163193

164-
return $file . $type;
194+
return $file . $extension;
165195
}
166196

167197
/**

0 commit comments

Comments
 (0)