
ค้นหาซอร์สโค้ด PHP สำหรับการเรียกใช้ฟังก์ชันและวิธีการการกำหนดตัวแปรคลาสและอื่น ๆ โดยตรงจาก PHP
composer require permafrost-dev/php-code-search ในการค้นหาไฟล์ให้ใช้วิธี search พารามิเตอร์เท่านั้นอาจเป็นสตริงที่มีชื่อไฟล์ที่ถูกต้องหรืออินสแตนซ์ของ PermafrostPhpCodeSearchSupportFile
ในการค้นหาสตริงแทนให้ใช้เมธอด searchCode
วิธีการค้นหาส่งคืนอินสแตนซ์ของ PermafrostPhpCodeSearchResultsFileSearchResults ซึ่งมีคุณสมบัติ results
แต่ละ result เป็นอินสแตนซ์ของ PermafrostPhpCodeSearchResultsSearchResult ด้วยคุณสมบัติต่อไปนี้:
node - รายการเฉพาะที่พบnode->name(): stringlocation - ตำแหน่งในไฟล์ที่พบรายการlocation->startLine(): intlocation->endLine(): intsnippet - ตัวอย่างของรหัสบรรทัดจากไฟล์ที่มีบรรทัดผลลัพธ์อยู่ตรงกลางsnippet->toString(): stringfile() (เมธอด) - ให้การเข้าถึงไฟล์ที่ค้นหา หากต้องการค้นหาผ่านรหัสในสตริงหรือไฟล์ให้ใช้คลาส Searcher :
use Permafrost PhpCodeSearch Searcher ;
$ searcher = new Searcher (); ในการค้นหาไฟล์ให้ใช้วิธี search และเมธอด searchCode เพื่อค้นหาสตริงของรหัส
$ searcher
-> functions ([ ' strtolower ' , ' strtoupper ' ])
-> search ( ' ./file1.php ' );
$ searcher
-> variables ([ ' /^one[A-Z]$/ ' ])
-> searchCode ( ' <?php $oneA = "1a"; ' ); เมื่อค้นหาโดยใช้วิธีการใด ๆ ที่มีอยู่การแสดงออกปกติสามารถใช้งานได้โดยรอบชื่อด้วย Slashes / , IE /testd+/
ในการค้นหาตัวแปรตามชื่อให้ใช้วิธี variables
$ results = $ searcher
-> variables ([ ' twoA ' , ' /^one.$/ ' ])
-> searchCode ( ' <?php ' .
' $oneA = "1a"; ' .
' $oneB = "1b"; ' .
' $twoA = "2a"; ' .
' $twoB = "2b"; ' .
'' );
foreach ( $ results -> results as $ result ) {
echo " Found ' { $ result -> node -> name ()} ' on line { $ result -> location -> startLine }" . PHP_EOL ;
} ในการค้นหาการเรียกใช้ฟังก์ชันหรือคำจำกัดความให้ใช้วิธี functions
// search for references AND definitions for 'strtolower' and/or 'myfunc'
$ searcher
-> functions ([ ' strtolower ' , ' myfunc ' ])
-> search ( ' file1.php ' ); ในการค้นหาวิธีการโทรตามชื่อให้ใช้ methods
โหนดการเรียกใช้เมธอดมีคุณสมบัติ args ที่สามารถวนผ่านเพื่อดึงอาร์กิวเมนต์สำหรับการโทรวิธี
$ results = $ searcher
-> methods ([ ' /test(One|Two)/ ' ])
-> searchCode ( ' <?php ' .
' $obj->testOne("hello world 1"); ' .
' $obj->testTwo("hello world", 2); ' .
''
);
foreach ( $ results -> results as $ result ) {
echo " Found ' { $ result -> node -> name ()} ' on line { $ result -> location -> startLine }" . PHP_EOL ;
foreach ( $ result -> node -> args as $ arg ) {
echo " argument: ' { $ arg -> value } ' " . PHP_EOL ;
}
} ในการค้นหาวิธีการแบบคงที่หรือการโทรอสังหาริมทรัพย์ให้ใช้วิธี static
คำค้นหาที่ถูกต้องเป็นชื่อคลาสเช่น Cache หรือชื่อคลาสและชื่อวิธีเช่น Cache::remember
$ searcher
-> static ([ ' Ray ' , ' Cache::has ' , ' Request::$myProperty ' ])
-> search ( ' ./app/Http/Controllers/MyController.php ' ); ในการค้นหาคำจำกัดความของคลาสหรือคลาสที่สร้างขึ้นโดยคำหลัก new ให้ใช้เมธอด classes
$ searcher
-> classes ([ ' MyController ' ])
-> search ( ' ./app/Http/Controllers/MyController.php ' ); ในการค้นหาการกำหนดตัวแปรโดยชื่อตัวแปรให้ใช้วิธี assignments หมายเหตุ: ควรละเว้น $
$ searcher
-> assignments ([ ' myVar ' ])
-> search ( ' ./app/Http/Controllers/MyController.php ' ); ในการส่งคืนผลการค้นหาโดยไม่มีตัวอย่างรหัสที่เกี่ยวข้องให้ใช้เมธอด withoutSnippets :
$ searcher
-> withoutSnippets ()
-> functions ([ ' strtolower ' ])
-> search ( ' file1.php ' );./vendor/bin/phpunitโปรดดู Changelog สำหรับข้อมูลเพิ่มเติมเกี่ยวกับสิ่งที่เปลี่ยนแปลงไปเมื่อเร็ว ๆ นี้
โปรดดูรายละเอียดที่มีส่วนร่วม
โปรดตรวจสอบนโยบายความปลอดภัยของเราเกี่ยวกับวิธีการรายงานช่องโหว่ด้านความปลอดภัย
ใบอนุญาต MIT (MIT) โปรดดูไฟล์ใบอนุญาตสำหรับข้อมูลเพิ่มเติม