Oihana PHP

copyFilteredFilesWithMetadata.php

Table of Contents

Functions

copyFilteredFilesWithMetadata()  : void
Copies the filtered files of a directory into a destination directory and, optionally, embeds a `.metadata.json` file describing the archive.

Functions

copyFilteredFilesWithMetadata()

Copies the filtered files of a directory into a destination directory and, optionally, embeds a `.metadata.json` file describing the archive.

copyFilteredFilesWithMetadata(string $sourceDir, string $destDir[, array<string|int, string> $excludePatterns = [] ][, callable|null $filterCallback = null ][, array<string, mixed> $metadata = [] ]) : void

This is the staging step shared by the directory-archiving helpers (tarDirectory() and zipDirectory()): it delegates the copy to copyFilteredFiles(), writes the metadata when provided, and guarantees the destination is non-empty.

Embedding metadata always makes the destination non-empty, even when no source file matched the filters (the archive then contains only .metadata.json).

Parameters
$sourceDir : string

The source directory to copy from.

$destDir : string

The destination (staging) directory to copy into.

$excludePatterns : array<string|int, string> = []

Glob patterns or file names to exclude.

$filterCallback : callable|null = null

Optional function (string $filepath): bool returning true to include the item.

$metadata : array<string, mixed> = []

Optional metadata embedded as .metadata.json.

Tags
throws
DirectoryException
author

Marc Alcaraz (ekameleon)

since
1.2.0
example
use function oihana\files\copyFilteredFilesWithMetadata;

copyFilteredFilesWithMetadata(
    '/var/www/html',
    '/tmp/staging',
    ['.git', 'node_modules'],
    fn( string $path ): bool => str_ends_with( $path , '.php' ),
    [ 'createdBy' => 'admin' ]
);
On this page

Search results