arthusantiago / bootstrap-for-cakephp
Automatically copy Bootstrap and Bootstrap Icons assets to CakePHP webroot directory
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/arthusantiago/bootstrap-for-cakephp
Requires
- php: >=8.1
- composer-plugin-api: ^2.0
Requires (Dev)
- phpunit/phpunit: ^10.0
README
Automatically copy Bootstrap and Bootstrap Icons assets to your CakePHP webroot/ directory when packages are installed or updated via Composer.
Features
- ✨ Automatic copying of Bootstrap CSS and JS files
- ✨ Automatic copying of Bootstrap Icons CSS and fonts
- 🚀 Works with Composer package install/update hooks
- 🛠️ Manual CLI command for on-demand copying
- ✅ Fully compatible with CakePHP 4.x and 5.x
- 🔧 Customizable configuration and paths
- 📝 Comprehensive logging via Composer IO interface
Installation
Install the package via Composer:
composer require arthusantiago/bootstrap-for-cakephp
Then ensure you have Bootstrap installed:
composer require twbs/bootstrap twbs/bootstrap-icons
How It Works
This package automatically detects when Bootstrap or Bootstrap Icons are installed or updated via Composer, and copies the necessary files to your CakePHP webroot/ directory:
- Bootstrap CSS/JS → webroot/css/andwebroot/js/
- Bootstrap Icons → webroot/css/andwebroot/css/fonts/
Usage
Automatic (Recommended)
Once installed, the package automatically copies assets whenever you:
composer install composer update composer require twbs/bootstrap composer update twbs/bootstrap
Manual Copy
If you need to manually copy assets, use the CLI command:
# Copy all supported packages automatically composer copy-bootstrap-assets # Or copy specific package assets composer copy-bootstrap-assets twbs/bootstrap twbs/bootstrap-icons # Or copy each one individually composer copy-bootstrap-assets twbs/bootstrap composer copy-bootstrap-assets twbs/bootstrap-icons
Advanced Usage
Customizing Asset Paths
Extend the AssetsConfig class to customize where assets are copied:
<?php // config/AssetsConfig.php namespace App\Config; use ArthuSantiago\BootstrapForCakePHP\AssetsConfig; class MyAssetsConfig extends AssetsConfig { protected static string $webrootPath = 'custom_webroot'; // Override package configuration protected static array $packages = [ // ... custom configuration ]; }
Then register your custom config in composer.json:
{
  "scripts": {
    "post-install-cmd": [
      "ArthuSantiago\\BootstrapForCakePHP\\BootstrapAssets::setupAssets"
    ]
  }
}
Custom Implementations
Extend BootstrapAssets to implement custom logic:
<?php namespace App\Tools; use ArthuSantiago\BootstrapForCakePHP\BootstrapAssets; use Composer\Script\Event; class CustomBootstrapAssets extends BootstrapAssets { public static function setupAssets(Event $event): void { parent::setupAssets($event); // Add custom logic here // e.g., compile SCSS, minify files, etc. } }
Running Tests
First, install development dependencies:
composer install
Then run the test suite:
# Run all tests composer test # Or run directly with PHPUnit vendor/bin/phpunit # List all available tests vendor/bin/phpunit --list-tests # Run specific test file vendor/bin/phpunit tests/TestCase/FileOperationsTest.php # Run specific test method vendor/bin/phpunit --filter testCopyFileShouldCopyFileSuccessfully # Run tests from specific testsuite vendor/bin/phpunit --testsuite "Bootstrap Assets Test Suite"
Requirements
- PHP 8.1 or higher
- CakePHP 4.0 or higher
- Composer 2.0 or higher
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests to improve this package.
Support
If you encounter any issues, please open an issue on the GitHub repository.