将具有多个类的php文件拆分为具有命名空间的类文件

Have a large file with 130k lines ~2k classes in it each encapsulated in a if(!class_exists()){}.

Objective is 2k individual class files with namespaces (currently none) from this data. Will use a parent namespace (let's call it Parent for now) and then first part of class name will be child namespace so. Example:

<?php
if (!class_exists('ThisClassName'){
    class ThisClassName {}
}
if (!class_exists('ThisOtherClass'){
    class ThisOtherClass{}
}
if (!class_exists('ThatClassName'){
    class ThatClassName {}
}
if (!class_exists('ThatOtherClass'){
    class ThatOtherClass{}
}

This will end up in this hierarchy:

src/ (root)
  This/
    ThisClassName.php
    ThisOtherClass.php
  That/
    ThatClassName.php
    ThatOtherClass.php

Example file:

<?php
namespace Parent\First;
class FirstClassName {}

Thoughts on how to start writing this script? Language for the file is PHP, though that's not required for any of the extraction scripting. Also consider any valid PHP could be in there for regex purposes.

P.s. For anyone curious this is NetSuite's PHP Toolkit (2016-2018, hopefully they wise up in 2019 and move to PSR)

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐