• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP get_declared_traits函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中get_declared_traits函数的典型用法代码示例。如果您正苦于以下问题:PHP get_declared_traits函数的具体用法?PHP get_declared_traits怎么用?PHP get_declared_traits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_declared_traits函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: declare

<?php

declare (strict_types=1);
namespace Phan\Tests\Language;

// Grab these before we define our own classes
$internal_class_name_list = get_declared_classes();
$internal_interface_name_list = get_declared_interfaces();
$internal_trait_name_list = get_declared_traits();
$internal_function_name_list = get_defined_functions()['internal'];
use Phan\CodeBase;
use Phan\Config;
use Phan\Language\Context;
use Phan\Language\UnionType;
class UnionTypeTest extends \PHPUnit_Framework_TestCase
{
    /** @var Context|null */
    protected $context = null;
    /** @var CodeBase */
    protected $code_base = null;
    protected function setUp()
    {
        global $internal_class_name_list;
        global $internal_interface_name_list;
        global $internal_trait_name_list;
        global $internal_function_name_list;
        $this->code_base = new CodeBase($internal_class_name_list, $internal_interface_name_list, $internal_trait_name_list, $internal_function_name_list);
        $this->context = new Context();
    }
    public function tearDown()
    {
开发者ID:black-silence,项目名称:phan,代码行数:31,代码来源:UnionTypeTest.php


示例17: array_flip

<?php

//========================================================================
// Author:  Pascal KISSIAN
// Resume:  http://pascal.kissian.net
//
// Copyright (c) 2015 Pascal KISSIAN
//
// Published under the MIT License
//          Consider it as a proof of concept!
//          No warranty of any kind.
//          Use and abuse at your own risks.
//========================================================================
$t_pre_defined_classes = array_flip(array_map('strtolower', get_declared_classes()));
$t_pre_defined_interfaces = array_flip(array_map('strtolower', get_declared_interfaces()));
$t_pre_defined_traits = function_exists('get_declared_traits') ? array_flip(array_map('strtolower', get_declared_traits())) : array();
$t_pre_defined_classes = array_merge($t_pre_defined_classes, $t_pre_defined_interfaces, $t_pre_defined_traits);
$t_pre_defined_class_methods = array();
$t_pre_defined_class_methods_by_class = array();
$t_pre_defined_class_properties = array();
$t_pre_defined_class_properties_by_class = array();
$t_pre_defined_class_constants = array();
$t_pre_defined_class_constants_by_class = array();
foreach ($t_pre_defined_classes as $pre_defined_class_name => $dummy) {
    $t = array_flip(array_map('strtolower', get_class_methods($pre_defined_class_name)));
    if (count($t)) {
        $t_pre_defined_class_methods_by_class[$pre_defined_class_name] = $t;
    }
    $t_pre_defined_class_methods = array_merge($t_pre_defined_class_methods, $t);
    $t = get_class_vars($pre_defined_class_name);
    if (count($t)) {
开发者ID:PhungVanDung,项目名称:yakpro-po,代码行数:31,代码来源:get_default_defined_objects.php


示例18: getUserDefinedTraits

function getUserDefinedTraits()
{
    static $traitCutoff;
    $traits = get_declared_traits();
    if (!isset($traitCutoff)) {
        $traitCutoff = count($traits);
        for ($i = 0; $i < count($traits); $i++) {
            $methods = get_class_methods($traits[$i]);
            if (empty($methods)) {
                continue;
            }
            list($first) = $methods;
            if ((new \ReflectionMethod($traits[$i], $first))->isUserDefined()) {
                $traitCutoff = $i;
                break;
            }
        }
    }
    return array_slice($traits, $traitCutoff);
}
开发者ID:pierredup,项目名称:patchwork,代码行数:20,代码来源:Utils.php


示例19: fopen

 $fp = fopen('tags', 'wb');
 $build = function (array $arr) {
     $b = array();
     foreach ($arr as $key => $val) {
         if ($val) {
             $b[] = "{$key}:{$val}";
         }
     }
     return implode("\t", $b);
 };
 $base = dirname(__DIR__) . '/';
 $it = new AppendIterator();
 $it->append(new ArrayIterator(get_declared_classes()));
 $it->append(new ArrayIterator(get_declared_interfaces()));
 if (function_exists('get_declared_traits')) {
     $it->append(new ArrayIterator(get_declared_traits()));
 }
 foreach ($it as $class) {
     $pathes = explode('\\', $class);
     if ('Test' === substr($class, -4) || 'Spec' === substr($class, -4) || 'PHP_Token_' === substr($class, 0, 10) || 'Double' === $pathes[0] || in_array('Test', $pathes) || in_array('Spec', $pathes)) {
         continue;
     }
     $rc = new ReflectionClass($class);
     if ($rc->isInternal()) {
         continue;
     }
     if ($rc->isInterface()) {
         $kind = 'i';
     } elseif (method_exists($rc, 'isTrait')) {
         if ($rc->isTrait()) {
             $kind = 't';
开发者ID:DQNEO,项目名称:prestissimo,代码行数:31,代码来源:bootstrap.php


示例20: __construct

 /**
  * Creates a snapshot of the current global state.
  *
  * @param Blacklist $blacklist
  * @param boolean   $includeGlobalVariables
  * @param boolean   $includeStaticAttributes
  * @param boolean   $includeConstants
  * @param boolean   $includeFunctions
  * @param boolean   $includeClasses
  * @param boolean   $includeInterfaces
  * @param boolean   $includeTraits
  * @param boolean   $includeIniSettings
  * @param boolean   $includeIncludedFiles
  */
 public function __construct(Blacklist $blacklist = null, $includeGlobalVariables = true, $includeStaticAttributes = true, $includeConstants = true, $includeFunctions = true, $includeClasses = true, $includeInterfaces = true, $includeTraits = true, $includeIniSettings = true, $includeIncludedFiles = true)
 {
     if ($blacklist === null) {
         $blacklist = new Blacklist();
     }
     $this->blacklist = $blacklist;
     if ($includeConstants) {
         $this->snapshotConstants();
     }
     if ($includeFunctions) {
         $this->snapshotFunctions();
     }
     if ($includeClasses || $includeStaticAttributes) {
         $this->snapshotClasses();
     }
     if ($includeInterfaces) {
         $this->snapshotInterfaces();
     }
     if ($includeGlobalVariables) {
         $this->setupSuperGlobalArrays();
         $this->snapshotGlobals();
     }
     if ($includeStaticAttributes) {
         $this->snapshotStaticAttributes();
     }
     if ($includeIniSettings) {
         $this->iniSettings = ini_get_all(null, false);
     }
     if ($includeIncludedFiles) {
         $this->includedFiles = get_included_files();
     }
     if (function_exists('get_declared_traits')) {
         $this->traits = get_declared_traits();
     }
 }
开发者ID:ProgrammingPeter,项目名称:nba-schedule-api,代码行数:49,代码来源:Snapshot.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_default函数代码示例发布时间:2022-05-15
下一篇:
PHP get_declared_interfaces函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap