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

v1.0.0 2024-11-12 15:13 UTC

This package is auto-updated.

Last update: 2025-03-12 16:50:12 UTC


README

Path2URL Banner

Path2URL

πŸš€ A robust PHP library for converting relative paths to absolute URLs

Latest Version on Packagist Total Downloads License PHP Version GitHub Stars Follow on GitHub

πŸ“– 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

🌐 Social

Twitter Follow LinkedIn

πŸ’ Support

If you found this package helpful, please consider:

πŸ“Š Project Stats

Repo Stats

πŸ”₯ Created and maintained by abdessattar23



If this package helps your project, please consider giving it a ⭐

Built with ❀️ by the PHP community