PHP code example of tbessenreither / copycat

1. Go to this page and download the library: Download tbessenreither/copycat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tbessenreither / copycat example snippets


 declare(strict_types=1);
namespace Tbessenreither\MyPackage;

use Tbessenreither\Copycat\Enum\CopyTargetEnum;
use Tbessenreither\Copycat\Interface\CopycatConfigInterface;
use Tbessenreither\Copycat\Interface\CopycatInterface;

class CopycatConfig implements CopycatConfigInterface
{
    public static function run(CopycatInterface $copycat): void
    {
        $copycat->copy(
            target: CopyTargetEnum::DDEV_COMMANDS_WEB,
            file: 'ddev/commands/web/test-command.sh',
            overwrite: false,
            gitIgnore: true,
        );
    }
}


$copycat->copy(
    target: CopyTargetEnum::DDEV_COMMANDS_WEB, # The target location for the copied file. Renaming is not supported, the file will be copied with the same name to the target location.
    file: 'ddev/commands/web/test-command.sh', # Path to the file in your package from the root directory (Not the autoload path of your namespace)
    overwrite: false, # Whether to overwrite the file if it already exists in the target location. Default is false to prevent accidental overwrites.
    gitIgnore: true, # Optionally add the copied file to .gitignore. Default is false.
);


$copycat->copyDirectory(
    target: \Tbessenreither\Copycat\Enum\CopyTargetEnum::KIRO_SETTINGS,
    source: 'src/sourceDir',
    overwrite: true,
    gitIgnore: false,
    createTargetDirectory: true,
);


$copycat->jsonAdd(
    target: JsonTargetEnum::COMPOSER_JSON, # The target JSON file to modify. This determines the expected system for the operation (e.g., only allowing modifications to composer.json in general projects, only allowing modifications to Symfony config files in Symfony apps, etc.). Also determines which paths are allowed to be modified (e.g., only allowing modifications in the extra section of composer.json) to ensure safe modifications.
    path: 'extra.somePackageConfig', # Dot notation of the path through the JSON structure where the value should be added or modified. If the path does not exist, it will be created.
    value: [
        'key1' => 'value1',
        'key2' => 'value2',
    ],
    overwrite: true, # Whether to overwrite the value if it already exists at the specified path. Default is false to prevent accidental overwrites.
);

$copycat->gitIgnoreAdd(
    entries: [ # this can also be a string if you want to add just a single entry
        'ignored-file.txt',
        'ignored-directory/*',
    ],
);

$copycat->dockerIgnoreAdd(
    entries: [ # this can also be a string if you want to add just a single entry
        'tests/',
        '.github/',
    ],
);

$copycat->symfonyBundleAdd(
    bundleClassName: Tbessenreither\MyPackage\MyPackageBundle::class,
);

$copycat->symfonyAddServiceToYaml(
    serviceClassName: Tbessenreither\MyPackage\MyPackageService::class,
    arguments: [ # Optional array of arguments to be passed to the service. This can be used to automatically wire services with their dependencies.
        '$argument1' => 'value1',
        '$argument2' => 'value2',
    ],
    public: true,
    decorates: 'some/class',
    tags: [
        'mytag1' => [
            'name' => 'ding',
            'template' => 'hat'
            'id' => 'swing',
            'priority' => 100,
        ],
    ],
);


$copycat->envAdd(
    target: EnvTargetEnum::DOT_EXAMPLE,
    entries: [
        'MY_ENV' => 'value',
        'MY_OTHER_ENV_VAR' => 'other_value',
    ],
    overwrite: false, # Whether to overwrite the value if the key already exists in the .env file. Default is false to prevent accidental overwrites.
);

use Tbessenreither\Copycat\Dto\EnvVar;

$copycat->envAdd(
    target: EnvTargetEnum::DOT_EXAMPLE,
    entries: [
        new EnvVar(
            name: 'MY_ENV',
            isFlag: true,
            description: 'This is a flag that does something when it exists',
        ),
        new EnvVar(
            name: 'STRING_SIMPLE',
            value: 'other_value',
            description: 'This is a string env var with a simple value',
        ),
        new EnvVar(
            name: 'STRING_COMPLEX',
            value: 'a more complex % string',
        ),
        new EnvVar(
            name: 'INT_VAR',
            value: 123,
        ),
        new EnvVar(
            name: 'BOOL_VAR',
            value: true,
        ),
        new EnvVar(
            name: 'NULL_VAR',
            value: null,
        ),
    ],
    overwrite: false, # Whether to overwrite the value if the key already exists in the .env file. Default is false to prevent accidental overwrites.
);
text
Running PHP Copycat...
Reverting copycat for namespace Tbessenreither\FeatureFlagServiceClient
    - Removing src/CopycatConfig.php from public
    - Removing .gitignore entries:
        Loading file: /var/www/html/.gitignore
        Storing modifications for: /var/www/html/.gitignore
    - Removing Tbessenreither\FeatureFlagServiceClient\Bundle\FeatureFlagClientBundle from symfony bundles.php.
        Loading file: /var/www/html/config/bundles.php
        Storing modifications for: /var/www/html/config/bundles.php

Writing buffered file modifications to disk...
    - Writing file to disk: /var/www/html/.gitignore
    - Writing file to disk: /var/www/html/config/bundles.php

PHP Copycat finished.