-
Notifications
You must be signed in to change notification settings - Fork 22
API
The Herrera\Box\Box API.
- __construct
- addCompactor
- addFile
- addFromString
- buildFromDirectory
- buildFromIterator
- compactContents
- create
- getPhar
- replaceValues
- setStubUsingFile
- setValues
- sign
- signUsingFile
Sets the Phar that Box will be working on, as well as the file path for that Phar.
<?php $box = new Herrera\Box\Box(new Phar('test.phar'), 'test.phar');Adds a file contents compactor.
Please see CompactorInterface for implementing a file contents compactor.
<?php
use Herrera\Box\Compactor\Composer;
$box->addCompactor(new Composer());Adds a file to the Phar, with its contents run through compactContents() and replaceValues().
- If the
$localfile name is not provided,$filewill be used.
<?php $box->addFile('/path/to/my/file.php', 'my/file.php');Adds the file contents to the Phar, with the contents run through compactContents() and replaceValues().
<?php $box->addFromString('my/file.php', '<?php echo "Hello, world!\n";');Recursively adds the directory to the Phar, with each file's contents run through compactContents() and replaceValues().
If a regular expression is provided, all files not matching the regular expression will not be added.
<?php $box->buildFromDirectory('/path/to/dir', '/\.php$/');Adds the files returned from the iterator to the Phar, with each file's contents run through compactContents() and replaceValues().
Please see the PHP documentation for Phar::buildFromIterator() for details about what kind of data is expected from the iterator.
<?php
use Symfony\Component\Finder\Finder;
$finder = new Finder();
$finder->name('*.php')->in('/path/to/dir');
$box->buildFromIterator($finder);Runs the contents through each compactor added by addCompactor() and returns the results.
If no compactor supports the $file, the contents will be returned unchanged.
Before:
<?php
use Herrera\Box\Compactor\Composer;
$box->addCompactor(new Composer());
$contents = $box->compactContents('my/file.php', <<<CONTENTS
<?php
/**
* My class.
*/
class MyClass
{
/**
* My method.
*/
public function myMethod()
{
}
}
CONTENTS
);After:
<?php
class MyClass
{
public function myMethod()
{
}
}Returns a new instance of Phar and Box.
The given arguments are used for the Phar::__construct() method.
<?php $box = Box::create('test.phar');Returns the Phar instance provided in __construct().
<?php $phar = $box->getPhar();Searches for the placeholder values and replaces them with the values specified by setValues().
<?php
$box->setValues(array('@name@' => 'world'));
$contents = $box->replaceValues('Hello, @name@!'); // "Hello, world!"Reads the file and sets the Phar stub using its contents.
- If
$replaceis set totrue, the contents will be run throughreplaceValues().
<?php $box->setStubUsingFile('/path/to/stub.php');Sets the search and replace values used by replaceValues().
- The array key is the search term.
- The array value is value the search term is replaced with.
<?php $box->setValues(array('@name@' => 'Name'));Signs the Phar using the given private key and password.
<?php $box->sign($privateKey, 'privateKeyPassword');Signs the Phar using the given private key file and password.
<?php $box->signUsingFile('/path/to/private.key', 'privateKeyPassword');