Phar excludes directories when creating a tarball

I want to create a tar archive in a PHP script using the built-in class PharData.

I want the tar archive to represent the directory, so I thought about using PharData::buildFromDirectory()for this. Unfortunately, the directory is also a git repository and has a folder in it .git, which is much larger than the directory itself.

Therefore, I need to delete this directory .git(ideally also the directory .idea...) from the archive, because it will inflate it unnecessarily.

What I have tried so far:

  • Using regex to filter a directory:

    $archive->buildFromDirectory("..", "@^(?!.git).+@");
    

    What didn't work.

  • Usage PharData::delete(), but, unfortunately, this is only like deleting a file, not a directory.

So what is the best way to do what I want?

+4
2

, (basename). , .git.

([^.][^g][^i][^t]) , , , .

, .


Phar:: buildFromIterator, RecursiveFilterIterator, . , .

+2

, git, lookahead:

$phar->buildFromDirectory(__DIR__, '/^((?!\.git).)*$/');

+2

All Articles