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


PHP get_declared_traits函数代码示例

本文整理汇总了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);
    }
}
开发者ID:bateller,项目名称:phan,代码行数:28,代码来源:util.php

示例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);
 }
开发者ID:duxor,项目名称:GUSLE,代码行数:29,代码来源:TraitEnumerator.php

示例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;
 }
开发者ID:TuxBoy,项目名称:Demo-saf,代码行数:39,代码来源:Debug.php

示例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)}();
         }
     }
 }
开发者ID:spira,项目名称:api-core,代码行数:13,代码来源:TestCase.php

示例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)));
     }
 }
开发者ID:yceruto,项目名称:symfony,代码行数:69,代码来源:ClassCollectionLoader.php

示例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);
         }
     }
 }
开发者ID:opensolutions,项目名称:oss-framework,代码行数:20,代码来源:Trait.php

示例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);
 }
开发者ID:jdolieslager,项目名称:celeritas,代码行数:60,代码来源:Cacher.php

示例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();
     }));
 }
开发者ID:AydinHassan,项目名称:BetterReflection,代码行数:14,代码来源:PhpInternalSourceLocatorTest.php

示例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;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:12,代码来源:2042.php

示例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);
 }
开发者ID:ayoah,项目名称:symfony,代码行数:17,代码来源:ClassCacheCacheWarmer.php

示例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;
 }
开发者ID:fixin,项目名称:fixin,代码行数:13,代码来源:Processor.php

示例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;
     }
 }
开发者ID:ezrra,项目名称:PHP,代码行数:13,代码来源:Wizard.php

示例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);
 }
开发者ID:alphayax,项目名称:phpdoc_md,代码行数:20,代码来源:MdGen.php

示例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;
 }
开发者ID:jakubkulhan,项目名称:meta,代码行数:41,代码来源:AbstractMetaSpec.php

示例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
 */
开发者ID:knuthelland,项目名称:phpimports,代码行数:31,代码来源:phpimports.php


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