PHPackages                             tbessenreither/copycat - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. tbessenreither/copycat

ActiveLibrary[File &amp; Storage](/categories/file-storage)

tbessenreither/copycat
======================

tool for copying files and directories from bundles to your project

v0.8.9(1mo ago)13381MITPHPPHP ^8.4

Since Feb 17Pushed 1mo agoCompare

[ Source](https://github.com/tbessenreither/copycat)[ Packagist](https://packagist.org/packages/tbessenreither/copycat)[ RSS](/packages/tbessenreither-copycat/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (16)Used By (1)

PHP Copycat
===========

[](#php-copycat)

What is it?
-----------

[](#what-is-it)

PHP Copycat is a Composer package that provides a simple and safe way for PHP packages to automate file copying and configuration modifications in the projects that depend on them. It allows package authors to define a `CopycatConfig` class with operations like copying files, modifying JSON configurations, adding entries to `.gitignore`, and registering Symfony bundles. These operations are executed automatically when users run `composer install` or `composer update`, ensuring that necessary setup steps are performed without manual intervention.

All operations are designed to be safe and are based on a whitelist of allowed namespaces, so the project needs to explicitly allow the package to perform operations. Additionally, Copycat includes smart system validation to ensure that operations are only executed if the project matches the expected system (e.g., only copying Symfony files if the project is a Symfony app). This prevents accidental or unsafe changes in the wrong type of project.

Config files like the `composer.json` have additional protections to prevent malicious or accidental changes. For example, writes outside of the `extra` section are not allowed via json modifier, and the `copy` operation will not allow copying files from outside your package scope, ensuring safe and predictable automation. Additional to that all targets are predefined via enums in copycat, so there is no possibility to write to arbitrary paths in the project. This makes it a secure and reliable tool for package authors to enhance the user experience of their packages with necessary setup steps.

---

Features
--------

[](#features)

### Current features

[](#current-features)

- Copy files to specific targets (e.g., DDEV commands, Symfony, public, etc.)
- Add or modify JSON values at any path in a target file
- Add entries to your project's `.gitignore` in a grouped, idempotent way
- Register Symfony bundles automatically in `config/bundles.php`
- **Smart system validation:** Only runs operations if your project matches the expected system for the target (e.g., Symfony, DDEV)
- Secure: prevents copying files from outside your package scope
- Easily integrate with Composer scripts for automation
- Partial reversal of operations on package removal (removing copied files, removing bundle, removing .gitignore section)
- Adding values to .env files. All variables will be grouped by package namespace, and you can choose to overwrite existing entries or keep them to prevent accidental overwrites of user values.

### Planned Features

[](#planned-features)

PHP Copycat is actively developed. Planned features include:

- Echo of messages after execution (e.g., "Package \[Packagename\]: To use this package, do X, Y, Z...")

### Operation support matrix

[](#operation-support-matrix)

Legend: ✅ supported, 🔨 working on it, 🔴 not supported

copyjsonAddgitIgnoreAddsymfonyBundleAddsymfonyServiceYamlenvAddWrite✅✅✅✅✅✅Revert✅✅✅✅✅✅---

Setup
-----

[](#setup)

Require Copycat as a dependency via composer.

```
composer require tbessenreither/copycat
```

While you don't technically need copycat as a dependency in your package it is recommendet to at least use it as a dev dependency so you can take advantage of autocompletion and prevent errors.

### Within a package

[](#within-a-package)

Create a `CopycatConfig` class in the autoload root of your package that implements `CopycatConfigInterface`. This class will define the operations to be performed in the projects that depend on your package (e.g., copying files, modifying JSON, adding .gitignore entries, registering Symfony bundles). See the [Available Operations](#available-operations) section below for details and examples.

Example:

```
