files()->followLinks(); } else { $finder = new Finder(); $finder->sortByName(); } if ($pattern === null) { $pattern = '*.php'; } $finder->files()->followLinks()->name($pattern); if (is_string($directory)) { if (is_file($directory)) { // Scan a single file? $finder->append([$directory]); } else { // Scan a directory $finder->in($directory); } } elseif (is_array($directory)) { foreach ($directory as $path) { if (is_file($path)) { // Scan a file? $finder->append([$path]); } else { $finder->in($path); } } } else { throw new InvalidArgumentException('Unexpected $directory value:' . gettype($directory)); } if ($exclude !== null) { if (is_string($exclude)) { $finder->notPath(Util::getRelativePath($exclude, $directory)); } elseif (is_array($exclude)) { foreach ($exclude as $path) { $finder->notPath(Util::getRelativePath($path, $directory)); } } else { throw new InvalidArgumentException('Unexpected $exclude value:' . gettype($exclude)); } } return $finder; } /** * Escapes the special characters "/" and "~". * * https://swagger.io/docs/specification/using-ref/ * https://tools.ietf.org/html/rfc6901#page-3 */ public static function refEncode(string $raw): string { return str_replace('/', '~1', str_replace('~', '~0', $raw)); } /** * Converted the escaped characters "~1" and "~" back to "/" and "~". * * https://swagger.io/docs/specification/using-ref/ * https://tools.ietf.org/html/rfc6901#page-3 */ public static function refDecode(string $encoded): string { return str_replace('~1', '/', str_replace('~0', '~', $encoded)); } }