Ejemplo n.º 1
0
function makePhar(array $dt)
{
    //retornando com erro se o array estiver vazio
    if (count($dt) <= 0) {
        return false;
    }
    //aumentando a memoria e o tempo de execução - pode ser muito significante em sistemas lentos e diretórios muito grandes
    ini_set('memory_limit', '30M');
    ini_set('max_execution_time', 180);
    //Array com os dados da execução
    $ok = array();
    //lendo e executando as conversões indicadas
    foreach ($dt as $k => $lote) {
        //checando se deve converter indice['r']
        if (!isset($lote['r'])) {
            continue;
        }
        $dir = trim($lote['o'], ' \\/');
        $stub = '<?php 
			Phar::interceptFileFuncs();
			Phar::mungServer(array(\'REQUEST_URI\', \'PHP_SELF\', \'SCRIPT_NAME\', \'SCRIPT_FILENAME\'));
			Phar::webPhar(\'\', \'\', \'404.php\');
			__HALT_COMPILER();';
        // include(\'phar://\' . __FILE__ . \'/' . $lote['i'] . '\');
        if (is_dir($dir)) {
            //criando arquivo PHAR
            $phar = new Phar(trim($lote['d'], ' \\/'));
            //pegando o diretório (e sub-diretórios) e arquivos contidos
            $phar->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)), $dir);
            //criando o cabeçalho Stub
            $phar->setStub($stub);
            //carregando a assinatura
            if (file_exists(LIB . 'key.md5')) {
                $phar->setSignatureAlgorithm(Phar::MD5, file_get_contents(LIB . 'key.md5'));
            }
            //comprimindo os dados (exceto o Stub)
            $compactar = false;
            if (isset($lote['z'])) {
                $compactar = true;
                if (Phar::canCompress(Phar::GZ)) {
                    $phar->compressFiles(Phar::GZ);
                } elseif (Phar::canCompress(Phar::BZ2)) {
                    $phar->compressFiles(Phar::BZ2);
                }
            }
            //adicionando os dados de saída
            $ok[$k] = array('o' => $dir, 'd' => $lote['d'], 'z' => $compactar, 'i' => $lote['i']);
        } else {
            $ok[$k] = array('e' => 'O diretório "' . $dir . '" não existe!');
        }
    }
    if (count($ok) == 0) {
        return false;
    }
    return $ok;
}
Ejemplo n.º 2
0
 public function build($stub, $filename)
 {
     if (file_exists($filename)) {
         unlink($filename);
     }
     $phar = new \Phar($filename, 0, basename($filename));
     $phar->startBuffering();
     $phar->setStub($stub);
     if ($this->key !== NULL) {
         $privateKey = '';
         openssl_pkey_export($this->key, $privateKey);
         $phar->setSignatureAlgorithm(\Phar::OPENSSL, $privateKey);
         $keyDetails = openssl_pkey_get_details($this->key);
         file_put_contents($filename . '.pubkey', $keyDetails['key']);
     }
     $basedir = $this->basedir ? $this->basedir : $this->directories[0];
     foreach ($this->directories as $directory) {
         $phar->buildFromIterator($this->scanner->__invoke($directory), $basedir);
     }
     if ($this->compression !== \Phar::NONE) {
         $phar->compressFiles($this->compression);
     }
     $phar->stopBuffering();
 }
Ejemplo n.º 3
0
<?php

try {
    $phar = new Phar(dirname(__FILE__) . '/buildfromiterator2.phar');
    $phar->buildFromIterator(new stdClass());
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
<?php 
unlink(dirname(__FILE__) . '/buildfromiterator2.phar');
__halt_compiler();
?>
Ejemplo n.º 4
0
 /**
  * Add Files form folders.
  *
  * @param \Phar                    $phar   PHAR object to update.
  * @param \index0h\phar\Module $module Link to phar-module for getting configs and fire events.
  */
 public static function addFilesFromIterator(\Phar $phar, $module)
 {
     echo "\nAdd files";
     $phar->buildFromIterator(new Iterator($module));
 }
Ejemplo n.º 5
0
Archivo: build.php Proyecto: fjg/sacy
 function buildFromIterator(Iterator $it, $base_dir = null)
 {
     foreach ($it as $f) {
         $this->addFileToHash($f);
     }
     parent::buildFromIterator($it, $base_dir);
 }
Ejemplo n.º 6
0
 *   * Neither the name of Sebastian Bergmann nor the names of his
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
require 'File/Iterator/Factory.php';
$stub = <<<ENDSTUB
#!/usr/bin/env php
<?php
Phar::mapPhar('phpunit.phar');
require 'phar://phpunit.phar/TextUI/Command.php';
PHPUnit_TextUI_Command::main();
__HALT_COMPILER();
ENDSTUB;
$phar = new Phar('phpunit.phar', 0, 'phpunit.phar');
$phar->startBuffering();
$phar->buildFromIterator(File_Iterator_Factory::getFileIterator('PHPUnit'), dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PHPUnit');
$phar->setStub($stub);
$phar->stopBuffering();
Ejemplo n.º 7
0
#!/usr/bin/env php
<?php 
const PHAR_FILE = __DIR__ . '/../blackhole-bot.phar';
const EXEC_FILE = __DIR__ . '/../blackhole-bot';
$phar = new Phar(PHAR_FILE, 0, 'blackhole-bot.phar');
/**
 * Add files to phar
 */
$append = new AppendIterator();
$append->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/../src/', FilesystemIterator::SKIP_DOTS)));
$append->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/../vendor/', FilesystemIterator::SKIP_DOTS)));
$append->append(new ArrayIterator(['src/Config/Services/services.yml' => realpath(__DIR__ . '/../src/Config/Services/services.yml')]));
$phar->addFromString('bin/blackhole', str_replace('#!/usr/bin/env php', '', file_get_contents(__DIR__ . '/../bin/blackhole')));
/**
 * Build the phar
 */
$phar->buildFromIterator($append, __DIR__ . '/..');
// start buffering. Mandatory to modify stub.
$phar->startBuffering();
// Get the default stub. You can create your own if you have specific needs
$defaultStub = $phar->createDefaultStub('bin/blackhole');
// Adding files
$phar->buildFromDirectory(__DIR__, '/\\.php$/');
// Create a custom stub to add the shebang
$stub = "#!/usr/bin/env php \n" . $defaultStub;
// Add the stub
$phar->setStub($stub);
$phar->stopBuffering();
chmod(PHAR_FILE, 0755);
rename(PHAR_FILE, EXEC_FILE);
Ejemplo n.º 8
0
<?php

try {
    chdir(dirname(__FILE__));
    $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
    $a = $phar->buildFromIterator(new RegexIterator(new DirectoryIterator('.'), '/^frontcontroller\\d{0,2}\\.phar\\.phpt\\z|^\\.\\z|^\\.\\.\\z/'), dirname(__FILE__) . DIRECTORY_SEPARATOR);
    asort($a);
    var_dump($a);
    var_dump($phar->isFileFormat(Phar::ZIP));
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
<?php 
error_reporting(0);
unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
__halt_compiler();
?>
Ejemplo n.º 9
0
 /**
  * Creates a scaffolder from a given path.
  * 
  * @command-name CreateScaffolder
  * @command-description Creates a scaffolder from a given path.
  * 
  * @command-parameter-for $rootPath Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Path|-p Required. The path to package into a scaffolder.
  * @command-parameter-for $scaffolderFile Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --OutFile|-out Required. The filename of the scaffolder.
  */
 public function createScaffolderCommand($rootPath, $scaffolderFile)
 {
     $archive = new Phar($scaffolderFile);
     $archive->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath($rootPath))), realpath($rootPath));
 }
Ejemplo n.º 10
0
    }
    function key()
    {
        echo "key\n";
        return key($this->a);
    }
    function valid()
    {
        echo "valid\n";
        return current($this->a);
    }
    function rewind()
    {
        echo "rewind\n";
        return reset($this->a);
    }
}
try {
    chdir(dirname(__FILE__));
    $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
    var_dump($phar->buildFromIterator(new myIterator(array('a' => new stdClass()))));
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
<?php 
unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
__halt_compiler();
?>
        return $GLOBALS['fname2'];
    }
    function key()
    {
        return 'f' . $this->count;
    }
    function valid()
    {
        return $this->count < 3000;
    }
    function rewind()
    {
        $this->count = 1;
        return $GLOBALS['fname2'];
    }
}
try {
    chdir(dirname(__FILE__));
    $phar = new Phar($fname);
    $ret = $phar->buildFromIterator(new myIterator());
    foreach ($ret as $a => $val) {
        $ret[$a] = str_replace(dirname($fname2) . DIRECTORY_SEPARATOR, '*', $val);
    }
    var_dump($ret);
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
Ejemplo n.º 12
0
$buildRoot = $projectRoot . '/build';
$pharFile = $projectName . '.phar';
// Remove previous builds
if (is_file($buildRoot . '/' . $projectName)) {
    unlink($buildRoot . '/' . $projectName);
}
if (is_file($buildRoot . '/' . $pharFile)) {
    unlink($buildRoot . '/' . $pharFile);
}
// Remove dev dependencies
exec('composer install --no-dev');
// Build phar file
$phar = new Phar($buildRoot . '/' . $pharFile, 0, $pharFile);
$directoryIterator = new RecursiveDirectoryIterator($projectRoot . '/cli', FilesystemIterator::SKIP_DOTS);
$recursiveIterator = new RecursiveIteratorIterator($directoryIterator);
$phar->buildFromIterator($recursiveIterator, $projectRoot);
$directoryIterator = new RecursiveDirectoryIterator($projectRoot . '/src', FilesystemIterator::SKIP_DOTS);
$recursiveIterator = new RecursiveIteratorIterator($directoryIterator);
$phar->buildFromIterator($recursiveIterator, $projectRoot);
$directoryIterator = new RecursiveDirectoryIterator($projectRoot . '/vendor', FilesystemIterator::SKIP_DOTS);
$recursiveIterator = new RecursiveIteratorIterator($directoryIterator);
$phar->buildFromIterator($recursiveIterator, $projectRoot);
$phar->setStub(<<<EOF
#!/usr/bin/env php
<?php
Phar::mapPhar('{$pharFile}');
require 'phar://{$pharFile}/cli/index.php';
__HALT_COMPILER();
EOF
);
// Make file executable
Ejemplo n.º 13
0
 * @param mixed $key
 * @param RecursiveCallbackFilterIterator $iterator
 * @return bool True if you need to recurse or if the item is acceptable
 */
$filter = function ($file, $key, $iterator) use($exclude_folders, $exclude_files) {
    $file_name = $file->getFilename();
    if ($iterator->isDir() || substr($file_name, 0, 1) == ".") {
        if (!in_array(trim($file->getRealPath()), $exclude_folders)) {
            echo "Adding Directory: '" . $file->getRealPath() . "'" . PHP_EOL;
            return true;
        } else {
            echo "Skip Directory: '" . $file->getRealPath() . "'" . PHP_EOL;
            return false;
        }
    } else {
        foreach ($exclude_files as $exclude_file) {
            if (stristr($file_name, $exclude_file) !== FALSE) {
                echo "Skip File:" . $file_name . PHP_EOL;
                return false;
            }
        }
    }
    echo "Adding File: " . $file->getFilename() . PHP_EOL;
    return $file->isFile();
};
$innerIterator = new RecursiveDirectoryIterator(__DIR__, RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator(new RecursiveCallbackFilterIterator($innerIterator, $filter));
// Add the files
$phar->buildFromIterator($iterator, __DIR__);
// Set the starting file
$phar->setStub($phar->createDefaultStub('./application.php'));
Ejemplo n.º 14
0
    $name = 'Hoa.phar';
}
if (file_exists($name) && false === unlink($name)) {
    throw new Hoa\Core\Exception('Phar %s already exists and we cannot delete it.', 1, $name);
}
class Filter extends FilterIterator
{
    public function accept()
    {
        return false === strpos($this->current()->getPathname(), '.git');
    }
}
$phar = new Phar(__DIR__ . DS . $name);
$phar->setMetadata(['author' => 'Ivan Enderlin, Hoa community', 'license' => 'New BSD License', 'copyright' => \Hoa\Core::©(), 'version.name' => $name, 'datetime' => date('c')]);
$phar->setSignatureAlgorithm(Phar::SHA1);
$phar->buildFromIterator(new Filter(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root))), $root);
$phar->setStub(<<<'STUB'
<?php

Phar::mapPhar('Hoa.phar');
require 'phar://Hoa.phar/Core/Core.php';

$phar = new Phar(__FILE__);

foreach (array_slice($_SERVER['argv'], 1) ?: ['-h'] as $option) {
    switch (strtolower($option)) {
        case '-m':
        case '--metadata':
            echo 'Metadata:' . "\n\n";
            $metadata = $phar->getMetadata();
            $max      = 0;
Ejemplo n.º 15
0
#!/usr/bin/env php
<?php 
define("APP_ROOT", realpath(__DIR__ . '/../'));
define("BUILD_DIR", APP_ROOT . '/build');
define("SRC_DIR", APP_ROOT . '/src');
define("PHAR_NAME", 'mysql-compare.phar');
if (!class_exists('Phar')) {
    exit("Phar class is required");
}
if (!Phar::canWrite()) {
    exit("phar.readonly must be set to 1\n");
}
$p = new Phar(PHAR_NAME, 0, PHAR_NAME);
// create transaction - nothing is written to newphar.phar
// until stopBuffering() is called, although temporary storage is needed
$p->startBuffering();
// add all files in /path/to/project, saving in the phar with the prefix "project"
$p->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(SRC_DIR)), APP_ROOT);
$p['src/test/dev.sql'] = file_get_contents(APP_ROOT . '/src/test/dev.sql');
$p['src/test/live.sql'] = file_get_contents(APP_ROOT . '/src/test/live.sql');
//$p->setMetadata(array('bootstrap' => SRC_DIR . '/dbcompare.php'));
$defaultStub = $p->createDefaultStub('src/dbcompare.php');
$stub = "#!/usr/bin/env php \n" . $defaultStub;
$p->setStub($stub);
// save the phar archive to disk
$p->stopBuffering();
if (file_exists(BUILD_DIR . '/' . PHAR_NAME)) {
    chmod(BUILD_DIR . '/' . PHAR_NAME, 0755);
}
Ejemplo n.º 16
0
 /**
  * @param Phar   $phar
  * @param string $baseDirectory
  */
 private function compressAllFiles(Phar $phar, $baseDirectory)
 {
     $total = 0;
     $phar->startBuffering();
     foreach ($this->filesets as $fileset) {
         $dir = $fileset->getDir($this->project);
         $msg = sprintf("Fileset %s ...", $dir);
         $this->log($msg, Project::MSG_VERBOSE);
         $added = $phar->buildFromIterator($fileset, $baseDirectory);
         $total += count($added);
     }
     $phar->stopBuffering();
     if (Phar::NONE === $this->compression) {
         return;
     }
     $msg = sprintf("Compressing %d files (compression: %s) ... ", $total, $this->getCompressionLabel());
     $this->log($msg, Project::MSG_VERBOSE);
     // safeguard open files soft limit
     if (function_exists('posix_getrlimit')) {
         $rlimit = posix_getrlimit();
         if ($rlimit['soft openfiles'] < $total + 5) {
             $msg = sprintf("Limit of openfiles (%d) is too low.", $rlimit['soft openfiles']);
             $this->log($msg, Project::MSG_VERBOSE);
         }
     }
     // safeguard compression
     try {
         $phar->compressFiles($this->compression);
     } catch (BadMethodCallException $e) {
         if ($e->getMessage() === 'unable to create temporary file') {
             $msg = sprintf("Info: Check openfiles limit it must be %d or higher", $total + 5);
             throw new BadMethodCallException($msg, 0, $e);
         }
         throw $e;
     }
 }
Ejemplo n.º 17
0
#!/usr/bin/env php
<?php 
$wd = sys_get_temp_dir();
$sourceDir = realpath(__DIR__ . "/../../../..");
$vendorDir = "{$sourceDir}/vendor";
$binDir = "{$vendorDir}/bin";
$srcDir = "{$sourceDir}/src";
$bundle = "bundle.phar";
$targetDir = "{$sourceDir}/target";
$bundleFile = "bundle.phar";
$bundle = "{$targetDir}/{$bundleFile}";
if (!file_exists($targetDir)) {
    if (!mkdir($targetDir)) {
        die("Could not create target dir {$targetDir}");
    }
}
if (file_exists($bundle)) {
    unlink($bundle);
}
$phar = new Phar($bundle, 0, $bundleFile);
$iterator = new AppendIterator();
$iterator->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcDir, FilesystemIterator::SKIP_DOTS)));
$iterator->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($vendorDir, FilesystemIterator::SKIP_DOTS | RecursiveDirectoryIterator::FOLLOW_SYMLINKS)));
$phar->buildFromIterator($iterator, $sourceDir);
$phar->setStub($phar->createDefaultStub("vendor/phasty/service/bin/service.php", "vendor/phasty/service/bin/service.php"));
Ejemplo n.º 18
0
<?php

/*
 * Copyright MADE/YOUR/DAY <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
$pharPath = __DIR__ . '/svg-icon-font-generator.phar';
if (file_exists($pharPath)) {
    unlink($pharPath);
}
$phar = new Phar($pharPath);
$phar->setStub($phar->createDefaultStub('run.php'));
$files = new AppendIterator();
$files->append(new ArrayIterator(array('run.php' => __DIR__ . '/run.php')));
$files->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/src', FilesystemIterator::SKIP_DOTS)));
$files->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/vendor', FilesystemIterator::SKIP_DOTS)));
$phar->buildFromIterator($files, __DIR__);
echo "created svg-icon-font-generator.phar\n";
Ejemplo n.º 19
0
 /**
  * Add vendor files without the unneeded dependencies
  *
  * @param Phar $phar
  */
 private function _addVendorFiles(\Phar $phar)
 {
     $tempDir = __DIR__ . DIRECTORY_SEPARATOR . 'temp_' . time();
     $jsonFile = $tempDir . DIRECTORY_SEPARATOR . 'composer.json';
     FileHelper::createDirectory($tempDir);
     copy($this->_sourceDir . DIRECTORY_SEPARATOR . 'composer.json', $jsonFile);
     $composer = Json::decode(file_get_contents($jsonFile));
     // Remove dev and unneeded dependencies:
     $composer['replace'] = ["ezyang/htmlpurifier" => "*", "yiisoft/jquery" => "*", "yiisoft/jquery-pjax" => "*", "cebe/markdown" => "*"];
     unset($composer['require-dev']);
     unset($composer['suggest']);
     unset($composer['scripts']);
     file_put_contents($jsonFile, Json::encode($composer));
     exec('cd ' . $tempDir . ' && php ../composer.phar update --prefer-dist');
     exec('cd ' . $tempDir . ' && php ../composer.phar dump-autoload --optimize');
     $phar->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempDir . DIRECTORY_SEPARATOR . 'vendor', FilesystemIterator::SKIP_DOTS)), $tempDir);
     FileHelper::removeDirectory($tempDir);
 }
Ejemplo n.º 20
0
        $fileName = $file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename();
        $fileIndex = substr($fileName, strlen($sourceLocation));
        //$fileName = $file->getPath().DIRECTORY_SEPARATOR.$file->getFilename();
        $files[$fileIndex] = $fileName;
        // Coined "phindex" to refer to the included index pointing to the real filename on disk we are creating
        if (isset($options['v'])) {
            echo "   PHIndex[{$fileIndex}] = {$fileName}\n";
        }
    }
}
echo "Now building the phar.\n";
/*
* Now build the archive.
*/
$p->startBuffering();
$p->buildFromIterator(new ArrayIterator($files));
$p->stopBuffering();
/*
* finish up.
*/
//$p->setStub($p->createDefaultStub(substr($stubFile, strlen($sourceLocation))));
$p->setDefaultStub(substr($stubFile, strlen($sourceLocation)));
$p = null;
if (isset($options['v'])) {
    echo count($files) . " files Added to " . $pharFile . "\n";
}
echo "Done.\n";
exit;
function displayHelp()
{
    echo "\n\npachage.php\n";
    {
        echo "current\n";
        return current($this->a);
    }
    function key()
    {
        echo "key\n";
        return key($this->a);
    }
    function valid()
    {
        echo "valid\n";
        return current($this->a);
    }
    function rewind()
    {
        echo "rewind\n";
        return reset($this->a);
    }
}
try {
    chdir(dirname(__FILE__));
    $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar');
    var_dump($phar->buildFromIterator(new myIterator(array(basename(__FILE__, 'php') . 'phpt'))));
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
Ejemplo n.º 22
0
<?php

## Создание PHAR-архива с заглушкой.
try {
    $phar = new Phar('./autopager.phar', 0, 'autopager.phar');
    // Для записи директив phar.readonly конфигурационного
    // файла php.ini должна быть установлена в 0 или Off
    if (Phar::canWrite()) {
        // Буферизация записи, ничего не записывается, до
        // тех пор, пока не будет вызван метод stopBuffering()
        $phar->startBuffering();
        // Добавление всех файлов из компонента ISPager
        $phar->buildFromIterator(new DirectoryIterator(realpath('../composer/pager/src/ISPager')), '../composer/pager/src');
        // Добавляем автозагрузчик в архив
        $phar->addFromString('autoloader.php', file_get_contents('autoloader.php'));
        // Назначаем автозагрузчик в качестве файла-заглушки
        $phar->setDefaultStub('autoloader.php', 'autoloader.php');
        // Сохранение результатов на жесткий диск
        $phar->stopBuffering();
    } else {
        echo 'PHAR-архив не может быть бы записан';
    }
} catch (Exception $e) {
    echo 'Невозможно открыть PHAR-архив: ', $e;
}
Ejemplo n.º 23
0
    }
    function key()
    {
        echo "key\n";
        return key($this->a);
    }
    function valid()
    {
        echo "valid\n";
        return current($this->a);
    }
    function rewind()
    {
        echo "rewind\n";
        return reset($this->a);
    }
}
try {
    $phar = new Phar(dirname(__FILE__) . '/buildfromiterator3.phar');
    $phar->buildFromIterator(new myIterator(array()), new stdClass());
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
<?php 
error_reporting(0);
unlink(dirname(__FILE__) . '/buildfromiterator3.phar');
__halt_compiler();
?>
Ejemplo n.º 24
0
<?php

try {
    chdir(dirname(__FILE__));
    $phar = new Phar(dirname(__FILE__) . '/buildfromiterator10.phar');
    $dir = new RecursiveDirectoryIterator('.');
    $iter = new RecursiveIteratorIterator($dir);
    $a = $phar->buildFromIterator(new RegexIterator($iter, '/_\\d{3}\\.phpt$/'), dirname(__FILE__) . DIRECTORY_SEPARATOR);
    asort($a);
    var_dump($a);
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
<?php 
error_reporting(0);
unlink(dirname(__FILE__) . '/buildfromiterator10.phar');
__halt_compiler();
?>
    {
        echo "current\n";
        return current($this->a);
    }
    function key()
    {
        echo "key\n";
        return key($this->a);
    }
    function valid()
    {
        echo "valid\n";
        return current($this->a);
    }
    function rewind()
    {
        echo "rewind\n";
        return reset($this->a);
    }
}
try {
    chdir(dirname(__FILE__));
    $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar');
    var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . '/oopsie/there.phpt'))));
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
Ejemplo n.º 26
0
    }
    function key()
    {
        echo "key\n";
        return key($this->a);
    }
    function valid()
    {
        echo "valid\n";
        return current($this->a);
    }
    function rewind()
    {
        echo "rewind\n";
        return reset($this->a);
    }
}
try {
    chdir(dirname(__FILE__));
    $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
    var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . 'phpt', '.phar/stub.php' => basename(__FILE__, 'php') . 'phpt', '.phar/alias.txt' => basename(__FILE__, 'php') . 'phpt', '.phar/oops' => basename(__FILE__, 'php') . 'phpt'))));
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
<?php 
unlink(dirname(__FILE__) . '/buildfromiterator.phar');
__halt_compiler();
?>
Ejemplo n.º 27
0
<?php

$mindbody = new Phar("mboapi.phar");
$mindbody->startBuffering();
$files = new AppendIterator();
$files->append(new DirectoryIterator("services"));
$files->append(new DirectoryIterator("structures"));
$mindbody->buildFromIterator($files, dirname(__FILE__));
$mindbody->addFile("LICENSE");
$mindbody->addFile("README.markdown");
$mindbody->addFromString("loadServices.php", "<?php\n\tinclude_once(\"services/Appointment_Service.php\");\n\tinclude_once(\"services/Class_Service.php\");\n\tinclude_once(\"services/Client_Service.php\");\n\tinclude_once(\"services/Sale_Service.php\");\n\tinclude_once(\"services/Site_Service.php\");\n\tinclude_once(\"services/Staff_Service.php\");\n\tinclude_once(\"services/Data_Service.php\");\n\tinclude_once(\"services/Finder_Service.php\");\n?>");
$mindbody->setStub($mindbody->createDefaultStub("loadServices.php"));
$mindbody->stopBuffering();
foreach (new RecursiveIteratorIterator($mindbody) as $file) {
    echo $file->getFileName() . "\n";
}
Ejemplo n.º 28
0
<?php

$phar = new Phar(dirname(__FILE__) . '/buildfromiterator1.phar');
try {
    ini_set('phar.readonly', 1);
    $phar->buildFromIterator(1);
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
<?php 
unlink(dirname(__FILE__) . '/buildfromiterator1.phar');
__halt_compiler();
?>
Ejemplo n.º 29
0
    function key()
    {
        echo "key\n";
        return key($this->a);
    }
    function valid()
    {
        echo "valid\n";
        return current($this->a);
    }
    function rewind()
    {
        echo "rewind\n";
        return reset($this->a);
    }
}
try {
    chdir(dirname(__FILE__));
    $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar');
    var_dump($phar->buildFromIterator(new myIterator(array('a' => $a = fopen(basename(__FILE__, 'php') . 'phpt', 'r')))));
    fclose($a);
} catch (Exception $e) {
    var_dump(get_class($e));
    echo $e->getMessage() . "\n";
}
?>
===DONE===
<?php 
unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar');
__halt_compiler();
?>
Ejemplo n.º 30
0
<?php

$archive = new Phar('regression.phar');
$base = dirname(__FILE__);
$archive->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($base . '/src')), $base);
$archive->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($base . '/vendor')), $base);
$archive->setStub(Phar::createDefaultStub('vendor/autoload.php'));