public function demoFiles() { // Ensure that $this->parent->filesystem->execute() returns a valid object $this->filesystem = $this->parent->filesystem->execute('object'); // Check if $this->filesystem is a valid object if (is_object($this->filesystem)) { // Call dirlist() method on $this->filesystem $dir_array = $this->filesystem->dirlist($this->demo_data_dir, false, true); if (!empty($dir_array) && is_array($dir_array)) { // Sort the array by keys uksort($dir_array, 'strcasecmp'); return $dir_array; } } else { // Handle the case where $this->filesystem is not a valid object // You might log an error or throw an exception // For example: // throw new Exception('Filesystem object is not properly initialized'); } // If $this->filesystem is not a valid object or dirlist() method returns empty or not an array // Fallback mechanism to retrieve directory content using scandir() $dir_array = array(); // Check if demo directory exists if (is_dir($this->demo_data_dir)) { // Get list of files and directories in the demo directory $demo_content = array_diff(scandir($this->demo_data_dir), array('..', '.')); // Iterate through each item in the demo directory foreach ($demo_content as $value) { if (is_dir($this->demo_data_dir . $value)) { $dir_array[$value] = array('name' => $value, 'type' => 'd', 'files' => array()); // Get list of files in each subdirectory $sub_dir_content = array_diff(scandir($this->demo_data_dir . $value), array('..', '.')); // Iterate through files in the subdirectory foreach ($sub_dir_content as $d_value) { if (is_file($this->demo_data_dir . $value . '/' . $d_value)) { $dir_array[$value]['files'][$d_value] = array('name' => $d_value, 'type' => 'f'); } } } } // Sort the array by keys uksort($dir_array, 'strcasecmp'); } return $dir_array; }