本文整理汇总了PHP中Symfony\Component\HttpKernel\Kernel::stripComments方法的典型用法代码示例。如果您正苦于以下问题:PHP Kernel::stripComments方法的具体用法?PHP Kernel::stripComments怎么用?PHP Kernel::stripComments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Kernel
的用法示例。
在下文中一共展示了Kernel::stripComments方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: stripComments
private static function stripComments($content)
{
if (class_exists(Kernel::class)) {
$content = Kernel::stripComments($content);
}
return $content;
}
示例3: addFile
protected function addFile($phar, $file, $strip = true)
{
$path = str_replace(realpath(__DIR__ . '/../..') . '/', '', $file->getRealPath());
$content = file_get_contents($file);
if ($strip) {
$content = Kernel::stripComments(file_get_contents($file));
}
$phar->addFromString($path, $content);
}
示例4: addFile
protected function addFile($phar, $file, $strip = true)
{
$path = str_replace(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
$content = file_get_contents($file);
if ($strip) {
$content = Kernel::stripComments($content);
}
$phar->addFromString($path, $content);
}
示例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);
}
示例6: testStripComments
public function testStripComments()
{
$source = <<<'EOF'
<?php
$string = 'string should not be modified';
$string = 'string should not be
modified';
$heredoc = <<<HD
Heredoc should not be modified {$a[1+$b]}
HD;
$nowdoc = <<<'ND'
Nowdoc should not be modified
ND;
/**
* some class comments to strip
*/
class TestClass
{
/**
* some method comments to strip
*/
public function doStuff()
{
// inline comment
}
}
EOF;
$expected = <<<'EOF'
<?php
$string = 'string should not be modified';
$string = 'string should not be
modified';
$heredoc = <<<HD
Heredoc should not be modified {$a[1+$b]}
HD;
$nowdoc = <<<'ND'
Nowdoc should not be modified
ND;
class TestClass
{
public function doStuff()
{
}
}
EOF;
$output = Kernel::stripComments($source);
// Heredocs are preserved, making the output mixing Unix and Windows line
// endings, switching to "\n" everywhere on Windows to avoid failure.
if ('\\' === DIRECTORY_SEPARATOR) {
$expected = str_replace("\r\n", "\n", $expected);
$output = str_replace("\r\n", "\n", $output);
}
$this->assertEquals($expected, $output);
}
示例7: addProxyClasses
/**
* Generates code for the proxies to be attached after the container class.
*
* @return string
*/
private function addProxyClasses()
{
/* @var $definitions Definition[] */
$definitions = array_filter($this->container->getDefinitions(), array($this->getProxyDumper(), 'isProxyCandidate'));
$code = '';
$strip = '' === $this->docStar && method_exists('Symfony\\Component\\HttpKernel\\Kernel', 'stripComments');
foreach ($definitions as $definition) {
$proxyCode = "\n" . $this->getProxyDumper()->getProxyCode($definition);
if ($strip) {
$proxyCode = "<?php\n" . $proxyCode;
$proxyCode = substr(Kernel::stripComments($proxyCode), 5);
}
$code .= $proxyCode;
}
return $code;
}
示例8: testStripComments
public function testStripComments()
{
if (!function_exists('token_get_all')) {
$this->markTestSkipped('The function token_get_all() is not available.');
return;
}
$source = <<<'EOF'
<?php
$string = 'string should not be modified';
$string = 'string should not be
modified';
$heredoc = <<<HD
Heredoc should not be modified
HD;
$nowdoc = <<<'ND'
Nowdoc should not be modified
ND;
/**
* some class comments to strip
*/
class TestClass
{
/**
* some method comments to strip
*/
public function doStuff()
{
// inline comment
}
}
EOF;
$expected = <<<'EOF'
<?php
$string = 'string should not be modified';
$string = 'string should not be
modified';
$heredoc = <<<HD
Heredoc should not be modified
HD;
$nowdoc = <<<'ND'
Nowdoc should not be modified
ND;
class TestClass
{
public function doStuff()
{
}
}
EOF;
$output = Kernel::stripComments($source);
// Heredocs are preserved, making the output mixing Unix and Windows line
// endings, switching to "\n" everywhere on Windows to avoid failure.
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
$expected = str_replace("\r\n", "\n", $expected);
$output = str_replace("\r\n", "\n", $output);
}
$this->assertEquals($expected, $output);
}
示例9: testStripComments
public function testStripComments()
{
if (!function_exists('token_get_all')) {
$this->markTestSkipped();
return;
}
$source = <<<EOF
<?php
/**
* some class comments to strip
*/
class TestClass
{
/**
* some method comments to strip
*/
public function doStuff()
{
// inline comment
}
}
EOF;
$expected = <<<EOF
<?php
class TestClass
{
public function doStuff()
{
}
}
EOF;
$this->assertEquals($expected, Kernel::stripComments($source));
}
示例10: dumpContainer
/**
* Dumps the service container to PHP code in the cache.
*
* @param ConfigCache $cache The config cache
* @param ContainerBuilder $container The service container
* @param string $class The name of the class to generate
* @param string $baseClass The name of the container's base class
*/
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
{
// cache the container
$dumper = new PhpDumper($container);
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass));
if (!$this->debug) {
$content = SymfonyKernel::stripComments($content);
}
$cache->write($content, $container->getResources());
}
示例11: testStripComments
public function testStripComments()
{
if (!function_exists('token_get_all')) {
$this->markTestSkipped('The function token_get_all() is not available.');
return;
}
$source = <<<'EOF'
<?php
$string = 'string should not be modified';
$heredoc = <<<HD
Heredoc should not be modified
HD;
$nowdoc = <<<'ND'
Nowdoc should not be modified
ND;
/**
* some class comments to strip
*/
class TestClass
{
/**
* some method comments to strip
*/
public function doStuff()
{
// inline comment
}
}
EOF;
$expected = <<<'EOF'
<?php
$string = 'string should not be modified';
$heredoc =
<<<HD
Heredoc should not be modified
HD;
$nowdoc =
<<<'ND'
Nowdoc should not be modified
ND;
class TestClass
{
public function doStuff()
{
}
}
EOF;
$this->assertEquals($expected, Kernel::stripComments($source));
}