## How to package and use Yii framework in PHAR archive

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!

### Packaging

Rasmus Schultz made a special script to package the Yii framework into
a PHAR archive
. I forked it to save for a future (at least my GitHub account
will live as long as this blog).

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
compression.

### Using

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:

code, but that was inevitable... :(

Main change was starting from the $isPhar = strncmp('phar://',$path, 7) === 0; part.