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


PHP Kernel::stripComments方法代码示例

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


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

示例1: load

 /**
  * Loads a list of classes and caches them in one big file.
  *
  * @param array   $classes    An array of classes to load
  * @param string  $cacheDir   A cache directory
  * @param string  $name       The cache name prefix
  * @param Boolean $autoReload Whether to flush the cache when the cache is stale or not
  * @param Boolean $adaptive   Whether to remove already declared classes or not
  *
  * @throws \InvalidArgumentException When class can't be loaded
  */
 public static function load($classes, $cacheDir, $name, $autoReload, $adaptive = false)
 {
     // each $name can only be loaded once per PHP process
     if (isset(self::$loaded[$name])) {
         return;
     }
     self::$loaded[$name] = true;
     $classes = array_unique($classes);
     if ($adaptive) {
         // don't include already declared classes
         $classes = array_diff($classes, get_declared_classes(), get_declared_interfaces());
         // the cache is different depending on which classes are already declared
         $name = $name . '-' . substr(md5(implode('|', $classes)), 0, 5);
     }
     $cache = $cacheDir . '/' . $name . '.php';
     // auto-reload
     $reload = false;
     if ($autoReload) {
         $metadata = $cacheDir . '/' . $name . '.meta';
         if (!file_exists($metadata) || !file_exists($cache)) {
             $reload = true;
         } else {
             $time = filemtime($cache);
             $meta = unserialize(file_get_contents($metadata));
             if ($meta[1] != $classes) {
                 $reload = true;
             } else {
                 foreach ($meta[0] as $resource) {
                     if (!file_exists($resource) || filemtime($resource) > $time) {
                         $reload = true;
                         break;
                     }
                 }
             }
         }
     }
     if (!$reload && file_exists($cache)) {
         require_once $cache;
         return;
     }
     $files = array();
     $content = '';
     foreach ($classes as $class) {
         if (!class_exists($class) && !interface_exists($class)) {
             throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
         }
         $r = new \ReflectionClass($class);
         $files[] = $r->getFileName();
         $content .= preg_replace(array('/^\\s*<\\?php/', '/\\?>\\s*$/'), '', file_get_contents($r->getFileName()));
     }
     // cache the core classes
     if (!is_dir(dirname($cache))) {
         mkdir(dirname($cache), 0777, true);
     }
     self::writeCacheFile($cache, Kernel::stripComments('<?php ' . $content));
     if ($autoReload) {
         // save the resources
         self::writeCacheFile($metadata, serialize(array($files, $classes)));
     }
 }
开发者ID:spf13,项目名称:symfony,代码行数:71,代码来源:ClassCollectionLoader.php

示例2: load

 public static function load($classes, $cacheDir, $name, $autoReload)
 {
     $cache = $cacheDir . '/' . $name . '.php';
     // auto-reload
     $reload = false;
     if ($autoReload) {
         $metadata = $cacheDir . '/' . $name . '.meta';
         if (!file_exists($metadata) || !file_exists($cache)) {
             $reload = true;
         } else {
             $time = filemtime($cache);
             $meta = unserialize(file_get_contents($metadata));
             if ($meta[1] != $classes) {
                 $reload = true;
             } else {
                 foreach ($meta[0] as $resource) {
                     if (!file_exists($resource) || filemtime($resource) > $time) {
                         $reload = true;
                         break;
                     }
                 }
             }
         }
     }
     if (!$reload && file_exists($cache)) {
         require_once $cache;
         return;
     }
     $files = array();
     $content = '';
     foreach ($classes as $class) {
         if (!class_exists($class) && !interface_exists($class)) {
             throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
         }
         $r = new \ReflectionClass($class);
         $files[] = $r->getFileName();
         $content .= preg_replace(array('/^\\s*<\\?php/', '/\\?>\\s*$/'), '', file_get_contents($r->getFileName()));
     }
     // cache the core classes
     if (!is_dir(dirname($cache))) {
         mkdir(dirname($cache), 0777, true);
     }
     self::writeCacheFile($cache, Kernel::stripComments('<?php ' . $content));
     if ($autoReload) {
         // save the resources
         self::writeCacheFile($metadata, serialize(array($files, $classes)));
     }
 }
开发者ID:CodingFabian,项目名称:symfony,代码行数:48,代码来源:ClassCollectionLoader.php

示例3: load

 public static function load($classes, $cacheDir, $name, $autoReload, $adaptive = false)
 {
     if (isset(self::$loaded[$name])) {
         return;
     }
     self::$loaded[$name] = true;
     $classes = array_unique($classes);
     if ($adaptive) {
         $classes = array_diff($classes, get_declared_classes(), get_declared_interfaces());
         $name = $name . '-' . substr(md5(implode('|', $classes)), 0, 5);
     }
     $cache = $cacheDir . '/' . $name . '.php';
     $reload = false;
     if ($autoReload) {
         $metadata = $cacheDir . '/' . $name . '.meta';
         if (!file_exists($metadata) || !file_exists($cache)) {
             $reload = true;
         } else {
             $time = filemtime($cache);
             $meta = unserialize(file_get_contents($metadata));
             if ($meta[1] != $classes) {
                 $reload = true;
             } else {
                 foreach ($meta[0] as $resource) {
                     if (!file_exists($resource) || filemtime($resource) > $time) {
                         $reload = true;
                         break;
                     }
                 }
             }
         }
     }
     if (!$reload && file_exists($cache)) {
         require_once $cache;
         return;
     }
     $files = array();
     $content = '';
     foreach ($classes as $class) {
         if (!class_exists($class) && !interface_exists($class)) {
             throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
         }
         $r = new \ReflectionClass($class);
         $files[] = $r->getFileName();
         $c = preg_replace(array('/^\\s*<\\?php/', '/\\?>\\s*$/'), '', file_get_contents($r->getFileName()));
         if (!$r->inNamespace()) {
             $c = "\nnamespace\n{\n{$c}\n}\n";
         } else {
             $c = self::fixNamespaceDeclarations('<?php ' . $c);
             $c = preg_replace('/^\\s*<\\?php/', '', $c);
         }
         $content .= $c;
     }
     if (!is_dir(dirname($cache))) {
         mkdir(dirname($cache), 0777, true);
     }
     self::writeCacheFile($cache, Kernel::stripComments('<?php ' . $content));
     if ($autoReload) {
         self::writeCacheFile($metadata, serialize(array($files, $classes)));
     }
 }
开发者ID:notbrain,项目名称:symfony,代码行数:61,代码来源:bootstrap.php


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