| Crates.io | codegraph-php |
| lib.rs | codegraph-php |
| version | 0.1.0 |
| created_at | 2026-01-18 07:09:07.783847+00 |
| updated_at | 2026-01-18 07:09:07.783847+00 |
| description | PHP parser for CodeGraph - extracts code entities and relationships from PHP source files |
| homepage | |
| repository | https://github.com/anvanster/codegraph |
| max_upload_size | |
| id | 2051937 |
| size | 122,866 |
PHP parser for CodeGraph - extracts code entities and relationships from PHP source files.
| PHP Construct | Maps To |
|---|---|
function |
FunctionEntity |
class method |
FunctionEntity (with parent_class) |
class |
ClassEntity |
interface |
TraitEntity |
trait |
TraitEntity |
enum (PHP 8.1+) |
ClassEntity (with enum attribute) |
namespace |
ModuleEntity |
use statements |
ImportRelation |
extends |
InheritanceRelation |
implements |
ImplementationRelation |
Trait use |
ImplementationRelation |
use codegraph_php::PhpParser;
use codegraph_parser_api::CodeParser;
use codegraph::CodeGraph;
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut graph = CodeGraph::in_memory()?;
let parser = PhpParser::new();
// Parse a file
let file_info = parser.parse_file(Path::new("src/Controller.php"), &mut graph)?;
println!("Parsed {} functions", file_info.functions.len());
println!("Parsed {} classes", file_info.classes.len());
// Or parse source directly
let source = r#"<?php
class Example {
public function test(): void {
echo "Hello";
}
}
"#;
let file_info = parser.parse_source(source, Path::new("example.php"), &mut graph)?;
println!("Parsed {} entities", file_info.entity_count());
Ok(())
}
Run the basic example:
cargo run --example basic_parse
# Run all tests
cargo test -p codegraph-php
# Run specific test
cargo test -p codegraph-php test_parse_classes
# Run with verbose output
cargo test -p codegraph-php -- --nocapture
cargo bench -p codegraph-php
Apache-2.0