当前位置: 首页>>代码示例>>PHP>>正文


PHP Phar::buildFromIterator方法代码示例

本文整理汇总了PHP中Phar::buildFromIterator方法的典型用法代码示例。如果您正苦于以下问题:PHP Phar::buildFromIterator方法的具体用法?PHP Phar::buildFromIterator怎么用?PHP Phar::buildFromIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phar的用法示例。


在下文中一共展示了Phar::buildFromIterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: makePhar

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;
}
开发者ID:elandio,项目名称:pizza-10,代码行数:56,代码来源:makephar.php

示例2: build

 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();
 }
开发者ID:hco,项目名称:Autoload,代码行数:24,代码来源:PharBuilder.php

示例3: Phar

<?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();
?>
开发者ID:alphaxxl,项目名称:hhvm,代码行数:15,代码来源:phar_buildfromiterator2.php

示例4: addFilesFromIterator

 /**
  * 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));
 }
开发者ID:index0h,项目名称:yii2-phar,代码行数:11,代码来源:Builder.php

示例5: buildFromIterator

 function buildFromIterator(Iterator $it, $base_dir = null)
 {
     foreach ($it as $f) {
         $this->addFileToHash($f);
     }
     parent::buildFromIterator($it, $base_dir);
 }
开发者ID:fjg,项目名称:sacy,代码行数:7,代码来源:build.php

示例6: Phar

 *   * 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();
开发者ID:KnpLabs,项目名称:phpunit-easyinstall,代码行数:31,代码来源:make_phar.php

示例7: Phar

#!/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);
开发者ID:jlkaufman,项目名称:blackhole-bot,代码行数:30,代码来源:build.php

示例8: chdir

<?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();
?>
开发者ID:badlamer,项目名称:hhvm,代码行数:20,代码来源:phar_buildfromiterator8.php

示例9: createScaffolderCommand

 /**
  * 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));
 }
开发者ID:jkimdon,项目名称:cohomeals,代码行数:14,代码来源:Package.php

示例10: key

    }
    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();
?>
开发者ID:alphaxxl,项目名称:hhvm,代码行数:31,代码来源:phar_buildfromiterator5.php

示例11: key

        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===
开发者ID:gleamingthecube,项目名称:php,代码行数:30,代码来源:ext_phar_tests_bug45218_SLOWTESTU.php

示例12: unlink

$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
开发者ID:simondubois,项目名称:unsplash-downloader,代码行数:31,代码来源:create-phar.php

示例13: function

 * @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'));
开发者ID:erickmarsh,项目名称:CacheWarmer,代码行数:31,代码来源:build.php

示例14: accept

    $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;
开发者ID:Grummfy,项目名称:Central,代码行数:31,代码来源:Phar.php

示例15: realpath

#!/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);
}
开发者ID:sickhye,项目名称:mysql-dbcompare,代码行数:29,代码来源:build-phar.php


注:本文中的Phar::buildFromIterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。