Narven
11/8/2017 - 3:57 PM

Build Slim framework as phar

Build Slim framework as phar

<?php

require('Slim/Slim.php');
\Slim\Slim::registerAutoloader();
<?php

$srcRoot = realpath(__DIR__."/vendor/slim/slim");
$buildRoot = realpath(__DIR__);

$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcRoot.DIRECTORY_SEPARATOR.'Slim', FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::LEAVES_ONLY);

echo "Build Slim phar\n";

$phar = new Phar($buildRoot.'/slim.phar', 0, 'slim.phar');
$phar->buildFromIterator($iterator, $srcRoot);
$phar->addFile(__DIR__.DIRECTORY_SEPARATOR.'autoload.php', 'autoload.php');
$phar->setStub($phar->createDefaultStub("autoload.php"));

exit("Build complete\n");
{
    "require": {
        "slim/slim": "@stable"
    },
    "config": {
      "preferred-install": "dist"
    },
    "prefer-stable": true,
    "scripts": {
        "post-update-cmd": "php build.php",
        "post-install-cmd": "php build.php"
    }
}
<?php

require(__DIR__.'/slim.phar');

$app = new \Slim\Slim();
var_dump($app);