从PHP中的文件内容获取完全限定的类名
来源:互联网 发布:arena软件 编辑:程序博客网 时间:2024/06/05 06:44
<?phpfunction get_class_from_file($path_to_file){ //Grab the contents of the file $contents = file_get_contents($path_to_file); //Start with a blank namespace and class $namespace = $class = ""; //Set helper values to know that we have found the namespace/class token and need to collect the string values after them $getting_namespace = $getting_class = false; //Go through each token and evaluate it as necessary foreach (token_get_all($contents) as $token) { //If this token is the namespace declaring, then flag that the next tokens will be the namespace name if (is_array($token) && $token[0] == T_NAMESPACE) { $getting_namespace = true; } //If this token is the class declaring, then flag that the next tokens will be the class name if (is_array($token) && $token[0] == T_CLASS) { $getting_class = true; } //While we're grabbing the namespace name... if ($getting_namespace === true) { //If the token is a string or the namespace separator... if(is_array($token) && in_array($token[0], [T_STRING, T_NS_SEPARATOR])) { //Append the token's value to the name of the namespace $namespace .= $token[1]; } else if ($token === ';') { //If the token is the semicolon, then we're done with the namespace declaration $getting_namespace = false; } } //While we're grabbing the class name... if ($getting_class === true) { //If the token is a string, it's the name of the class if(is_array($token) && $token[0] == T_STRING) { //Store the token's value as the class name $class = $token[1]; //Got what we need, stope here break; } } } //Build the fully-qualified class name and return it return $namespace ? $namespace . '\\' . $class : $class;}
摘自:http://jarretbyrne.com/2015/06/197/
阅读全文
0 0
- 从PHP中的文件内容获取完全限定的类名
- php中的file_get_contents函数------获取文件内容
- 简单的从客户端上传文件的完全限定名称里取出文件名
- PHP 获取文件内容
- php中的一些常量以及获取当前类名函数名的方法
- php 获取页面中的指定内容类
- 从FTP获取自动下载文件的PHP类
- mysql必知必会 - 使用完全限定名
- PHP 获取类名
- php 获取对象的类名 get_class
- php 获取表单中的内容
- php获取当前类名函数名的方法
- php获取当前类名函数名的方法
- php获取/检查当前类名函数名的方法
- php获取当前类名函数名的方法
- php获取文件内容函数
- PHP获取远程文件内容
- PHP获取文件拓展名的几种方式
- jdbc连接数据库time_zone问题
- C语言局部变量
- css盒子模型
- [IDDFS] HDU 1560
- 设计模式-6大设计原则
- 从PHP中的文件内容获取完全限定的类名
- Windows下安装Python和pip终极教程
- (二)心累
- ios-蓝牙简介
- 安装Android-studio遇到Gradle sync failed:和出现building“project name”gradle project info
- Android的ROM制作
- NOIP 2017 完挂记
- 云的种类
- ClassLoader类加载器的实现细节