Skip to content

publicplan/document-processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Publicplan Document Processor

PHP Version License

Standalone DOCX to HTML processor for PHP 8.4+ with Strategy Pattern architecture.

Features

  • DOCX to HTML conversion
  • Strategy Pattern architecture - 10 specialized element converters
  • Clean Architecture - SRP, testable, maintainable
  • Stateless design - Thread-safe processing
  • Comprehensive testing - 33 tests, 71 assertions

Installation

composer require publicplan/document-processor

Quick Start

use Publicplan\DocumentProcessor\Service\DocumentProcessor;
use Publicplan\DocumentProcessor\Service\DocumentLoader;

// Initialize
$loader = new DocumentLoader();
$processor = new DocumentProcessor($loader);

// Process document
$result = $processor->process('/path/to/file.docx', 'filename.docx');

// Access results
$html = $result->html;
$hasChanges = $result->hasUnacceptedChanges;
$messages = $result->getAllMessages();

Framework Integration

Symfony

Register services in config/services.yaml:

Publicplan\DocumentProcessor\:
  resource: '../vendor/publicplan/document-processor/src/'
  autowire: true
  autoconfigure: true
  exclude:
    - '../vendor/publicplan/document-processor/src/Service/Converter/'

Then inject in your controller:

use Publicplan\DocumentProcessor\Service\DocumentProcessor;

class MyController extends AbstractController
{
    public function upload(
        Request $request,
        DocumentProcessor $processor
    ): Response {
        $result = $processor->process('/path/to/file.docx', 'doc.docx');
        return $this->render('result.html.twig', ['html' => $result->html]);
    }
}

Laravel

Register in config/app.php:

'providers' => [
    // ...
    App\Providers\DocumentProcessorServiceProvider::class,
],

Or use directly:

use Publicplan\DocumentProcessor\Service\DocumentProcessor;
use Publicplan\DocumentProcessor\Service\DocumentLoader;

Route::post('/upload', function (Request $request) {
    $processor = new DocumentProcessor(new DocumentLoader());
    $result = $processor->process($request->file('docx')->path(), 'upload.docx');
    return view('result', ['html' => $result->html]);
});

Plain PHP

require 'vendor/autoload.php';

use Publicplan\DocumentProcessor\Service\DocumentProcessor;
use Publicplan\DocumentProcessor\Service\DocumentLoader;

$processor = new DocumentProcessor(new DocumentLoader());
$result = $processor->process('document.docx', 'document.docx');
echo $result->html;

Architecture

DocumentProcessor
├── DocumentLoader (DOCX loading & validation)
├── Element Converters (Strategy Pattern)
│   ├── TextElementConverter
│   ├── TextRunElementConverter
│   ├── ListElementConverter
│   ├── TableElementConverter
│   ├── LinkElementConverter
│   ├── BreakElementConverter
│   ├── PageBreakElementConverter
│   └── PreserveTextElementConverter
└── ElementConverterRegistry

Requirements

  • PHP 8.4+
  • phpoffice/phpword ^1.0
  • ext-zip (for DOCX handling)

Testing

composer install
composer test

Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/my-feature
  3. Commit changes: git commit -am 'Add some feature'
  4. Push to branch: git push origin feature/my-feature
  5. Create Pull Request

Please ensure all tests pass and follow PSR-12 coding standards.

Versioning

We use SemVer:

  • MAJOR: Breaking changes
  • MINOR: New features (backward compatible)
  • PATCH: Bug fixes (backward compatible)

Changelog

See CHANGELOG.md for version history.

License

MIT License - see LICENSE file for details.

Credits

Created by Publicplan GmbH

Related Projects

  • Jarvis - Bridge system for Confluence/Jira integration

Note: This bundle was extracted from the Jarvis project to be a standalone, reusable component.

About

Standalone DOCX to HTML processor for PHP 8.4+

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages