PHP code example of codebase-dump / php

1. Go to this page and download the library: Download codebase-dump/php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codebase-dump / php example snippets




odebaseDump\Core\CodebaseAnalysis;
use CodebaseDump\Core\IgnorePatternManager;
use CodebaseDump\Core\PlainTextOutputFormatter;

$path = '/path/to/your/project';

$ignorePatternManager = new IgnorePatternManager($path);
$codebaseAnalysis = new CodebaseAnalysis();

// Single directory
$data = $codebaseAnalysis->analyzeDirectory(
    path: $path,
    ignorePatternManager: $ignorePatternManager,
    basePath: $path
);

// Multiple directories (merged into one tree)
$data = $codebaseAnalysis->analyzeDirectories(
    paths: ['/path/to/project1', '/path/to/project2'],
    ignorePatternManager: $ignorePatternManager
);

$formatter = new PlainTextOutputFormatter();
$output = $formatter->format($data, $ignorePatternManager->getIgnorePatternsAsArray());

file_put_contents('output.txt', $output);
bash
# Install dependencies
cd php
composer install

php/
├── src/
│   ├── Core/
│   │   ├── AuditApiUploader.php      # API upload functionality
│   │   ├── CodebaseAnalysis.php      # Directory/file analysis
│   │   ├── IgnorePatternManager.php  # Pattern matching
│   │   ├── OutputFormatterBase.php    # Base formatter class
│   │   ├── PlainTextOutputFormatter.php
│   │   └── MarkdownOutputFormatter.php
│   ├── Models/
│   │   ├── NodeAnalysis.php          # Abstract base class
│   │   ├── TextFileAnalysis.php      # Text file model
│   │   └── DirectoryAnalysis.php     # Directory model
│   ├── _version.php
│   └── cli.php                       # CLI application
├── tests/
│   ├── TestCase.php
│   ├── NodeModelsTest.php
│   ├── CodebaseAnalysisTest.php
│   ├── IgnorePatternManagerTest.php
│   └── AuditApiUploaderTest.php
├── composer.json
├── phpunit.xml
└── README.md