Commit 7c03d6ea by zhufx

1.自建组件,支持配置扫描目录

parent c28249a3
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/16
* Time: 11:09
*/
$basePath = dirname(__DIR__,3);
/**
* 用于自建组件扫描路径配置(键值是方便开发人员理解,代码中无意义)
* [
* 'commonPath' => $basePath.'/Common',
* 'enmu' => $basePath.'/Order/Enum',
*
* ];
*/
return [
'commonPath' => $basePath.'/Common',
];
\ No newline at end of file
...@@ -5,46 +5,45 @@ ...@@ -5,46 +5,45 @@
* Date: 2018/7/16 * Date: 2018/7/16
* Time: 9:32 * Time: 9:32
*/ */
$basePath = dirname(__DIR__,3); $scanPaths = include __DIR__.'/PathConfig.php';
$files = \Swoft\Helper\DirHelper::glob($basePath,'*.php');
$baseNamespace = "Hdll\Services";
$data = []; $data = [];
foreach ( $files as $file ) {
$path = dirname($file);
$suffixNamespace = str_replace($basePath,"",$path);
$suffixNamespace = str_replace("/","\\",$suffixNamespace);
$namespace = $baseNamespace.$suffixNamespace; foreach ($scanPaths as $basePath) {
$files = \Swoft\Helper\DirHelper::glob($basePath,'*.php');
$baseNamespace = "Hdll\Services\\";
$fileName = basename($file,'.php'); foreach ( $files as $file ) {
$pathSpace = str_replace("/var/www/swoft/vendor/hdll/services/src/","",$file);
$pathSpace = dirname($pathSpace);
$pathSpace = str_replace("/","\\",$pathSpace);
$className = $namespace.'\\'.$fileName; $namespace = $baseNamespace.$pathSpace;
try {
include_once $file;
if ( ! class_exists($className,false) ) {
continue;
}
//获取注解里的table $fileName = basename($file,'.php');
$res = new \ReflectionClass($className);
$commentString = $res->getDocComment();
if ( strpos($commentString,'@Bean()') === false ) { $className = $namespace.'\\'.$fileName;
continue; try {
} include_once $file;
if ( ! class_exists($className,false) ) {
continue;
}
$data[$className] = ['class' => $className]; //获取注解里的table
$res = new \ReflectionClass($className);
$commentString = $res->getDocComment();
}catch (Exception $e) { if ( strpos($commentString,'@Bean()') === false ) {
continue;
}
} $data[$className] = ['class' => $className];
}catch (Exception $e) {
}
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment