本文整理汇总了PHP中php_strip_whitespace函数的典型用法代码示例。如果您正苦于以下问题:PHP php_strip_whitespace函数的具体用法?PHP php_strip_whitespace怎么用?PHP php_strip_whitespace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了php_strip_whitespace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
public function compile($pharFile, $name = 'foo-app', array $files = array(), array $directories = array(), $stub_file, $base_path, $name_pattern = '*.php', $strip = TRUE)
{
if (file_exists($pharFile)) {
unlink($pharFile);
}
$phar = new \Phar($pharFile, 0, $name);
// The signature is automatically set unless we decide to compress. In that
// case we have to manually set it. Setting to the default just in case.
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
// CLI Component files
$iterator = Finder::create()->files()->name($name_pattern)->in($directories);
// We need to set the adapter to use the PhpAdapter because we are working
// with Phar files and the higher priority ones by default in symfony can
// run into issues.
//$iterator->removeAdapters();
//$iterator->addAdapter(new PhpAdapter());
$files = array_merge($files, iterator_to_array($iterator));
foreach ($files as $file) {
$path = str_replace($base_path . '/', '', $file);
if ($strip) {
$phar->addFromString($path, php_strip_whitespace($file));
} else {
$phar->addFromString($path, file_get_contents($file));
}
}
$phar->setStub(file_get_contents($stub_file));
$phar->stopBuffering();
// Not all systems support compressed Phars. For now disabling.
// $phar->compressFiles(\Phar::GZ);
chmod($pharFile, 0755);
unset($phar);
}
示例2: buildCacheContent
protected function buildCacheContent($module)
{
$content = '';
$path = realpath(APP_PATH . $module) . DS;
// 加载模块配置
$config = \think\Config::load(CONF_PATH . $module . 'config' . CONF_EXT);
// 加载应用状态配置
if ($module && $config['app_status']) {
$config = \think\Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
}
// 读取扩展配置文件
if ($module && $config['extra_config_list']) {
foreach ($config['extra_config_list'] as $name => $file) {
$filename = CONF_PATH . $module . $file . CONF_EXT;
\think\Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
}
}
// 加载别名文件
if (is_file(CONF_PATH . $module . 'alias' . EXT)) {
$content .= '\\think\\Loader::addClassMap(' . var_export(include CONF_PATH . $module . 'alias' . EXT, true) . ');' . PHP_EOL;
}
// 加载行为扩展文件
if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
$content .= '\\think\\Hook::import(' . var_export(include CONF_PATH . $module . 'tags' . EXT, true) . ');' . PHP_EOL;
}
// 加载公共文件
if (is_file($path . 'common' . EXT)) {
$content .= substr(php_strip_whitespace($path . 'common' . EXT), 5) . PHP_EOL;
}
$content .= '\\think\\Config::set(' . var_export(\think\Config::get(), true) . ');';
return $content;
}
示例3: loadFile
protected function loadFile($file)
{
$striped = "";
// remove all whitespaces and comments
// replace short tags
$t = token_get_all(str_replace('<?=', '<?php echo ', php_strip_whitespace($file)));
$blacklist = array(T_AS, T_CASE, T_INSTANCEOF, T_USE);
foreach ($t as $i => $token) {
if (is_string($token)) {
$striped .= $token;
} elseif (T_WHITESPACE === $token[0]) {
if (isset($t[$i + 1]) && is_array($t[$i + 1])) {
if (in_array($t[$i + 1][0], $blacklist)) {
$striped .= $t[$i][1];
continue;
}
if (isset($t[$i - 1]) && is_array($t[$i - 1])) {
if (in_array($t[$i - 1][0], $blacklist)) {
$striped .= $t[$i][1];
continue;
}
if ($t[$i - 1][0] == T_ECHO || $t[$i - 1][0] == T_PRINT) {
$striped .= $t[$i][1];
continue;
}
}
}
$striped .= str_replace(' ', '', $token[1]);
} else {
$striped .= $token[1];
}
}
$this->buffer = $striped;
}
示例4: addModule
public function addModule($matches)
{
$matches[1] = str_replace(' AS ', ' as ', $matches[1]);
$moduleVar = explode(' as ', $matches[1]);
$moduleVar[0] = trim($moduleVar[0]);
if (isset($moduleVar[1])) {
$moduleVar[1] = trim($moduleVar[1]);
}
$query = explode('?', $moduleVar[0]);
$file = __MODULE__ . '/' . $this->getModulePath($query[0]);
if (file_exists($file)) {
$this->className = $this->getClassName($query[0]);
$nameSpace = isset($moduleVar[1]) ? $moduleVar[1] : $query[0];
if (isset($this->module[$nameSpace])) {
$this->throwException(E_ACTION_BUILD_NAMESPACEBEENUSED, $nameSpace);
}
$this->module[$nameSpace] = $this->className[1];
if (isset($query[1])) {
parse_str($query[1], $this->args[$nameSpace]);
}
if (!isset($this->moduleFile[$file])) {
$this->moduleFile[$file] = filemtime($file);
$this->moduleSource .= $this->replaceClassName(mgGetScript(php_strip_whitespace($file)), $this->className);
}
} else {
$this->throwException(E_ACTION_TEMPLATEBUILD_MODULEFILENOTEXISTS, $file);
}
return NULL;
}
示例5: read
/**
* Returns the stream without Php comments and whitespace.
*
* @return the resulting stream, or -1
* if the end of the resulting stream has been reached
*
* @throws IOException if the underlying stream throws an IOException
* during reading
*/
function read($len = null)
{
if ($this->processed === true) {
return -1;
// EOF
}
// Read XML
$php = null;
while (($buffer = $this->in->read($len)) !== -1) {
$php .= $buffer;
}
if ($php === null) {
// EOF?
return -1;
}
if (empty($php)) {
$this->log("PHP file is empty!", Project::MSG_WARN);
return '';
// return empty string, don't attempt to strip whitespace
}
// write buffer to a temporary file, since php_strip_whitespace() needs a filename
$file = new PhingFile(tempnam(PhingFile::getTempDir(), 'stripwhitespace'));
file_put_contents($file->getAbsolutePath(), $php);
$output = php_strip_whitespace($file->getAbsolutePath());
unlink($file->getAbsolutePath());
$this->processed = true;
return $output;
}
示例6: testPluginClassForClosureCall
protected function testPluginClassForClosureCall($class)
{
$reflection = new \ReflectionClass($class);
$methods = $reflection->getMethods();
foreach ($methods as $method) {
if (strpos($method->getName(), 'around') !== 0) {
continue;
}
$parameters = $method->getParameters();
$chain_closure = $parameters[1];
$chain_closure_var_name = $chain_closure->getName();
$lines = file($method->getFilename());
array_unshift($lines, '');
$method_lines = array_splice($lines, $method->getStartLine(), $method->getEndLine() - $method->getStartLine());
$path = tempnam('/tmp', 'forstrip');
$method_text = implode('', $method_lines);
file_put_contents($path, '<' . '?' . 'php' . "\n" . $method_text);
$method_text = php_strip_whitespace($path);
unlink($path);
if (strpos($method_text, '$' . $chain_closure_var_name . '(') === false) {
echo $class, " : ";
echo 'FAILED: ', ' could not find ' . '$' . $chain_closure_var_name . '()', "\n";
echo ' ' . $reflection->getFilename(), "\n";
echo ' ' . $method->getFilename(), "\n";
} else {
// echo $class," : ";
// echo 'PASSED',"\n";
}
}
}
示例7: seeMinimizedFile
public function seeMinimizedFile($file, $relativePathAsArray)
{
$realFile = $this->createFileEvent($relativePathAsArray);
$expected = php_strip_whitespace($realFile->realPath);
$actual = file_get_contents($file->realPath);
$this->assertEquals($expected, $actual);
}
示例8: print_files
function print_files()
{
$data = array();
//should declare array to be used to hold valid input files
echo '<b>Ingesting the data files that are in the data directory!</b>';
echo '<br>*******************************************************<br>';
$dirfiles = listdir(ES__PLUGIN_DIR . "data");
if ($dirfiles) {
foreach ($dirfiles as $key => $filename) {
if (substr($filename, -4) == '.txt' && !is_dir($filename)) {
$data[$filename] = php_strip_whitespace($filename);
$theData = make_post($filename);
insert_post($theData);
echo "<br>";
echo "<br>Finished.";
echo "<br>";
} else {
$other[$filename] = !is_dir($filename) ? file_get_contents($filename) : '';
}
}
$myFile = ES__PLUGIN_DIR . "/data/test.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
}
insert_post($theData);
echo "<br>";
echo "<br>Finished.";
echo "<br>";
}
示例9: findClasses
private static function findClasses($path)
{
$extraTypes = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait';
if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) {
$extraTypes .= '|enum';
}
try {
$contents = @php_strip_whitespace($path);
if (!$contents) {
if (!file_exists($path)) {
throw new \Exception('File does not exist');
}
if (!is_readable($path)) {
throw new \Exception('File is not readable');
}
}
} catch (\Exception $e) {
throw new \RuntimeException('Could not scan for classes inside ' . $path . ": \n" . $e->getMessage(), 0, $e);
}
if (!preg_match('{\\b(?:class|interface' . $extraTypes . ')\\s}i', $contents)) {
return array();
}
$contents = preg_replace('{<<<\\s*(\'?)(\\w+)\\1(?:\\r\\n|\\n|\\r)(?:.*?)(?:\\r\\n|\\n|\\r)\\2(?=\\r\\n|\\n|\\r|;)}s', 'null', $contents);
$contents = preg_replace('{"[^"\\\\]*(\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(\\\\.[^\'\\\\]*)*\'}s', 'null', $contents);
if (substr($contents, 0, 2) !== '<?') {
$contents = preg_replace('{^.+?<\\?}s', '<?', $contents, 1, $replacements);
if ($replacements === 0) {
return array();
}
}
$contents = preg_replace('{\\?>.+<\\?}s', '?><?', $contents);
$pos = strrpos($contents, '?>');
if (false !== $pos && false === strpos(substr($contents, $pos), '<?')) {
$contents = substr($contents, 0, $pos);
}
preg_match_all('{
(?:
\\b(?<![\\$:>])(?P<type>class|interface' . $extraTypes . ') \\s+ (?P<name>[a-zA-Z_\\x7f-\\xff:][a-zA-Z0-9_\\x7f-\\xff:\\-]*)
| \\b(?<![\\$:>])(?P<ns>namespace) (?P<nsname>\\s+[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?:\\s*\\\\\\s*[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*)? \\s*[\\{;]
)
}ix', $contents, $matches);
$classes = array();
$namespace = '';
for ($i = 0, $len = count($matches['type']); $i < $len; $i++) {
if (!empty($matches['ns'][$i])) {
$namespace = str_replace(array(' ', "\t", "\r", "\n"), '', $matches['nsname'][$i]) . '\\';
} else {
$name = $matches['name'][$i];
if ($name[0] === ':') {
$name = 'xhp' . substr(str_replace(array('-', ':'), array('_', '__'), $name), 1);
} else {
if ($matches['type'][$i] === 'enum') {
$name = rtrim($name, ':');
}
}
$classes[] = ltrim($namespace . $name, '\\');
}
}
return $classes;
}
示例10: compress_php
function compress_php($phpFile, $delStart = true)
{
$content = php_strip_whitespace($phpFile);
$content = preg_replace('/[\\s]*\\?\\>$/', '', trim($content));
$delStart && ($content = preg_replace('/^\\<\\?php[\\s]*/', '', $content));
return $content;
}
示例11: cache
/**
* Cache declared interfaces and classes to a single file
* @todo - extract the file_put_contents / php_strip_whitespace calls or figure out a way to mock the filesystem
*
* @param string
* @return void
*/
public function cache($classCacheFilename)
{
if (file_exists($classCacheFilename)) {
$this->reflectClassCache($classCacheFilename);
$code = file_get_contents($classCacheFilename);
} else {
$code = "<?php\n";
}
$classes = array_merge(get_declared_interfaces(), get_declared_classes());
foreach ($classes as $class) {
$class = new ClassReflection($class);
if (!$this->shouldCacheClass->isSatisfiedBy($class)) {
continue;
}
// Skip any classes we already know about
if (in_array($class->getName(), $this->knownClasses)) {
continue;
}
$this->knownClasses[] = $class->getName();
$code .= $this->cacheCodeGenerator->getCacheCode($class);
}
file_put_contents($classCacheFilename, $code);
// minify the file
file_put_contents($classCacheFilename, php_strip_whitespace($classCacheFilename));
}
示例12: addFile
/**
* Add a file in phar removing whitespaces from the file
*
* @param Phar $phar
* @param string $sFile
* @param null $baseDir
*/
function addFile($phar, $sFile, $baseDir = null)
{
if (null !== $baseDir) {
$phar->addFromString(substr($sFile, strlen($baseDir) + 1), php_strip_whitespace($sFile));
} else {
$phar->addFromString($sFile, php_strip_whitespace($sFile));
}
}
示例13: minify
public function minify($filename)
{
$string = php_strip_whitespace($filename);
if ($this->getBanner()) {
$string = preg_replace('/^<\\?php/', '<?php ' . $this->getBanner(), $string);
}
return $string;
}
示例14: compile
public function compile(array $files, $destFile)
{
$source = '';
foreach ($files as $k => $v) {
$source .= ' ' . str_replace(array('<?php', '<?', '?>') . '' . php_strip_whitespace($v));
}
return @file_put_contents($destFile, '<?php ' . $source);
}
示例15: inspectPhpFile
/**
* @param string $path
* @return string[]
* @throws RuntimeException
*/
static function inspectPhpFile($path)
{
try {
$contents = php_strip_whitespace($path);
} catch (\Exception $e) {
throw new \RuntimeException('Could not scan for classes inside ' . $path . ": \n" . $e->getMessage(), 0, $e);
}
return self::inspectFileContents($contents);
}