Nguyen Tien Si
GO1
<?php
// Example #1 Using an external file
include '/path/to/external/file.php';
// Example #2 Using a file within a phar archive
include 'phar:///path/to/myphar.phar/file.php';
?>
Folder structures
<?php
// index.php
require_once "phar://myphar.phar/common.php";
$config = parse_ini_file("config.ini");
AppManager::run($config);
<?php
// common.php
class AppManager
{
public static function run($config) {
echo "Print the config variable";
var_dump($config);
}
}[phar]
app = myphar
<?php
// create-phar.php
$srcRoot = "src/";
$buildRoot = "build/";
// Create a new Phar object with three args
$phar = new Phar($buildRoot . "/myphar.phar",
FilesystemIterator::CURRENT_AS_FILEINFO |
FilesystemIterator::KEY_AS_FILENAME, "myapp.phar");
$phar["index.php"] = file_get_contents($srcRoot . "/index.php");
$phar["common.php"] = file_get_contents($srcRoot . "/common.php");
$phar->setStub($phar->createDefaultStub("index.php"));
copy($srcRoot . "/config.ini", $buildRoot . "/config.ini");
[12:55][mrsinguyen@go1:~/Workspaces/myphar]$ php create-phar.php[13:02][mrsinguyen@go1:~/Workspaces/myphar]$ cd build/
[13:03][mrsinguyen@go1:~/Workspaces/myphar/build]$ ls
config.ini myphar.phar
[13:03][mrsinguyen@go1:~/Workspaces/myphar/build]$ chmod +x myphar.phar
[13:03][mrsinguyen@go1:~/Workspaces/myphar/build]$ php myphar.phar
Print the config variablearray(1) {
["app"]=>
string(6) "myphar"
}
[13:03][mrsinguyen@go1:~/Workspaces/myphar/build]$
<?php
// test.php
// http://localhost/test.php
require '/home/mrsinguyen/Workspaces/myphar/build/myphar.phar';
$ wget https://phar.phpunit.de/phpunit.phar
$ chmod +x phpunit.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version
PHPUnit 4.5.0 by Sebastian Bergmann and contributors.To globally install the PHAR:
You may also use the downloaded PHAR file directly:
$ wget https://phar.phpunit.de/phpunit.phar
$ php phpunit.phar --version
PHPUnit 4.5.0 by Sebastian Bergmann and contributors.$ curl -sS https://getcomposer.org/installer | php
$ chmod +x composer.phar
$ mv composer.phar /usr/local/bin/composer
$ composer --version
Composer version 1.0-dev (9f9cff558e5f447165f4265f320b2b1178f18301) 2015-03-08 18:02:57To globally install the Composer:
You may also use the downloaded Composer file directly:
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar --version
Composer version 1.0-dev (9f9cff558e5f447165f4265f320b2b1178f18301) 2015-03-08 18:02:57