Update file.php minor code improvements

This commit is contained in:
markjcrane 2023-05-15 23:17:37 -06:00
parent 0c585bcb07
commit 74b3ce154c
1 changed files with 11 additions and 5 deletions

View File

@ -26,6 +26,7 @@ class file {
* @var boolean $recursive get the sub directories * @var boolean $recursive get the sub directories
*/ */
public function glob($dir, $recursive) { public function glob($dir, $recursive) {
$files = [];
if ($dir != '' || $dir != '/') { if ($dir != '' || $dir != '/') {
$tree = glob(rtrim($dir, '/') . '/*'); $tree = glob(rtrim($dir, '/') . '/*');
if ($recursive) { if ($recursive) {
@ -56,6 +57,9 @@ class file {
* Get the sounds list of search as a relative path without the rate * Get the sounds list of search as a relative path without the rate
*/ */
public function sounds($language = 'en', $dialect = 'us', $voice = 'callie') { public function sounds($language = 'en', $dialect = 'us', $voice = 'callie') {
//define an empty array
$array = [];
//set default values //set default values
if (!isset($language)) { $language = 'en'; } if (!isset($language)) { $language = 'en'; }
if (!isset($dialect)) { $dialect = 'us'; } if (!isset($dialect)) { $dialect = 'us'; }
@ -67,11 +71,13 @@ class file {
$files = $this->glob($dir.'/*/'.$rate, true); $files = $this->glob($dir.'/*/'.$rate, true);
//loop through the languages //loop through the languages
if (!empty($files)) {
foreach($files as $file) { foreach($files as $file) {
$file = substr($file, strlen($dir)+1); $file = substr($file, strlen($dir)+1);
$file = str_replace("/".$rate, "", $file); $file = str_replace("/".$rate, "", $file);
$array[] = $file; $array[] = $file;
} }
}
//return the list of sounds //return the list of sounds
return $array; return $array;