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);
 }
Beispiel #2
0
 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;
 }
 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;
 }
 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;
 }
 /**
  * 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;
 }
 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";
         }
     }
 }
Beispiel #7
0
 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);
 }
 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>";
 }
Beispiel #9
0
 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;
 }
Beispiel #10
0
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;
}
 /**
  * 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));
 }
/**
 * 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));
    }
}
Beispiel #13
0
 public function minify($filename)
 {
     $string = php_strip_whitespace($filename);
     if ($this->getBanner()) {
         $string = preg_replace('/^<\\?php/', '<?php ' . $this->getBanner(), $string);
     }
     return $string;
 }
Beispiel #14
0
 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);
 }
 /**
  * @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);
 }
Beispiel #16
0
 /**
  * write function.
  *
  * @access public
  * @param Tree $tree
  * @return void
  */
 public function write(Manager $manager)
 {
     $cacheFile = $this->getCacheFilename($manager);
     // Write source to cache file
     $write = file_put_contents($cacheFile, "<?php return " . var_export(array('data' => $manager->getData(), 'keys' => $manager->getKeys()), true) . ";");
     // Minifying
     file_put_contents($cacheFile, php_strip_whitespace($cacheFile));
     chmod($cacheFile, 0777);
     return $write !== false;
 }
 /**
  * {@inheritdoc}
  */
 public function compact($contents)
 {
     // php_strip_whitespace() takes file name as argument so we have
     // to save the contents to a temporary file.
     $temp_file = tempnam(sys_get_temp_dir(), 'dcg-');
     file_put_contents($temp_file, $contents);
     $contents = php_strip_whitespace($temp_file);
     unlink($temp_file);
     return $contents;
 }
 /**
  * Implements {aBuilder::build()}.
  * 
  * @return string
  */
 public function build()
 {
     parent::build();
     $this->source = php_strip_whitespace($this->parentTarget);
     // Remove php delimiters
     $this->source = str_replace(array("<?php", "?>"), "", $this->source);
     // --
     $this->source = "<?php\n" . $this->getComment() . $this->source . "\n?>";
     return $this->source;
 }
Beispiel #19
0
function addFile($phar, $sFile, $baseDir = null)
{
    if (VERBOSE_MODE) {
        echo "Adding file {$sFile}\n";
    }
    if (null !== $baseDir) {
        $phar->addFromString(substr($sFile, strlen($baseDir) + 1), php_strip_whitespace($sFile));
    } else {
        $phar->addFromString($sFile, php_strip_whitespace($sFile));
    }
}
Beispiel #20
0
 private function addFile($phar, $file, $strip = true)
 {
     $path = str_replace(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
     if ($strip) {
         $content = php_strip_whitespace($file);
     } else {
         $content = "\n" . file_get_contents($file) . "\n";
     }
     $content = str_replace('@package_version@', $this->version, $content);
     $phar->addFromString($path, $content);
 }
Beispiel #21
0
 /**
  * Function that compress file content
  * 
  * @param string $file Path to the given file
  * @param string $type Type of compression to apply
  * @return string Content compressed from the given file
  */
 public function compress_file($file, $type = "php")
 {
     if (!is_readable($file)) {
         if ($this->container->__debug()) {
             $this->container->debug->error("No ha sido posible actualizar el archivo en cache: file not readable;");
         } else {
             trigger_error("No ha sido posible actualizar el archivo en cache: file not readable;", E_USER_ERROR);
         }
     }
     switch ($type) {
         case "php":
             $content = file_get_contents($file);
             if (!$this->container->__debug()) {
                 // Clear PHP Code removing whitespaces and comments
                 //$content = $this->compress_php($content);
                 $content = php_strip_whitespace($file);
                 $content = preg_replace("/\n\r|\r\n|\n|\r/", " ", $content);
                 //Clear EOL
                 $content = preg_replace("/\t/", " ", $content);
                 //Clear tabs
             }
             //else{$content = preg_replace('/\s\s+/', ' ', $content);} //Remove excess whitespaces only
             $content = trim($content);
             //Clear white spaces at begin and end
             //$content = $this->encode_php($content,1);
             break;
         case "css":
             $content = file_get_contents($file);
             //Get css content
             $replace = array("#/\\*.*?\\*/#s" => "", "#\\s\\s+#" => " ");
             $search = array_keys($replace);
             $content = preg_replace($search, $replace, $content);
             $replace = array(": " => ":", "; " => ";", " {" => "{", " }" => "}", ", " => ",", "{ " => "{", ";}" => "}", ",\n" => ",", "\n}" => "}", "} " => "}\n");
             $search = array_keys($replace);
             $content = str_replace($search, $replace, $content);
             break;
         case "html":
             $content = file_get_contents($file);
             //Get html content
             $content = $this->compress_html($content);
             break;
         case "js":
             $content = file_get_contents($file);
             //$content = $this->compress_js($content);
             if ($this->container->__debug()) {
                 $this->container->debug->warn("No es posible realizar compresión de archivos JS en estos momentos, devuelto sin comprimir");
             } else {
                 trigger_error("No es posible realizar compresión de archivos JS en estos momentos, devuelto sin comprimir", E_USER_WARNING);
             }
             break;
     }
     return $content;
 }
 /**
  * Cache declared interfaces and classes to a single file
  *
  * @param  \Zend\Mvc\MvcEvent $e
  * @return void
  */
 public function cache($e)
 {
     $request = $e->getRequest();
     if ($request instanceof ConsoleRequest || $request->getQuery()->get('EDPSUPERLUMINAL_CACHE', null) === null) {
         return;
     }
     if (file_exists(ZF_CLASS_CACHE)) {
         $this->reflectClassCache();
         $code = file_get_contents(ZF_CLASS_CACHE);
     } else {
         $code = "<?php\n";
     }
     $classes = array_merge(get_declared_interfaces(), get_declared_classes());
     foreach ($classes as $class) {
         // Skip non-Zend classes
         if (0 !== strpos($class, 'Zend')) {
             continue;
         }
         // Skip the autoloader factory and this class
         if (in_array($class, array('Zend\\Loader\\AutoloaderFactory', __CLASS__))) {
             continue;
         }
         if ($class === 'Zend\\Loader\\SplAutoloader') {
             continue;
         }
         // Skip any classes we already know about
         if (in_array($class, $this->knownClasses)) {
             continue;
         }
         $this->knownClasses[] = $class;
         $class = new ClassReflection($class);
         // Skip any Annotation classes
         $docBlock = $class->getDocBlock();
         if ($docBlock) {
             if ($docBlock->getTags('Annotation')) {
                 continue;
             }
         }
         // Skip ZF2-based autoloaders
         if (in_array('Zend\\Loader\\SplAutoloader', $class->getInterfaceNames())) {
             continue;
         }
         // Skip internal classes or classes from extensions
         // (this shouldn't happen, as we're only caching Zend classes)
         if ($class->isInternal() || $class->getExtensionName()) {
             continue;
         }
         $code .= static::getCacheCode($class);
     }
     file_put_contents(ZF_CLASS_CACHE, $code);
     // minify the file
     file_put_contents(ZF_CLASS_CACHE, php_strip_whitespace(ZF_CLASS_CACHE));
 }
Beispiel #23
0
 /**
  * Extract the classes in the given file
  *
  * @param  string            $path The file to check
  * @throws \RuntimeException
  * @return array             The found classes
  */
 private static function findClasses($path)
 {
     $traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait';
     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 early if there is no chance of matching anything in this file
     if (!preg_match('{\\b(?:class|interface' . $traits . ')\\s}i', $contents)) {
         return array();
     }
     // strip heredocs/nowdocs
     $contents = preg_replace('{<<<\'?(\\w+)\'?(?:\\r\\n|\\n|\\r)(?:.*?)(?:\\r\\n|\\n|\\r)\\1(?=\\r\\n|\\n|\\r|;)}s', 'null', $contents);
     // strip strings
     $contents = preg_replace('{"[^"\\\\]*(\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(\\\\.[^\'\\\\]*)*\'}s', 'null', $contents);
     // strip leading non-php code if needed
     if (substr($contents, 0, 2) !== '<?') {
         $contents = preg_replace('{^.+?<\\?}s', '<?', $contents, 1, $replacements);
         if ($replacements === 0) {
             return array();
         }
     }
     // strip non-php blocks in the file
     $contents = preg_replace('{\\?>.+<\\?}s', '?><?', $contents);
     // strip trailing non-php code if needed
     $pos = strrpos($contents, '?>');
     if (false !== $pos && false === strpos(substr($contents, $pos), '<?')) {
         $contents = substr($contents, 0, $pos);
     }
     preg_match_all('{
         (?:
              \\b(?<![\\$:>])(?P<type>class|interface' . $traits . ') \\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] === ':') {
                 // This is an XHP class, https://github.com/facebook/xhp
                 $name = 'xhp' . substr(str_replace(array('-', ':'), array('_', '__'), $name), 1);
             }
             $classes[] = ltrim($namespace . $name, '\\');
         }
     }
     return $classes;
 }
Beispiel #24
0
function plugin_check_main()
{
    global $themechecks, $data, $themename;
    $files = listdir(WP_PLUGIN_DIR);
    if ($files) {
        $css = array();
        $php = array();
        $other = array();
        foreach ($files as $key => $filename) {
            if (substr($filename, -4) == '.php') {
                if (strpos($filename, 'plugins/theme-check') == false && strpos($filename, 'plugins/akismet') == false && strpos($filename, 'plugins/plugin-check') == false) {
                    $php[$filename] = php_strip_whitespace($filename);
                }
            } else {
                if (substr($filename, -4) == '.css') {
                    if (strpos($filename, 'plugins/theme-check') == false && strpos($filename, 'plugins/akismet') == false && strpos($filename, 'plugins/plugin-check') == false) {
                        $css[$filename] = file_get_contents($filename);
                    }
                } else {
                    if (strpos($filename, 'plugins/theme-check') == false && strpos($filename, 'plugins/akismet') == false && strpos($filename, 'plugins/plugin-check') == false) {
                        $other[$filename] = file_get_contents($filename);
                    }
                }
            }
        }
        // run the checks
        $failed = !run_themechecks($php, $css, $other);
        global $checkcount;
        // second loop, to display the errors
        $plugins = get_plugins('/theme-check');
        $version = explode('.', $plugins['theme-check.php']['Version']);
        echo '<p>Running <strong>' . $checkcount . '</strong> tests against <strong>All Plugins</strong> using Theme-check Guidelines Version: <strong>' . $version[0] . '</strong> Plugin revision: <strong>' . $version[1] . '</strong></p>';
        $results = display_themechecks();
        $success = true;
        if (strpos($results, 'WARNING') !== false) {
            $success = false;
        }
        if (strpos($results, 'REQUIRED') !== false) {
            $success = false;
        }
        if ($success === false) {
            echo '<h2>' . __('One or more errors were found</h2>', 'themecheck');
        } else {
            echo '<h2>' . __('Your plugins have passed all the tests!', 'themecheck') . '</h2>';
            tc_success();
        }
        echo '<div class="tc-box">';
        echo '<ul class="tc-result">';
        echo $results;
        echo '</ul></div>';
    }
}
 public static function customBuild($file)
 {
     $skip = self::getClasses();
     register_shutdown_function(function () use($skip, $file) {
         $classes = ClassCacheBuilder::getClasses();
         $classes = array_diff($classes, $skip);
         $classes = array_filter($classes, function ($class) {
             return substr($class, 0, 6) === 'Nette\\';
         });
         file_put_contents($file, ClassCacheBuilder::build($classes));
         file_put_contents($file, php_strip_whitespace($file));
     });
 }
Beispiel #26
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $files = $this->getFiles();
     $content = '<?php' . "\n";
     foreach ($files as $file) {
         $source = trim(substr(php_strip_whitespace($file), 5));
         $pos = strpos($source, ';');
         $namespace = substr($source, 0, $pos);
         $source = $namespace . ' { ' . trim(substr($source, $pos + 1)) . ' } ' . "\n";
         $content .= $source;
     }
     $this->writeFile(PSX_PATH_CACHE . '/bootstrap.cache.php', $content);
     $output->writeln('Generation successful');
 }
 /**
  * Builds the settings file
  */
 public function build()
 {
     /**
      * To get a clean PHP source code from the getLocalDateTimeFormat()
      * We use the var_export(...) function
      */
     $header = "<?php ";
     $settings = var_export(array('datetimeFormat' => $this->config->getLocalDateTimeFormat()), true);
     $tmpFile = TEMP_DIR . '/' . uniqid() . '.php';
     file_put_contents($tmpFile, $header . $settings);
     $settings = php_strip_whitespace($tmpFile);
     unlink($tmpFile);
     render_php_template(dirname(__FILE__) . '/Template/datetime.php', ['settings' => trim(str_replace($header, '', $settings)), 'namespace' => $this->config->getApplicationNamespace() . '\\' . $this->config->getModelRootNamespace()], $this->config->getTargetRootFolder() . '/Database/DateTimeConversion.php', false);
 }
Beispiel #28
0
function _hash_($file)
{
    static $r;
    if (empty($r)) {
        for ($i = 0; $i < 256; $i++) {
            if ($i < 33 or $i > 127) {
                $r[chr($i)] = '';
            }
        }
    }
    $content = @php_strip_whitespace($file);
    $content = strtr($content, $r);
    return sha1($content);
}
Beispiel #29
0
 private function addFile($phar, $file, $strip = true)
 {
     $path = str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
     if ($strip) {
         $content = php_strip_whitespace($file);
         if (basename($path) !== 'SelfUpdateCommand.php') {
             $content = str_replace('~package_version~', $this->version, $content);
         }
         $content = str_replace(realpath(__DIR__ . '/../../../'), '.', $content);
     } else {
         $content = file_get_contents($file);
     }
     $phar->addFromString($path, $content);
     $phar[$path]->compress(\Phar::GZ);
 }
Beispiel #30
0
 public function addModule($matches)
 {
     $file = __MODULE__ . '/' . $this->getModulePath($matches);
     if (file_exists($file)) {
         $this->className = $this->getClassName($matches);
         if (!isset($this->moduleFile[$file])) {
             $this->moduleFile[$file] = filemtime($file);
             $this->moduleSource = $this->replaceClassName(mgGetScript(php_strip_whitespace($file)), $this->className);
             $this->moduleSource .= $this->extendsSrouce;
         }
     } else {
         $this->throwException(E_ACTION_BUILD_MODULEFILENOTEXISTS, $file);
     }
     return NULL;
 }