/** * List files and directories in the directory. * * @param int $sortOrder [optional] The order of the entries being returned. Using alphabetical order by default. * Order types: * - SCANDIR_SORT_ASCENDING * - SCANDIR_SORT_DESCENDING * - SCANDIR_SORT_NONE * @param resource $context [optional] The directory context. See PHPs scandir() function for more information. * @param bool $ignorePeriodDirs [optional] True to ignore period dirs such as /. and /.., false otherwise. * * @return Array|null A list of filesystem objects as an array or null on failure. * * @see scandir(); */ public function scan($sortOrder = SCANDIR_SORT_ASCENDING, $context, $ignorePeriodDirs = false) { // Make sure the directory handle was opened if (!$this->isOpened()) { return null; } // Scan the directory if ($context !== null) { $scan = scandir($this->handle, $sortOrder, $context); } else { $scan = scandir($this->handle, $sortOrder); } // Make sure the result was valid if ($scan === false) { return null; } // Create an array of filesystem objects $entries = array(); foreach ($scan as $entry) { // Check whether period directories should be ignored if ($ignorePeriodDirs && StringUtils::equals($entry, array('.', '..'), false, true)) { continue; } $entries[] = FileSystemObject::from($this->dir, $entry); } // Return the result return $entries; }