1. Go to this page and download the library: Download herrera-io/box library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
herrera-io / box example snippets
use Herrera\Box\Box;
use Herrera\Box\StubGenerator;
$box = Box::create('test.phar');
$box->buildFromDirectory('/path/to/dir');
$box->getPhar()->setStub(
StubGenerator::create()
->index('path/to/script.php')
->generate()
);
namespace Example\Compactor;
use Herrera\Box\Compactor\CompactorInterface;
/**
* My example compactor.
*/
class RemoveWhitespace implements CompactorInterface
{
/**
* Seek and destroy (whitespaces).
*
* @param string $source The source code.
*
* @return string The compacted source code.
*/
public function compact($source)
{
return preg_replace('/[ \t]+$/m', '', $source);
}
/**
* Make sure we support it.
*
* @param string $file The file path.
*
* @return boolean Returns TRUE if supported, FALSE if not.
*/
public function supports($file)
{
return ('php' === pathinfo($file, PATHINFO_EXTENSION));
}
}
namespace Example\Compactor;
use Herrera\Box\Compactor\Compactor;
/**
* My example compactor.
*/
class RemoveWhitespace extends Compactor
{
/**
* The default supported file extensions.
*
* @var array
*/
protected $extensions = array('php');
/**
* Seek and destroy (whitespaces).
*
* @param string $source The source code.
*
* @return string The compacted source code.
*/
public function compact($source)
{
return preg_replace('/[ \t]+$/m', '', $source);
}
}
$example = new Example\Compactor\RemoveWhitespace();
$example->setExtensions(
array(
'inc',
'php'
)
);
use Herrera\Box\Compactor\Javascript;
$compactor = new Javascript();
use Herrera\Box\Compactor\Json;
$compactor = new Json();
use Herrera\Box\Compactor\Php;
$compactor = new Php();
use Herrera\Annotations\Tokenizer;
$compactor->setTokenizer(new Tokenizer());
use Herrera\Box\Exception\SignatureException;
use Herrera\Box\Signature;
$sig = new Signature('/path/to/my.phar');
// same output as Phar->getSignature()
$signature = $sig->get();
try {
// TRUE if passed, FALSE if failed
$result = $sig->verify();
} catch (SignatureException $exception) {
// the signature could not be verified
}
if (Signature::create('/path/to/my.phar')->verify()) {
// do the do
}
use Herrera\Box\Extract;
$extract = new Extract('/path/to/my.phar', 65538);
$extract->go('/path/to/extract/dir');
use Herrera\Box\StubGenerator;
$generator = new StubGenerator();
$banner = <<<BANNER
Copyright (c) 2013 Some Dude
Some license text here.
BANNER;
$mimetypes = array(
'phps' => Phar::PHP
);
$rewrite = <<<REWRITE
function rewrite_url(\$uri)
{
return \$rewritten;
}
REWRITE;
$stub = $generator
->alias('test.phar')
->banner($banner)
->extract(true)
->index('bin/cli.php')
->intercept(true)
->mimetypes($mimetypes)
->mung(array('REQUEST_URI'))
->notFound('lib/404.php')
->rewrite($rewrite)
->shebang('/home/dude/.local/php/bin/php')
->web(true)
->generate();
/**
* Copyright (c) 2013 Some Dude
*
* Some license text here.
*/
define('BOX_EXTRACT_PATTERN_DEFAULT', '__HALT' . '_COMPILER();
user Herrera\Box\Box;
// use an existing Phar instance
$box = new Box($phar);
// or create one
$box = Box::create('/path/to/my.phar');
use Herrera\Box\Compactor\Json;
use Herrera\Box\Compactor\Php;
$box->addCompactor(new Json());
$box->addCompactor(new Php());
$box->addCompactor($custom);