abdessattar23 / path2url
A robust PHP library that converts relative file paths to absolute URLs in HTML, CSS, and JavaScript files, with automatic backup creation and comprehensive logging
Requires
- php: >=7.4
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^9.0
README

Path2URL
π A robust PHP library for converting relative paths to absolute URLs
π About Path2URL
π οΈ Path2URL is a powerful PHP library designed to automatically convert relative file paths to absolute URLs in HTML, CSS, and JavaScript files. Perfect for migrating websites, setting up CDNs, or managing content across different environments.
β° Last Updated: 2024-11-12 14:53:36 UTC
β¨ Features
π Key Features:
- π Converts relative paths to absolute URLs
- π Supports HTML, CSS, and JavaScript files
- πΎ Automatic backup creation before modifications
- π Comprehensive logging system
- βοΈ Configurable file extensions
- π Type-safe with PHP 7.4+ features
β‘ Installation
π¦ Install the package via Composer:
composer require abdessattar23/path2url
π Basic Usage
use Path2URL\Path2URL; // Initialize the converter $converter = new Path2URL( '/path/to/your/files', 'https://your-domain.com' ); // Process all files $stats = $converter->process();
π― Example Transformations
π HTML Files
<!-- Before --> <img src="./images/logo.png"> <a href="../docs/guide.pdf"> <!-- After --> <img src="https://your-domain.com/images/logo.png"> <a href="https://your-domain.com/docs/guide.pdf">
π¨ CSS Files
/* Before */ background-image: url('./images/bg.jpg'); background: url('../assets/pattern.png'); /* After */ background-image: url('https://your-domain.com/images/bg.jpg'); background: url('https://your-domain.com/assets/pattern.png');
βοΈ Advanced Configuration
// Custom configuration $converter = new Path2URL( '/path/to/your/files', 'https://your-domain.com', ['html', 'css', 'js', 'xml'], // Custom file extensions 'custom_log.log' // Custom log file );
π Logging Example
[2024-11-12 13:46:07] [INFO] Starting URL conversion process
[2024-11-12 13:46:07] [INFO] Processing file: /path/to/file.html
[2024-11-12 13:46:07] [INFO] Created backup: file.html.1731417583.bak
[2024-11-12 13:46:07] [INFO] Successfully processed file
π Requirements
- π» PHP 7.4 or higher
- π¦ Composer for dependency management
π§ͺ Testing
Run the test suite:
composer test
π Security
π‘οΈ Found a security issue? Please email abdessattar23 instead of using the issue tracker.
π€ Contributing
Contributions are welcome! Please see CONTRIBUTING for details.
π License
βοΈ The MIT License (MIT). Please see License File for more information.
πΊοΈ Roadmap
- π₯οΈ CLI interface implementation
- π Additional file type support
- βοΈ Custom URL transformation rules
- π Framework integrations
- β‘ Real-time processing option
π₯ Credits
- π¨βπ» Author: abdessattar23
- π All Contributors
π Social
π Support
If you found this package helpful, please consider:
- β Starring the repository
- π Reporting issues
- π€ Contributing to the code
- β Buy me a coffee
π Project Stats
π₯ Created and maintained by abdessattar23
If this package helps your project, please consider giving it a β
Built with β€οΈ by the PHP community