Okay, today's the task: pushing all of 1892 files of Yii framework to the Git
repository is a burden, and upgrading it to new version pollutes the git log
with changes to files you don't care about. Let's package it into a PHAR!
You need just to put this script to the root of Yii codebase (cloned github
repo, for example), and run it as usual:
This will create the PHAR archive in the same directory.
Hovewer, beware the catch 1: PHP can refuse to create packed archive, emitting
the following error:
I decided to just remove lines 140 and 142 from the script:
And that's all. I can bear with 20 MB file in repo, and don't really care about
To connect the resulting PHAR to your Yii application, replace your usual:
With the following:
Note that in new Phar() invocation you should use real path to your phar
archive file, but second line should be written verbatim, as the PHAR which
becomes created is being made with alias 'yii', using feature described in
the documentation for Phar::__construct.
However, of course, there's a catch 2: Yii built-in asset manager (CAssetManager)
has too specific publish method, unable to cope with custom PHP streams.
So, we need the fixed version.
I decided to create a descendant of CAssetManager descriptively called PharCompatibleAssetManager
with the following definition exactly:
I'm really, really sorry that you had to read this traditionally horrible Yii
code, but that was inevitable... :(
Main change was starting from the $isPhar = strncmp('phar://', $path, 7) ===
Now just link this asset manager instead of built-in one:
Now your Yii web application uses phar archive instead of huge pile of separate
files. They say that this increases performance, but my personal reasons was
just to reduce the number of files inside the repository.