本文整理汇总了PHP中get_declared_interfaces函数的典型用法代码示例。如果您正苦于以下问题:PHP get_declared_interfaces函数的具体用法?PHP get_declared_interfaces怎么用?PHP get_declared_interfaces使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_declared_interfaces函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: 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)));
}
}
示例3: __construct
/**
* 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: execute
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: __construct
/** @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: info
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: add_internal
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: parseClassLists
/**
* 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: scan
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: minifyYii
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: __construct
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: executeOnce
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: testOneClass
/**
* @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: 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 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: cache
/**
* 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);
}