Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
php-any
loon
Repository navigation
Code
Issues
Pull requests
1
(1)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
loon
/
framework
/
src
/
Module
/
ClassDiscovery.php
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
51 lines (48 loc) · 1.99 KB
master
Breadcrumbs
loon
/
framework
/
src
/
Module
/
ClassDiscovery.php
Copy path
Top
File metadata and controls
Code
Blame
51 lines (48 loc) · 1.99 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace Loom;
/**
* 按目录和命名空间拼出类名。扫描时跳过符号链接,同级路径按字符串排序,并且不加载文件。
*
* 构造参数:无,本类型未声明构造参数。
*
* 返回值:本类型只有静态 scan,不需要为扫描去构造实例。
*
* 使用示例(依赖对象由所在应用或测试环境提供):
* @example $classes = ClassDiscovery::scan($config->path('app'), 'App');
*/
final class ClassDiscovery
{
/**
* 列出目录对应的类名。glob 失败时抛出 LogicException。得到的路径先按字符串排序。
* 符号链接跳过。子目录用目录名追加命名空间后递归。扩展名为 php 的文件用文件名当作类名,其他文件忽略。
* 不 require 文件,也不检查类声明是否与文件名一致。
*
* @param string $directory 要扫描的目录。
* @param string $namespace 该目录对应的命名空间前缀。
* @return array 完整类名。同级路径按字符串排序后逐个处理,目录递归展开,php 文件用文件名作为类名。
*
* 使用示例(依赖对象由所在应用或测试环境提供):
* @example $classes = ClassDiscovery::scan($config->path('app'), 'App');
*/
public static function scan(string $directory, string $namespace): array
{
$classes = [];
$paths = glob($directory . '/*');
if ($paths === false) {
throw new \LogicException('Cannot scan ' . $directory);
}
sort($paths, SORT_STRING);
foreach ($paths as $path) {
if (is_link($path)) {
continue;
}
if (is_dir($path)) {
$classes = array_merge($classes, self::scan($path, $namespace . '\\' . basename($path)));
} elseif (str_ends_with($path, '.php')) {
$classes[] = $namespace . '\\' . basename($path, '.php');
}
}
return $classes;
}
}
You can’t perform that action at this time.