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


PHP Phar::setDefaultStub方法代码示例

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


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

示例1: testReading

    /**
     * Test that the reading is successful.
     *
     * @return void
     *
     * @dataProvider testReadingFlagsProvider
     */
    public function testReading($compression, $signatureName, $signatureFlag)
    {
        $pharfile = $this->getTempFile('temp.phar');
        $phar = new \Phar($pharfile, 0, 'temp.phar');
        $phar->startBuffering();
        $phar->addFromString('/bin/script', $fileData = <<<EOF
#!/usr/bin/php
<?php
echo 'hello world';
EOF
);
        $phar->setDefaultStub('/bin/script', '/web/index');
        $phar->stopBuffering();
        $phar->setSignatureAlgorithm($signatureFlag);
        if ($compression !== \Phar::NONE) {
            $phar->compressFiles($compression);
        }
        unset($phar);
        $reader = new PharReader();
        $phar = $reader->load($pharfile);
        $this->assertEquals('temp.phar', $phar->getAlias());
        $this->assertTrue($phar->isSigned());
        $this->assertEquals($signatureName, $phar->getSignatureAlgorithm());
        $files = $phar->getFiles();
        $this->assertEquals('bin/script', $files[0]->getFilename());
        $this->assertEquals($fileData, $files[0]->getContent());
    }
开发者ID:cyberspectrum,项目名称:pharpiler,代码行数:34,代码来源:PharReaderTest.php

示例2: compile

 public function compile()
 {
     if (file_exists('symfony.phar')) {
         unlink('symfony.phar');
     }
     $phar = new \Phar('symfony.phar', 0, 'Symfony');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     // Files
     foreach ($this->getFiles() as $file) {
         $path = str_replace(__DIR__ . '/', '', $file);
         if (false !== strpos($file, '.php')) {
             $content = Kernel::stripComments(file_get_contents($file));
         } else {
             $content = file_get_contents($file);
         }
         $phar->addFromString($path, $content);
     }
     // Stubs
     $phar['_cli_stub.php'] = $this->getCliStub();
     $phar['_web_stub.php'] = $this->getWebStub();
     $phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
     $phar->stopBuffering();
     //$phar->compressFiles(\Phar::GZ);
     unset($phar);
 }
开发者ID:kawahara,项目名称:symfony-bootstrapper,代码行数:26,代码来源:Compiler.php

示例3: buildModulePhar

function buildModulePhar($name, $format = Phar::PHAR, $compression = Phar::NONE, $executable = true, $fake = false)
{
    echo "Building {$name}...\t";
    $glob = glob($name.'.*');
    if (count($glob) > 0) {
        foreach ($glob as $file) {
            if (!is_dir($file)) {
                unlink($file);
            }   
        }
    }
    $filename = $name . '.phar';
    $phar = new Phar($filename);
    if ($fake) {
        $phar['Module.php'] = '<?php //no class here';
    } else {
        $phar['Module.php'] = "<?php \n\nnamespace $name;\n\nclass Module\n{}";
    }
    if (false === $executable) {
        $phar->convertToData($format, $compression);
    } else {
        $phar->setDefaultStub('Module.php', 'Module.php');
        if ($format !== Phar::PHAR || $compression !== Phar::NONE) {
            $phar->convertToExecutable($format, $compression);
        }
    }
    if ($format !== Phar::PHAR || $compression !== Phar::NONE) {
        unlink($filename);
    }
    echo "Done!\n";
}
开发者ID:noose,项目名称:zf2,代码行数:31,代码来源:_buildPhars.php

示例4: compile

 public function compile($pharFile = 'goutte.phar')
 {
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $phar = new \Phar($pharFile, 0, 'Goutte');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     // CLI Component files
     foreach ($this->getFiles() as $file) {
         $path = str_replace(__DIR__ . '/', '', $file);
         $phar->addFromString($path, file_get_contents($file));
     }
     // Stubs
     $phar['_cli_stub.php'] = $this->getCliStub();
     $phar['_web_stub.php'] = $this->getWebStub();
     $phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
     $phar->stopBuffering();
     // $phar->compressFiles(\Phar::GZ);
     unset($phar);
 }
开发者ID:yanniboi,项目名称:github_drupalorg,代码行数:21,代码来源:Compiler.php

示例5: compile

 public function compile($pharFile = 'silex.phar')
 {
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $phar = new \Phar($pharFile, 0, 'Silex');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = new Finder();
     $finder->files()->name('*.php')->exclude('tests')->in(__DIR__ . '/..');
     foreach ($finder as $file) {
         $path = str_replace(realpath(__DIR__ . '/../..') . '/', '', realpath($file));
         $content = Kernel::stripComments(file_get_contents($file));
         $phar->addFromString($path, $content);
     }
     // Stubs
     $phar['_cli_stub.php'] = $this->getStub();
     $phar['_web_stub.php'] = $this->getStub();
     $phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
     $phar->stopBuffering();
     // $phar->compressFiles(\Phar::GZ);
     unset($phar);
 }
开发者ID:radek-baczynski,项目名称:Silex,代码行数:23,代码来源:Compiler.php

示例6: buildPhar

 /**
  * Build and configure Phar object.
  *
  * @return Phar
  */
 private function buildPhar()
 {
     $phar = new Phar($this->destinationFile);
     if (!empty($this->stubPath)) {
         $phar->setStub(file_get_contents($this->stubPath));
     } else {
         if (!empty($this->cliStubFile)) {
             $cliStubFile = $this->cliStubFile->getPathWithoutBase($this->baseDirectory);
         } else {
             $cliStubFile = null;
         }
         if (!empty($this->webStubFile)) {
             $webStubFile = $this->webStubFile->getPathWithoutBase($this->baseDirectory);
         } else {
             $webStubFile = null;
         }
         $phar->setDefaultStub($cliStubFile, $webStubFile);
     }
     if ($this->metadata === null) {
         $this->createMetaData();
     }
     if ($metadata = $this->metadata->toArray()) {
         $phar->setMetadata($metadata);
     }
     if (!empty($this->alias)) {
         $phar->setAlias($this->alias);
     }
     return $phar;
 }
开发者ID:tammyd,项目名称:phing,代码行数:34,代码来源:PharPackageTask.php

示例7: dirname

<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
$phar = new Phar($fname);
$phar['a.php'] = '<php echo "this is a\\n"; ?>';
$phar['b.php'] = '<php echo "this is b\\n"; ?>';
$phar->setDefaultStub();
$phar->stopBuffering();
var_dump($phar->getStub());
echo "============================================================================\n";
echo "============================================================================\n";
$phar->setDefaultStub('my/custom/thingy.php');
$phar->stopBuffering();
var_dump($phar->getStub());
echo "============================================================================\n";
echo "============================================================================\n";
$phar->setDefaultStub('my/custom/thingy.php', 'the/web.php');
$phar->stopBuffering();
var_dump($phar->getStub());
echo "============================================================================\n";
echo "============================================================================\n";
try {
    $phar->setDefaultStub(str_repeat('a', 400));
    $phar->stopBuffering();
    var_dump(strlen($phar->getStub()));
    $phar->setDefaultStub(str_repeat('a', 401));
    $phar->stopBuffering();
    var_dump(strlen($phar->getStub()));
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
开发者ID:zaky-92,项目名称:php-1,代码行数:31,代码来源:ext_phar_tests_phar_setdefaultstub.php

示例8: Exception

<?php

set_error_handler(function ($num, $msg, $file, $line) {
    throw new Exception($msg, 0, $num, $file, $line);
});
$targetDirPath = __DIR__ . '/target';
if (!file_exists($targetDirPath)) {
    mkdir($targetDirPath);
}
$phar = new Phar($targetDirPath . '/lightship.phar', 0, 'lightship.phar');
$phar->buildFromDirectory(__DIR__ . '/src/Lightship/Bin/lightship/');
$phar->setDefaultStub('lightship.php');
开发者ID:solarfield,项目名称:lightship-bin-php,代码行数:12,代码来源:build.php

示例9: Phar

<?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;
}
开发者ID:igorsimdyanov,项目名称:php7,代码行数:25,代码来源:stub.php

示例10: Phar

<?

$sLibraryPath = 'lib/SampleLibrary.phar';

// we will build library in case if it not exist
if (! file_exists($sLibraryPath)) {
    ini_set("phar.readonly", 0); // Could be done in php.ini

    $oPhar = new Phar($sLibraryPath); // creating new Phar
    $oPhar->setDefaultStub('index.php', 'classes/index.php'); // pointing main file which require all classes
    $oPhar->buildFromDirectory('classes/'); // creating our library using whole directory

    $oPhar->compress(Phar::GZ); // plus - compressing it into gzip
}

// when library already compiled - we will using it
require_once('phar://'.$sLibraryPath.'.gz');

// demonstration of work
$oClass1 = new SampleClass();
echo $oClass1->getAnyContent();
echo '<pre>';
print_r($oClass1);
echo '</pre>';

$oClass2 = new SampleClass2();
echo $oClass2->getAnyContent();
echo $oClass2->getContent2();
echo '<pre>';
print_r($oClass2);
echo '</pre>';
开发者ID:karloleary,项目名称:phar-template-generator,代码行数:31,代码来源:index.php

示例11: dirname

<?php

$fname = dirname(__FILE__) . '/tempmanifest2.phar.php';
$pname = 'phar://' . $fname;
$phar = new Phar($fname);
$phar->setDefaultStub();
$phar->setAlias('fred');
$phar['file1.txt'] = 'hi';
$phar['file2.txt'] = 'hi2';
$phar['subdir/ectory/file.txt'] = 'hi3';
$phar->mount($pname . '/mount2', __FILE__);
$phar->addEmptyDir('one/level');
$phar->extractTo(dirname(__FILE__) . '/extract2', 'mount2');
$phar->extractTo(dirname(__FILE__) . '/extract2');
$out = array();
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/extract2', 0x3000), RecursiveIteratorIterator::CHILD_FIRST) as $path => $file) {
    $extracted[] = $path;
}
sort($extracted);
foreach ($extracted as $out) {
    echo "{$out}\n";
}
?>
===DONE===
<?php 
@unlink(dirname(__FILE__) . '/tempmanifest2.phar.php');
$dir = dirname(__FILE__) . '/extract2/';
@unlink($dir . 'file1.txt');
@unlink($dir . 'file2.txt');
@unlink($dir . 'subdir/ectory/file.txt');
@rmdir($dir . 'subdir/ectory');
开发者ID:alphaxxl,项目名称:hhvm,代码行数:31,代码来源:phar_extract2.php

示例12: Phar

<?php

## Хранение бинарных файлов.
try {
    $phar = new Phar('./gallery.phar', 0, 'gallery.phar');
    // Для записи директив phar.readonly конфигурационного
    // файла php.ini должна быть установлена в 0 или Off
    if (Phar::canWrite()) {
        // Буферизация записи, ничего не записывается, до
        // тех пор, пока не будет вызван метод stopBuffering()
        $phar->startBuffering();
        // Добавление всех файлов из папки photos
        foreach (glob('../composer/photos/*') as $jpg) {
            $phar[basename($jpg)] = file_get_contents($jpg);
        }
        // Назначаем файл-заглушку
        $phar['show.php'] = file_get_contents('show.php');
        $phar->setDefaultStub('show.php', 'show.php');
        // Сохранение результатов на жесткий диск
        $phar->stopBuffering();
    } else {
        echo 'PHAR-архив не может быть бы записан';
    }
} catch (Exception $e) {
    echo 'Невозможно открыть PHAR-архив: ', $e;
}
开发者ID:igorsimdyanov,项目名称:php7,代码行数:26,代码来源:gallery_phar.php

示例13: buildPhar

 /**
  * Build and configure Phar object.
  *
  * @return Phar
  */
 private function buildPhar()
 {
     $phar = new Phar($this->destinationFile);
     $phar->setSignatureAlgorithm($this->signatureAlgorithm);
     if (isset($this->stubPath)) {
         $phar->setStub(file_get_contents($this->stubPath));
     } else {
         $phar->setDefaultStub($this->cliStubFile->getPathWithoutBase($this->baseDirectory), $this->webStubFile->getPathWithoutBase($this->baseDirectory));
     }
     if ($metadata = $this->metadata->toArray()) {
         $phar->setMetadata($metadata);
     }
     if (!empty($this->alias)) {
         $phar->setAlias($this->alias);
     }
     return $phar;
 }
开发者ID:altesien,项目名称:FinalProject,代码行数:22,代码来源:PharPackageTask.php

示例14: Phar

<?php

$sLibraryPath = '../CompiledPHAR/SecurityCheck_compiled.phar';
if (file_exists($sLibraryPath)) {
    @unlink($sLibraryPath);
}
if (file_exists($sLibraryPath . ".gz")) {
    @unlink($sLibraryPath . ".gz");
}
if (!file_exists($sLibraryPath)) {
    ini_set("phar.readonly", 0);
    // Could be done in php.ini
    $oPhar = new Phar($sLibraryPath);
    // creating new Phar
    $oPhar->setDefaultStub('index.php', '../SecurityCheck/index.php');
    // pointing main file which require all classes
    $oPhar->buildFromDirectory('../SecurityCheck/');
    // creating our library using whole directory
    $oPhar->compress(Phar::GZ);
    // plus - compressing it into gzip
}
开发者ID:beejhuff,项目名称:PHP-Security,代码行数:21,代码来源:compilePHAR.php

示例15: testWriteLoaded

    /**
     * Test that the writing of a loaded phar results in an equal file.
     *
     * @return void
     *
     * @dataProvider testWritingFlagsProvider
     */
    public function testWriteLoaded($compression, $signatureFlag)
    {
        $pharfile = $this->getTempFile('temp.phar');
        $phar = new \Phar($pharfile, 0, 'temp.phar');
        $phar->startBuffering();
        $phar->addFromString('/bin/script', $fileData = <<<EOF
#!/usr/bin/php
<?php
echo 'hello world';
EOF
);
        $phar->setDefaultStub('/bin/script', '/web/index');
        $phar->stopBuffering();
        if (0 !== $signatureFlag) {
            $phar->setSignatureAlgorithm($signatureFlag);
        }
        if ($compression !== \Phar::NONE) {
            $phar->compress($compression);
        }
        unset($phar);
        $reader = new PharReader();
        $phar = $reader->load($pharfile);
        $pharfile2 = $this->getTempFile('temp.phar');
        $writer = new PharWriter();
        $writer->save($phar, $pharfile2);
        unset($writer);
        $this->assertFileEquals($pharfile, $pharfile2);
    }
开发者ID:cyberspectrum,项目名称:pharpiler,代码行数:35,代码来源:PharWriterTest.php


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