コード例 #1
0
 /**
  * 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));
 }
コード例 #2
0
 /**
  * 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)));
     }
 }
コード例 #3
0
ファイル: iphp.php プロジェクト: apinstein/phocoa
 /**
  * Constructor
  *
  * @param array Options hash:
  *                  - OPT_TAGS_FILE: the path to a tags file produce with ctags for your project -- all tags will be used for autocomplete
  */
 public function __construct($options = array())
 {
     // merge opts
     $this->options = array_merge(array(self::OPT_TAGS_FILE => NULL, self::OPT_REQUIRE => NULL), $options);
     // initialize temp files
     $this->tmpFileShellCommand = $this->tmpFileNamed('command');
     $this->tmpFileShellCommandRequires = $this->tmpFileNamed('requires');
     $this->tmpFileShellCommandState = $this->tmpFileNamed('state');
     // setup autocomplete
     $phpList = get_defined_functions();
     $this->autocompleteList = array_merge($this->autocompleteList, $phpList['internal']);
     $this->autocompleteList = array_merge($this->autocompleteList, get_defined_constants());
     $this->autocompleteList = array_merge($this->autocompleteList, get_declared_classes());
     $this->autocompleteList = array_merge($this->autocompleteList, get_declared_interfaces());
     // initialize tags
     $tagsFile = $this->options[self::OPT_TAGS_FILE];
     if (file_exists($tagsFile)) {
         $tags = array();
         $tagLines = file($tagsFile);
         foreach ($tagLines as $tag) {
             $matches = array();
             if (preg_match('/^([A-z0-9][^\\W]*)\\W.*/', $tag, $matches)) {
                 $tags[] = $matches[1];
             }
         }
         $this->autocompleteList = array_merge($this->autocompleteList, $tags);
     }
     // process optional require files
     if ($this->options[self::OPT_REQUIRE]) {
         if (!is_array($this->options[self::OPT_REQUIRE])) {
             $this->options[self::OPT_REQUIRE] = array($this->options[self::OPT_REQUIRE]);
         }
         file_put_contents($this->tmpFileShellCommandRequires, serialize($this->options[self::OPT_REQUIRE]));
     }
 }
コード例 #4
0
ファイル: loadclass.php プロジェクト: Debenson/openwan
 function execute()
 {
     echo "search class files...";
     $files = find_files($this->_source_dir, array('extnames' => array('.php'), 'excludes' => array('_config')));
     echo "ok\n\n";
     $this->_files = $files;
     spl_autoload_register(array($this, 'autoload'));
     $classes = get_declared_classes();
     $classes = array_merge($classes, get_declared_interfaces());
     foreach ($files as $path) {
         require_once $path;
     }
     $new_classes = get_declared_classes();
     $new_classes = array_merge($new_classes, get_declared_interfaces());
     $found = array_diff($new_classes, $classes);
     $files = array();
     foreach ($found as $class) {
         $r = new ReflectionClass($class);
         $files[$class] = $r->getFileName();
     }
     $arr = array();
     $len = strlen($this->_source_dir);
     foreach ($files as $class => $path) {
         $filename = str_replace(array('/', '\\'), '/', substr($path, $len + 1));
         $class = strtolower($class);
         $arr[$class] = $filename;
     }
     $output = "<?php global \$G_CLASS_FILES;\$G_CLASS_FILES = ";
     $output .= str_replace(array(' ', "\n"), '', var_export($arr, true));
     $output .= ";\n";
     file_put_contents($this->_output_file, $output, LOCK_EX);
     echo "ok\n";
 }
コード例 #5
0
ファイル: class_tree.php プロジェクト: cefalo19/php-src
 /** @param base  base class to collect sub classes for
  * @param check_interfaces whether we deal with interfaces
  */
 function __construct($base, $check_interfaces = false)
 {
     foreach (get_declared_classes() as $cname) {
         $parent = get_parent_class($cname);
         if (strcasecmp($parent, $base) == 0) {
             $this->offsetSet($cname, new SubClasses($cname));
         }
         if ($check_interfaces) {
             if ($parent) {
                 $parent_imp = class_implements($parent);
             }
             foreach (class_implements($cname) as $iname) {
                 if (strcasecmp($iname, $base) == 0) {
                     if (!$parent || !in_array($iname, $parent_imp)) {
                         $this->offsetSet($cname, new SubClasses($cname));
                     }
                 }
             }
         }
     }
     if ($check_interfaces) {
         foreach (get_declared_interfaces() as $cname) {
             foreach (class_implements($cname) as $iname) {
                 if (strcasecmp($iname, $base) == 0) {
                     $this->offsetSet($cname, new SubClasses($cname, true));
                 }
             }
         }
     }
     $this->uksort('strnatcasecmp');
 }
コード例 #6
0
ファイル: debug.php プロジェクト: art-youth/framework
 static function info($type = 1)
 {
     $type_list = array('basic', 'const', 'variable', 'function', 'class', 'interface', 'file');
     if (is_int($type) && $type < 7) {
         $type = $type_list[$type];
     }
     switch ($type) {
         case 'const':
             $const_arr = get_defined_constants(true);
             return $const_arr['user'];
             //2因作用域,请在外边直接调用函数
         //2因作用域,请在外边直接调用函数
         case 'variable':
             return 'please use: get_defined_vars()';
         case 'function':
             $fun_arr = get_defined_functions();
             return $fun_arr['user'];
         case 'class':
             return array_slice(get_declared_classes(), 125);
         case 'interface':
             return array_slice(get_declared_interfaces(), 10);
         case 'file':
             return get_included_files();
         default:
             return array('system' => php_uname(), 'service' => php_sapi_name(), 'php_version' => PHP_VERSION, 'frame_name' => config('frame|name'), 'frame_version' => config('frame|version'), 'magic_quotes' => get_magic_quotes_gpc(), 'time_zone' => date_default_timezone_get());
     }
 }
コード例 #7
0
ファイル: util.php プロジェクト: bateller/phan
function add_internal($internal_classes)
{
    global $functions, $internal_arginfo;
    foreach ($internal_classes as $class_name) {
        add_class($class_name, 0);
    }
    foreach (get_declared_interfaces() as $class_name) {
        add_class($class_name);
    }
    foreach (get_declared_traits() as $class_name) {
        add_class($class_name);
    }
    foreach (get_defined_functions()['internal'] as $function_name) {
        $function = new \ReflectionFunction($function_name);
        $required = $function->getNumberOfRequiredParameters();
        $optional = $function->getNumberOfParameters() - $required;
        $functions[strtolower($function_name)] = ['file' => 'internal', 'namespace' => $function->getNamespaceName(), 'avail' => true, 'conditional' => false, 'flags' => 0, 'lineno' => 0, 'endLineno' => 0, 'name' => $function_name, 'docComment' => '', 'required' => $required, 'optional' => $optional, 'ret' => null, 'params' => []];
        add_param_info($function_name);
    }
    foreach (array_keys($internal_arginfo) as $function_name) {
        if (strpos($function_name, ':') !== false) {
            continue;
        }
        $ln = strtolower($function_name);
        $functions[$ln] = ['file' => 'internal', 'avail' => false, 'conditional' => false, 'flags' => 0, 'lineno' => 0, 'endLineno' => 0, 'name' => $function_name, 'docComment' => '', 'ret' => null, 'params' => []];
        add_param_info($function_name);
    }
}
コード例 #8
0
 /**
  * Prepares and returns used class lists.
  *
  * @return ReflectionClass[]
  */
 protected function parseClassLists()
 {
     $this->declared = array_flip(array_merge(get_declared_classes(), get_declared_interfaces()));
     foreach ($this->getNamespaces() as $namespace) {
         foreach ($namespace->getClasses() as $name => $ref) {
             $class = $this->reflectionFactory->createFromReflection($ref);
             $this->allClasses[self::TOKENIZED_CLASSES][$name] = $class;
             if (!$class->isDocumented()) {
                 continue;
             }
             $this->loadParentClassesAndInterfacesFromClassReflection($ref);
         }
     }
     /** @var ReflectionClass $class */
     foreach ($this->allClasses[self::TOKENIZED_CLASSES] as $class) {
         if (!$class->isDocumented()) {
             continue;
         }
         foreach ($class->getOwnMethods() as $method) {
             $this->processFunction($method);
         }
         foreach ($class->getOwnProperties() as $property) {
             $this->loadAnnotationFromReflection($class, $property->getAnnotations(), 'var');
         }
     }
     foreach ($this->getFunctions() as $function) {
         $this->processFunction($function);
     }
     array_walk_recursive($this->allClasses, function (&$reflection) {
         if (!$reflection instanceof ReflectionClass) {
             $reflection = $this->reflectionFactory->createFromReflection($reflection);
         }
     });
     return $this->allClasses;
 }
コード例 #9
0
ファイル: TypeScanner.php プロジェクト: spotframework/spot
 public function scan($namespace)
 {
     $namespace = trim($namespace, "\\") . "\\";
     $paths = [];
     foreach (spl_autoload_functions() as $loader) {
         if (is_array($loader) && count($loader) === 2) {
             if ($loader[0] instanceof ComposerLoader) {
                 foreach ($loader[0]->getPrefixes() as $prefix => $loaderPaths) {
                     if (strpos($prefix . "\\", $namespace) === 0) {
                         $paths = array_merge($paths, $loaderPaths);
                     } else {
                         if (strpos($namespace, $prefix . "\\") === 0) {
                             $paths = array_merge($paths, array_map(function ($path) use($namespace, $prefix) {
                                 return $path . "/" . str_replace("\\", "/", $namespace);
                             }, $loaderPaths));
                         }
                     }
                 }
             }
         }
     }
     array_map([$this->phpLoader, "load"], $paths);
     return array_filter(array_merge(get_declared_classes(), get_declared_interfaces()), function ($name) use($namespace) {
         return stripos($name, $namespace) === 0;
     });
 }
コード例 #10
0
 protected function minifyYii($entryScript)
 {
     try {
         ob_start();
         $this->runRequest($entryScript);
         $_SERVER['REQUEST_URI'] = '/index.php';
         $this->runRequest($entryScript, array('r' => 'post'));
         ob_end_clean();
     } catch (CException $e) {
         echo $e;
         die;
     }
     $classes = array_merge(get_declared_classes(), get_declared_interfaces());
     $results = array();
     foreach ($classes as $class) {
         $c = new ReflectionClass($class);
         if (strpos($c->getFileName(), YII_PATH) === 0 && strpos($c->getFileName(), YII_PATH . DIRECTORY_SEPARATOR . 'console') !== 0) {
             $results[$class] = $c->getFileName();
         }
     }
     $results = $this->sortByInheritance($results);
     $content = '';
     foreach ($results as $fileName => $class) {
         $content .= "\n" . file_get_contents($fileName);
     }
     return $content;
 }
コード例 #11
0
 function __construct($dump_file = false, $gzip_dump_file = false)
 {
     $functions = get_defined_functions();
     $this->data = array('memory_usage' => memory_get_usage(), 'interfaces' => get_declared_interfaces(), 'classes' => get_declared_classes(), 'constants' => get_defined_constants(), 'user_functions' => $functions['user'], 'int_functions' => $functions['internal']);
     if ($dump_file) {
         $this->dump($dump_file, $gzip_dump_file);
     }
 }
コード例 #12
0
 public function executeOnce(AgaviFilterChain $filterChain, AgaviExecutionContainer $container)
 {
     $filterChain->execute($container);
     $interfaces = get_declared_interfaces();
     $classes = get_declared_classes();
     $text = "Interfaces ** \n - " . implode("\n - ", $interfaces) . "\n Classes ** \n - " . implode("\n - ", $classes);
     $container->getContext()->getLoggerManager()->getLogger("debug")->log(new AgaviLoggerMessage("{$text}", AgaviLogger::DEBUG));
 }
コード例 #13
0
 /**
  * @runInSeparateProcess
  */
 public function testOneClass()
 {
     $message = new \Zend\Stdlib\Message();
     $classes = array_merge(get_declared_interfaces(), get_declared_classes());
     $actual = $this->sut->cache($classes);
     $expected = $this->getTestFileContents('testMessageClass');
     $this->assertEquals($expected, $actual);
 }
コード例 #14
0
 /**
  * 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 bool   $autoReload Whether to flush the cache when the cache is stale or not
  * @param bool   $adaptive   Whether to remove already declared classes or not
  * @param string $extension  File extension of the resulting file
  *
  * @throws \InvalidArgumentException When class can't be loaded
  */
 public static function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
 {
     // each $name can only be loaded once per PHP process
     if (isset(self::$loaded[$name])) {
         return;
     }
     self::$loaded[$name] = true;
     if ($adaptive) {
         $declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
         // don't include already declared classes
         $classes = array_diff($classes, $declared);
         // the cache is different depending on which classes are already declared
         $name = $name . '-' . substr(hash('sha256', implode('|', $classes)), 0, 5);
     }
     $classes = array_unique($classes);
     // cache the core classes
     if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
         throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
     }
     $cacheDir = rtrim(realpath($cacheDir) ?: $cacheDir, '/' . DIRECTORY_SEPARATOR);
     $cache = $cacheDir . DIRECTORY_SEPARATOR . $name . $extension;
     // auto-reload
     $reload = false;
     if ($autoReload) {
         $metadata = $cache . '.meta';
         if (!is_file($metadata) || !is_file($cache)) {
             $reload = true;
         } else {
             $time = filemtime($cache);
             $meta = unserialize(file_get_contents($metadata));
             sort($meta[1]);
             sort($classes);
             if ($meta[1] != $classes) {
                 $reload = true;
             } else {
                 foreach ($meta[0] as $resource) {
                     if (!is_file($resource) || filemtime($resource) > $time) {
                         $reload = true;
                         break;
                     }
                 }
             }
         }
     }
     if (!$reload && file_exists($cache)) {
         require_once $cache;
         return;
     }
     if (!$adaptive) {
         $declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
     }
     $files = self::inline($classes, $cache, $declared);
     if ($autoReload) {
         // save the resources
         self::writeCacheFile($metadata, serialize(array(array_values($files), $classes)));
     }
 }
コード例 #15
0
ファイル: Cacher.php プロジェクト: jdolieslager/celeritas
 /**
  * Make cache file from current loaded classes
  *
  */
 public function cache()
 {
     set_time_limit(120);
     $swpLockFile = $this->getConfig()->getSwapFile() . '.lock';
     if (is_file($swpLockFile)) {
         return;
     }
     file_put_contents($swpLockFile, '');
     // Open working file
     if (is_file($this->getConfig()->getSwapFile()) === false) {
         file_put_contents($this->getConfig()->getSwapFile(), '');
     }
     $this->handle = fopen($this->getConfig()->getSwapFile(), 'r+');
     // Lock the file
     if (flock($this->handle, LOCK_EX) === false) {
         return;
     }
     // Clear the file
     ftruncate($this->handle, 0);
     // Traits first, then interfaces at last the classes
     $classes = array_merge(get_declared_traits(), get_declared_interfaces(), get_declared_classes());
     // We only want to cache classes once
     $classes = array_unique($classes);
     $this->classList = array_flip($classes);
     $this->classList = array_fill_keys($classes, false);
     // Write PHP open tag
     fwrite($this->handle, '<?php' . PHP_EOL);
     // Walk through the classes
     foreach ($this->classList as $class => &$used) {
         $this->processClassIntoCacheFile(new Reflection\ClassReflection($class));
     }
     // Flush last contents to the file
     fflush($this->handle);
     // Release the swap lock
     flock($this->handle, LOCK_UN);
     // Close cache file handle
     fclose($this->handle);
     // Minify cache file
     file_put_contents($this->getConfig()->getSwapFile(), php_strip_whitespace($this->getConfig()->getSwapFile()));
     $fileLock = $this->getConfig()->getFile() . '.lock';
     file_put_contents($fileLock, '');
     if (is_file($this->getConfig()->getFile())) {
         unlink($this->getConfig()->getFile());
     }
     // Replace old cache file
     copy($this->getConfig()->getSwapFile(), $this->getConfig()->getFile());
     if (is_file($this->getConfig()->getSwapFile())) {
         // Hotfix for Windows environments
         if (@unlink($this->getConfig()->getSwapFile()) === false) {
             unlink($this->getConfig()->getSwapFile());
         }
     }
     // Unlink Locks
     unlink($swpLockFile);
     unlink($fileLock);
 }
コード例 #16
0
 public function testIteratorHasCorrectTotal()
 {
     $iterator = new cfhCompile_ClassIterator_Declared();
     $total = count(get_declared_interfaces()) + count(get_declared_classes());
     $i = 0;
     foreach ($iterator as $c) {
         $i++;
     }
     $this->assertEquals($total, $i);
 }
コード例 #17
0
 /**
  * @return string[] internal symbols
  */
 public function internalSymbolsProvider()
 {
     $allSymbols = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
     $indexedSymbols = array_combine($allSymbols, $allSymbols);
     return array_map(function ($symbol) {
         return [$symbol];
     }, array_filter($indexedSymbols, function ($symbol) {
         $reflection = new PhpReflectionClass($symbol);
         return $reflection->isInternal();
     }));
 }
コード例 #18
0
ファイル: reflection_test.php プロジェクト: naderman/pflow
 public function testGetInterfaces()
 {
     $interfaces = ezcReflection::getInterfaces();
     self::assertContainsOnly('ezcReflectionClass', $interfaces);
     foreach ($interfaces as $interfaceName => $interface) {
         self::assertTrue($interface->isInterface());
         self::assertEquals($interface->getName(), $interfaceName);
         $interfaceNames[] = $interface->getName();
     }
     self::assertEquals(get_declared_interfaces(), $interfaceNames);
 }
コード例 #19
0
 public function addGlobalizedClass($class)
 {
     if (!is_string($class)) {
         throw new \Exception('class value must be a string');
     }
     if ($this->isGlobalizedClassRegistered($class)) {
         throw new \Exception('class class value "' . $class . '" is already defined');
     }
     if (!in_array($class, get_declared_classes()) && !in_array($class, get_declared_interfaces())) {
         $this->_globalizedClasses[] = $class;
     }
 }
コード例 #20
0
 private function requireFile($file)
 {
     $previousDefinedClasses = get_declared_classes();
     $previousDefinedInterfaces = get_declared_interfaces();
     require_once $this->file;
     $currentDefinedClasses = get_declared_classes();
     $currentDefinedInterfaces = get_declared_interfaces();
     $userDefinedClasses = array_diff($currentDefinedClasses, $previousDefinedClasses);
     $userDefinedInterfaces = array_diff($currentDefinedInterfaces, $previousDefinedInterfaces);
     //now treat classes and interfaces as the same
     $this->userDefinedClasses = array_merge($userDefinedClasses, $userDefinedInterfaces);
 }
コード例 #21
0
ファイル: php2c.php プロジェクト: xiaolizhi/php2c
 public function load($source)
 {
     $classes = get_declared_classes();
     $interfaces = get_declared_interfaces();
     $functions = get_defined_functions()['user'];
     $constants = get_defined_constants();
     require_once $source;
     $this->classes = array_diff(get_declared_classes(), $classes);
     $this->interfaces = array_diff(get_declared_interfaces(), $interfaces);
     $this->functions = array_diff(get_defined_functions()['user'], $functions);
     $this->constants = array_diff(get_defined_constants(), $constants);
 }
コード例 #22
0
 /**
  * Warms up the cache.
  *
  * @param string $cacheDir The cache directory
  */
 public function warmUp($cacheDir)
 {
     $classmap = $cacheDir . '/classes.map';
     if (!is_file($classmap)) {
         return;
     }
     if (file_exists($cacheDir . '/classes.php')) {
         return;
     }
     $declared = null !== $this->declaredClasses ? $this->declaredClasses : array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
     ClassCollectionLoader::inline(include $classmap, $cacheDir . '/classes.php', $declared);
 }
コード例 #23
0
 /**
  * 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));
 }
コード例 #24
0
ファイル: Processor.php プロジェクト: fixin/fixin
 protected function processElementsItems()
 {
     $items = [];
     foreach (array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits()) as $name) {
         $reflection = new \ReflectionClass($name);
         if ($reflection->isInternal() || mb_substr($name, 0, 11) === 'FixinTools\\') {
             continue;
         }
         $items[$reflection->name] = new Item($this, $reflection);
     }
     ksort($items);
     $this->items = $items;
 }
コード例 #25
0
ファイル: TypeScanner.php プロジェクト: laiello/perminator
 private static function findTypes(array $searchTypeList, array $excludeTypeList)
 {
     $correctTypes = array();
     $foundTypeList = array_merge(get_declared_classes(), get_declared_interfaces());
     foreach ($foundTypeList as $type) {
         if (in_array($type, $excludeTypeList)) {
             continue;
         }
         if (self::hasTypeList($type, $searchTypeList)) {
             $correctTypes[] = $type;
         }
     }
     return $correctTypes;
 }
コード例 #26
0
 function testLazyLoadInterfaceGuessNameFromFile()
 {
     $name1 = $this->_rndName();
     $path1 = $this->_writeInterfaceFile($name1, '.php');
     $name2 = $this->_rndName();
     $path2 = $this->_writeInterfaceFile($name2, '.php');
     lmb_require_class($path1);
     lmb_require_class($path2);
     $this->assertFalse(in_array($name1, get_declared_interfaces()));
     $this->assertFalse(in_array($name2, get_declared_interfaces()));
     $this->assertTrue(interface_exists($name1, true));
     //triggers autoload
     $this->assertTrue(in_array($name1, get_declared_interfaces()));
     $this->assertFalse(in_array($name2, get_declared_interfaces()));
 }
コード例 #27
0
 /**
  * Returns string representation of all given arguments.
  *
  * @return string
  */
 function dump()
 {
     $args = func_get_args();
     $bt = debug_backtrace();
     if (count($args) < 1) {
         $args['version'] = PHP_VERSION;
         $args['environment'] = $_SERVER;
         $args['interfaces'] = get_declared_interfaces();
         $args['classes'] = get_declared_classes();
         //$args['constants']        = get_defined_constants(true);
         //$args['functions']        = get_defined_functions();
         //$args['variables']        = get_defined_vars();
         //$args['backtrace']        = $bt;
     }
     $inner = '';
     foreach ($args as $index => $arg) {
         $str = '';
         if (true === $arg) {
             $str = 'true';
         } else {
             if (false === $arg) {
                 $str = 'false';
             } else {
                 $str = print_r($arg, true);
             }
         }
         if (true) {
             //$escape) {
             $index = htmlspecialchars($index, ENT_QUOTES, 'UTF-8');
             $str = htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
         }
         $methods = '';
         if (is_object($arg)) {
             $methods = '<pre>' . print_r(get_class_methods($arg), true) . '</pre>';
         }
         $id = '';
         if ($this->format != 'plain') {
             $id = rawurlencode($index) . str_replace(array('.', ' '), array('_', '_'), microtime());
         }
         $inner .= $this->tr($this->tdnb($id, $index . ' => ' . gettype($arg) . $methods, $id) . $this->td($id, $id, $str));
     }
     if (@$bt[3]['file'] == __FILE__) {
         $bt = $bt[3];
     } else {
         $bt = $bt[2];
     }
     return $this->table($this->tr($this->th($bt['function'], $bt['file'], $bt['line'])) . $inner . $this->trend());
 }
コード例 #28
0
ファイル: MdGen.php プロジェクト: alphayax/phpdoc_md
 /**
  * Load class in the source directory
  */
 protected function loadClasses()
 {
     if (!is_dir($this->srcDirectory)) {
         throw new \Exception('Source directory not found : ' . $this->srcDirectory);
     }
     $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->srcDirectory), \RecursiveIteratorIterator::SELF_FIRST);
     $Regex = new \RegexIterator($objects, '/^.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH);
     foreach ($Regex as $name => $object) {
         if (!empty($name)) {
             require_once $name;
         }
     }
     $classes = get_declared_classes();
     $traits = get_declared_traits();
     $interfaces = get_declared_interfaces();
     $this->loadedClasses = array_merge($classes, $traits, $interfaces);
 }
コード例 #29
0
ファイル: model.php プロジェクト: Debenson/openwan
 protected function _findPackages($files)
 {
     $found_classes = array();
     foreach ($files as $file) {
         require_once $file;
     }
     $classes = array_merge(get_declared_classes(), get_declared_interfaces());
     $this->_last_errors = array();
     foreach ($classes as $class) {
         $doc = new ReflectionClass($class);
         if (!in_array($doc->getFileName(), $files)) {
             continue;
         }
         try {
             $found_classes[] = API_Doc_Class::instance($class);
         } catch (API_Doc_Exception $ex) {
             $this->_last_errors[] = $ex;
         }
     }
     foreach ($found_classes as $class) {
         try {
             $package = $class->package;
             if (!$package) {
                 throw new API_Doc_EmptyPackageException($class, sprintf('Class "%s" use empty package name.', $class->name));
             }
             $package->classes[] = $class;
             if (!isset($this->packages[$package->name])) {
                 $this->packages[$package->name] = $package;
             }
         } catch (API_Doc_Exception $ex) {
             $this->_last_errors[] = $ex;
         }
     }
     $this->classes = $found_classes;
     foreach ($this->packages as $name => $package) {
         $filename = "{$this->docs_dir}/package.{$name}.texy";
         if (is_file($filename)) {
             $contents = file_get_contents($filename);
             $lines = explode("\n", $contents);
             $summary = reset($lines);
             $package->summary = trim($summary);
             $package->description = $contents;
             unset($lines);
         }
     }
 }
コード例 #30
0
ファイル: Compiler.php プロジェクト: snouhaud/camptocamp.org
 /**
  * method for making a single file of most used doctrine runtime components
  * including the compiled file instead of multiple files (in worst
  * cases dozens of files) can improve performance by an order of magnitude
  *
  * @throws Doctrine_Compiler_Exception      if something went wrong during the compile operation
  * @return void
  */
 public static function compile($target = null)
 {
     $path = Doctrine::getPath();
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY);
     foreach ($it as $file) {
         $e = explode('.', $file->getFileName());
         // we don't want to require versioning files
         if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
             require_once $file->getPathName();
         }
     }
     $classes = array_merge(get_declared_classes(), get_declared_interfaces());
     $ret = array();
     foreach ($classes as $class) {
         $e = explode('_', $class);
         if ($e[0] !== 'Doctrine') {
             continue;
         }
         $refl = new ReflectionClass($class);
         $file = $refl->getFileName();
         print 'Adding ' . $file . PHP_EOL;
         $lines = file($file);
         $start = $refl->getStartLine() - 1;
         $end = $refl->getEndLine();
         $ret = array_merge($ret, array_slice($lines, $start, $end - $start));
     }
     if ($target == null) {
         $target = $path . DIRECTORY_SEPARATOR . 'Doctrine.compiled.php';
     }
     // first write the 'compiled' data to a text file, so
     // that we can use php_strip_whitespace (which only works on files)
     $fp = @fopen($target, 'w');
     if ($fp === false) {
         throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open {$target}");
     }
     fwrite($fp, "<?php " . implode('', $ret));
     fclose($fp);
     $stripped = php_strip_whitespace($target);
     $fp = @fopen($target, 'w');
     if ($fp === false) {
         throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open {$file}");
     }
     fwrite($fp, $stripped);
     fclose($fp);
 }