本文整理汇总了PHP中get_declared_traits函数的典型用法代码示例。如果您正苦于以下问题:PHP get_declared_traits函数的具体用法?PHP get_declared_traits怎么用?PHP get_declared_traits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_declared_traits函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: listItems
/**
* {@inheritdoc}
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
{
// bail early if current PHP doesn't know about traits.
if (!function_exists('trait_exists')) {
return;
}
// only list traits when no Reflector is present.
//
// TODO: make a NamespaceReflector and pass that in for commands like:
//
// ls --traits Foo
//
// ... for listing traits in the Foo namespace
if ($reflector !== null || $target !== null) {
return;
}
// only list traits if we are specifically asked
if (!$input->getOption('traits')) {
return;
}
$traits = $this->prepareTraits(get_declared_traits());
if (empty($traits)) {
return;
}
return array('Traits' => $traits);
}
示例3: globalDump
/**
* Global variables dump : dump all variables and resource we can found :
* - $GLOBALS
* - $_SERVER
* - all static property values from classes
*
* I don't know where I could found those : help me if you can !
* - all static variables declared into functions
* - all opened resources (ie files or mysql links)
*
* @param $display boolean|string true or 'pre' if you want to displaying it
* @return array returns the result array
*/
public static function globalDump($display = 'pre')
{
$dump['$GLOBALS'] = $GLOBALS;
$dump['$_SERVER'] = $_SERVER;
foreach (array_merge(get_declared_classes(), get_declared_traits()) as $class) {
foreach ((new Reflection_Class($class))->getProperties([T_EXTENDS, T_USE]) as $property) {
if ($property->isStatic()) {
if (!$property->isPublic()) {
$property->setAccessible(true);
$not_accessible = true;
} else {
$not_accessible = false;
}
$dump['STATIC'][$class][$property->name] = $property->getValue();
if ($not_accessible) {
$property->setAccessible(false);
}
}
}
}
if ($display) {
$pre = $display === 'pre';
echo ($pre ? '<pre>' : '') . print_r($dump, true) . ($pre ? '</pre>' : '');
}
return $dump;
}
示例4: bootTraits
/**
* Allow traits to have custom initialization built in.
*
* @return void
*/
protected function bootTraits()
{
foreach (get_declared_traits() as $trait) {
if (method_exists($this, 'boot' . class_basename($trait))) {
$this->{'boot' . class_basename($trait)}();
}
}
}
示例5: 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)));
}
}
示例6: initialiseTraits
/**
* All declared traits can have their own initialisation method. This function
* iterates over the declared traits and initialises them if necessary.
*
* NB - order of initialisation is order of declaration
*
* This function should be called from the contructor and it passes those
* same variables used for construction to the traits' init methods.
*
* @param null|array $options An array of options
*/
private function initialiseTraits($options)
{
foreach (get_declared_traits() as $trait) {
$fn = "{$trait}_Init";
if (method_exists($this, $fn)) {
$this->{$fn}($options);
}
}
}
示例7: 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);
}
示例8: internalSymbolsProvider
/**
* @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();
}));
}
示例9: get_declared_user_traits
function get_declared_user_traits()
{
$ret = array();
foreach (get_declared_traits() as $v) {
// exclude system traits
$rc = new ReflectionClass($v);
if ($rc->getFileName() !== false) {
$ret[] = $v;
}
}
return $ret;
}
示例10: warmUp
/**
* 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);
}
示例11: processElementsItems
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;
}
示例12: processClassesAndTraits
private function processClassesAndTraits()
{
foreach (array_merge(get_declared_classes(), get_declared_traits()) as $classOrTrait) {
if (isset($this->processedClasses[$classOrTrait])) {
continue;
}
$reflector = new \ReflectionClass($classOrTrait);
foreach ($reflector->getMethods() as $method) {
$this->processFunctionOrMethod($method);
}
$this->processedClasses[$classOrTrait] = true;
}
}
示例13: loadClasses
/**
* 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);
}
示例14: processFiles
/**
* @param string[] $fileNames
* @throws MetaException
* @return boolean
*/
public function processFiles(array $fileNames)
{
$types = array();
foreach ($fileNames as $fileName) {
require_once $fileName;
}
foreach (array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits()) as $typeName) {
$rc = new \ReflectionClass($typeName);
if ($rc->getFileName() && in_array(realpath($rc->getFileName()), $fileNames)) {
$types[] = Type::fromReflection($rc);
}
}
$matched = false;
foreach ($types as $type) {
$result = $this->compile($type);
if ($result === null) {
continue;
}
$matched = true;
$outputFileName = $this->createOutputFileName($type, $result->getClass());
$outputDirectory = dirname($outputFileName);
if (!is_dir($outputDirectory)) {
if (!mkdir($outputDirectory, 0777, true)) {
throw new MetaException("Could not create output directory '{$outputDirectory}'.");
}
}
$content = (string) $result->getFile();
// do not overwrite files with same content
if (!file_exists($outputFileName) || md5_file($outputFileName) !== md5($content)) {
if (!file_put_contents($outputFileName, $content)) {
throw new MetaException("Could not write output to file '{$outputFileName}'.");
}
}
}
return $matched;
}
示例15: get_defined_functions
#!/usr/bin/php
<?php
/**
* Tool to auto insert use statements into PHP
*/
$ignore = get_defined_functions()['internal'];
$ignore = array_merge($ignore, get_declared_classes());
$ignore = array_merge($ignore, get_declared_interfaces());
$ignore = array_merge($ignore, get_declared_traits());
$ignore = array_merge($ignore, array_keys(get_defined_constants()));
$ignore[] = 'parent';
$ignore[] = 'self';
$inputFile = $argv[1];
require dirname(__FILE__) . '/vendor/autoload.php';
/**
* Returns project root path. The root is where composer.json is defined
*/
function findProject($filename)
{
$filename = realpath($filename);
if ($filename == '/') {
return null;
}
if (file_exists(dirname($filename) . '/composer.json')) {
return dirname($filename);
}
return findProject(dirname($filename));
}
/**
* Returns the parsed AST
*/