1. Go to this page and download the library: Download cmpayments/crate-lib 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/ */
cmpayments / crate-lib example snippets
use CmPayments\Crate\Crate;
use CmPayments\Crate\StubGenerator;
$crate = Crate::create('test.phar');
$crate->buildFromDirectory('/path/to/dir');
$crate->getPhar()->setStub(
StubGenerator::create()
->index('path/to/script.php')
->generate()
);
namespace Example\Compactor;
use CmPayments\Crate\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 CmPayments\Crate\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 CmPayments\Crate\Compactor\Javascript;
$compactor = new Javascript();
use CmPayments\Crate\Compactor\Json;
$compactor = new Json();
use CmPayments\Crate\Compactor\Php;
$compactor = new Php();
use Herrera\Annotations\Tokenizer;
$compactor->setTokenizer(new Tokenizer());
use CmPayments\Crate\Exception\SignatureException;
use CmPayments\Crate\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 CmPayments\Crate\Extract;
$extract = new Extract('/path/to/my.phar', 65538);
$extract->go('/path/to/extract/dir');
use CmPayments\Crate\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('CRATE_EXTRACT_PATTERN_DEFAULT', '__HALT' . '_COMPILER();
use CmPayments\Crate\Crate;
// use an existing Phar instance
$crate = new Crate($phar);
// or create one
$crate = Crate::create('/path/to/my.phar');
use CmPayments\Crate\Compactor\Json;
use CmPayments\Crate\Compactor\Php;
$crate->addCompactor(new Json());
$crate->addCompactor(new Php());
$crate->addCompactor($custom);