Skip to content

Instantly share code, notes, and snippets.

@jippi
Last active October 12, 2017 07:52
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jippi/c993b8ef4a6a3cd1765d to your computer and use it in GitHub Desktop.
Save jippi/c993b8ef4a6a3cd1765d to your computer and use it in GitHub Desktop.
CakePHP inside a Phar file. NOTE: Change "ROOT" constant in paths.php to "."
<?php
require 'vendor/autoload.php';
$phar = new Phar(__DIR__ . '/dist/bownty-infra.phar', 0, 'bownty-infra');
$phar->startBuffering();
$collection = collection(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__)));
$collection = $collection->reject(function($file) { return $file->getFilename() === '.'; });
$collection = $collection->reject(function($file) { return $file->getFilename() === '..'; });
$collection = $collection->reject(function($file) { return strpos($file->getPath(), '.git') !== false; });
$collection = $collection->reject(function($file) { return strpos($file->getPath(), '/dist/') !== false; });
$collection = $collection->reject(function($file) { return strpos($file->getPath(), '/logs/') !== false; });
$collection = $collection->reject(function($file) { return strpos($file->getPath(), '/tmp/') !== false; });
$collection = $collection->reject(function($file) { return strpos($file->getPath(), '/tests/') !== false; });
$collection = $collection->reject(function($file) { return strpos($file->getPath(), '/test/') !== false; });
$collection = $collection->reject(function($file) { return strpos($file->getPath(), '/webroot/') !== false; });
$phar->buildFromIterator($collection, __DIR__);
$stub = "#!/usr/bin/env php \n" . $phar->createDefaultStub('bin/cake-phar.php');
$phar->setStub($stub);
$phar->stopBuffering();
<?php
// only change to the file is removing line 1 from bin/cake.php
include dirname(__DIR__) . '/config/bootstrap.php';
exit(Cake\Console\ShellDispatcher::run($argv));
SHELL := /bin/bash
.PHONY: phar clean help
.DEFAULT_GOAL := help
phar: ## Build a phar file
mkdir -p dist/
rm -f dist/bownty-infra.phar
php build.php
chmod 0775 dist/bownty-infra.phar
clean: ## Cleanup the dist/ directory
rm -rf dist/
help:
@grep -P '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment