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


PHP ReflectionFunction::getStaticVariables方法代码示例

本文整理汇总了PHP中ReflectionFunction::getStaticVariables方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunction::getStaticVariables方法的具体用法?PHP ReflectionFunction::getStaticVariables怎么用?PHP ReflectionFunction::getStaticVariables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionFunction的用法示例。


在下文中一共展示了ReflectionFunction::getStaticVariables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: serialize

 /**
  * @link http://php.net/manual/en/serializable.serialize.php
  */
 public function serialize()
 {
     // prepare code
     $file = new SplFileObject($this->reflection->getFileName());
     $file->seek($this->reflection->getStartLine() - 1);
     $code = '';
     while ($file->key() < $this->reflection->getEndLine()) {
         $code .= $file->current();
         $file->next();
     }
     $start = strpos($code, 'function');
     $code = substr($code, $start, strpos($code, '}') - $start + 1);
     // prepare variables
     $variables = [];
     $index = stripos($code, 'use');
     // if 'use' keyword found
     if (false !== $index) {
         // get the names of the variables inside the use statement
         $start = strpos($code, '(', $index) + 1;
         $end = strpos($code, ')', $start);
         $use_variables = explode(',', substr($code, $start, $end - $start));
         $static_variables = $this->reflection->getStaticVariables();
         // keep only the variables that appeared in both scopes
         foreach ($use_variables as $variable) {
             $variable = trim($variable, '$&');
             $variables[$variable] = $static_variables[$variable];
         }
     }
     return serialize(['code' => $code, 'variables' => $variables]);
 }
开发者ID:acfatah,项目名称:serializable-closure,代码行数:33,代码来源:SerializableClosure.php

示例2: view

 public function view()
 {
     $services = array();
     $bindings = Core::getBindings();
     foreach ($bindings as $name => $binding) {
         /** @var \Closure $binding */
         $reflection = new \ReflectionFunction($binding['concrete']);
         $static = $reflection->getStaticVariables();
         $className = null;
         if (!isset($static['concrete'])) {
             try {
                 $class = Core::make($name);
                 $className = get_class($class);
             } catch (\Exception $e) {
             }
         } else {
             $className = $static['concrete'];
         }
         if ($className !== null && $className !== get_class($this)) {
             if ($className[0] !== '\\') {
                 $className = '\\' . $className;
             }
             $services[$name] = array('class' => $className);
         }
     }
     ksort($services);
     $this->set('services', $services);
 }
开发者ID:BacLuc,项目名称:newGryfiPage,代码行数:28,代码来源:services.php

示例3: parse

 public function parse(&$variable)
 {
     if (!$variable instanceof Closure) {
         return false;
     }
     $this->name = 'Closure';
     $reflection = new ReflectionFunction($variable);
     $ret = array('Parameters' => array());
     if ($val = $reflection->getParameters()) {
         foreach ($val as $parameter) {
             // todo http://php.net/manual/en/class.reflectionparameter.php
             $ret['Parameters'][] = $parameter->name;
         }
     }
     if ($val = $reflection->getStaticVariables()) {
         $ret['Uses'] = $val;
     }
     if (method_exists($reflection, 'getClousureThis') && ($val = $reflection->getClosureThis())) {
         $ret['Uses']['$this'] = $val;
     }
     if ($val = $reflection->getFileName()) {
         $this->value = Kint::shortenPath($val) . ':' . $reflection->getStartLine();
     }
     return $ret;
 }
开发者ID:DeRossi,项目名称:Training_CI,代码行数:25,代码来源:closure.php

示例4: getStaticVariables

 /**
  * Returns an associative array containing this function's static variables
  * and their values
  *
  * @return array<sting,mixed> This function's static variables
  */
 public function getStaticVariables()
 {
     if ($this->reflectionSource instanceof ReflectionFunction) {
         return $this->reflectionSource->getStaticVariables();
     } else {
         return parent::getStaticVariables();
     }
 }
开发者ID:zetacomponents,项目名称:reflection,代码行数:14,代码来源:function.php

示例5: dumpFuncInfo

function dumpFuncInfo($name)
{
    $funcInfo = new ReflectionFunction($name);
    var_dump($funcInfo->getName());
    var_dump($funcInfo->isInternal());
    var_dump($funcInfo->isUserDefined());
    var_dump($funcInfo->getStartLine());
    var_dump($funcInfo->getEndLine());
    var_dump($funcInfo->getStaticVariables());
}
开发者ID:badlamer,项目名称:hhvm,代码行数:10,代码来源:ReflectionFunction_001.php

示例6: render

 public function render()
 {
     $file = '<?php namespace PHPSTORM_META { $STATIC_METHOD_TYPES = array(\\Core::make(\'\') => array(' . PHP_EOL;
     $legacyHelpers = array();
     $bindings = Core::getBindings();
     foreach ($bindings as $name => $binding) {
         /** @var \Closure $binding */
         $reflection = new \ReflectionFunction($binding['concrete']);
         $static = $reflection->getStaticVariables();
         $className = null;
         if (!isset($static['concrete'])) {
             try {
                 $class = Core::make($name);
                 if (is_object($class)) {
                     $className = get_class($class);
                 }
             } catch (\Exception $e) {
             }
         } else {
             $className = $static['concrete'];
         }
         if ($className !== null && $className !== get_class($this)) {
             if ($className[0] !== '\\') {
                 $className = '\\' . $className;
             }
             $file .= '\'' . $name . '\' instanceof ' . $className . ',' . PHP_EOL;
             if (substr($name, 0, 7) === 'helper/') {
                 $legacyHelpers[substr($name, 7)] = $className;
             }
         }
     }
     $app = Core::make('app');
     $reflection = new \ReflectionClass($app);
     $instances = $reflection->getProperty("instances");
     $instances->setAccessible(true);
     // :)
     foreach ($instances->getValue($app) as $name => $instance) {
         if (!isset($bindings[$name])) {
             $className = get_class($instance);
             $file .= '\'' . $name . '\' instanceof ' . $className . ',' . PHP_EOL;
         }
     }
     $file .= '), \\Loader::helper(\'\') => array(';
     foreach ($legacyHelpers as $legacyHelper => $className) {
         $file .= '\'' . $legacyHelper . '\' instanceof ' . $className . ',' . PHP_EOL;
     }
     $file .= '), \\Package::getByHandle(\'\') => array(';
     $packages = \Package::getAvailablePackages(false);
     foreach ($packages as $package) {
         /** @var \Package $package */
         $file .= '\'' . $package->getPackageHandle() . '\' instanceof \\' . get_class($package) . ',' . PHP_EOL;
     }
     $file .= '));}';
     return $file;
 }
开发者ID:digideskio,项目名称:concrete5,代码行数:55,代码来源:MetadataGenerator.php

示例7: makeId

 public function makeId(\Closure $callback)
 {
     $ref = new \ReflectionFunction($callback);
     $file = new \SplFileObject($ref->getFileName());
     $file->seek($ref->getStartLine() - 1);
     $content = '';
     while ($file->key() < $ref->getEndLine()) {
         $content .= $file->current();
         $file->next();
     }
     return sha1(json_encode(array($content, $ref->getStaticVariables(), $ref->getFileName(), $ref->getStartLine() - 1, $ref->getEndLine())));
 }
开发者ID:schpill,项目名称:standalone,代码行数:12,代码来源:closure.php

示例8: getVariables

 /**
  * Get the variables used by the Closure.
  *
  * @return array
  */
 public function getVariables()
 {
     if (!$this->getUseIndex()) {
         return array();
     }
     $staticVariables = $this->reflection->getStaticVariables();
     // When looping through the variables, we will only take the variables that are
     // specified in the use clause, and will not take any other static variables
     // that may be used by the Closures, allowing this to re-create its state.
     $usedVariables = array();
     foreach ($this->getUseClauseVariables() as $variable) {
         $variable = trim($variable, ' $&');
         $usedVariables[$variable] = $staticVariables[$variable];
     }
     return $usedVariables;
 }
开发者ID:centaurustech,项目名称:sagip,代码行数:21,代码来源:SerializableClosure.php

示例9: unwrap

 public static function unwrap(\Closure $closure)
 {
     $reflectionFunction = new \ReflectionFunction($closure);
     if (substr($reflectionFunction->getName(), -1) === '}') {
         $vars = $reflectionFunction->getStaticVariables();
         return isset($vars['_callable_']) ? $vars['_callable_'] : $closure;
     } else {
         if ($obj = $reflectionFunction->getClosureThis()) {
             return [$obj, $reflectionFunction->getName()];
         } else {
             if ($class = $reflectionFunction->getClosureScopeClass()) {
                 return [$class->getName(), $reflectionFunction->getName()];
             }
         }
     }
     return $reflectionFunction->getName();
 }
开发者ID:edde-framework,项目名称:edde,代码行数:17,代码来源:CallbackUtils.php

示例10: verifyCallbackJob

 private function verifyCallbackJob($callback, LinkTarget $expectedTitle, $expectedUserId, callable $notificationTimestampCondition)
 {
     $this->assertInternalType('callable', $callback);
     $callbackReflector = new ReflectionFunction($callback);
     $vars = $callbackReflector->getStaticVariables();
     $this->assertArrayHasKey('job', $vars);
     $this->assertInstanceOf(ActivityUpdateJob::class, $vars['job']);
     /** @var ActivityUpdateJob $job */
     $job = $vars['job'];
     $this->assertEquals($expectedTitle->getDBkey(), $job->getTitle()->getDBkey());
     $this->assertEquals($expectedTitle->getNamespace(), $job->getTitle()->getNamespace());
     $jobParams = $job->getParams();
     $this->assertArrayHasKey('type', $jobParams);
     $this->assertEquals('updateWatchlistNotification', $jobParams['type']);
     $this->assertArrayHasKey('userid', $jobParams);
     $this->assertEquals($expectedUserId, $jobParams['userid']);
     $this->assertArrayHasKey('notifTime', $jobParams);
     $this->assertTrue($notificationTimestampCondition($jobParams['notifTime']));
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:19,代码来源:WatchedItemStoreUnitTest.php

示例11: formatStaticVariables

 /**
  * Format static (used) variable names.
  *
  * @param \Closure $value
  *
  * @return string
  */
 protected function formatStaticVariables(\Closure $value)
 {
     $r = new \ReflectionFunction($value);
     $used = $r->getStaticVariables();
     if (empty($used)) {
         return '';
     }
     $names = array_map(array($this, 'formatParamName'), array_keys($used));
     return sprintf(self::USE_FMT, implode(', ', $names));
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:17,代码来源:ClosurePresenter.php

示例12: dummy

<?php

function dummy()
{
    static $a = array();
}
class Test
{
    const A = 0;
    public function func()
    {
        static $a = array(self::A => 'a');
    }
}
$reflect = new ReflectionFunction("dummy");
print_r($reflect->getStaticVariables());
$reflect = new ReflectionMethod('Test', 'func');
print_r($reflect->getStaticVariables());
开发者ID:badlamer,项目名称:hhvm,代码行数:18,代码来源:bug63614.php

示例13: _dumpObject

 /**
  * Dump an object
  *
  * @param   mixed         $var    Variable to dump
  * @param   KObjectConfig $config The configuration options
  * @param   integer       $level  Current recursion level (internal usage only)
  * @return  string
  */
 protected function _dumpObject($var, KObjectConfig $config, $level = 0)
 {
     $fields = $this->_getObjectVars($var);
     if ($var instanceof Closure) {
         $rc = new ReflectionFunction($var);
         $fields = array();
         foreach ($rc->getParameters() as $param) {
             $fields[] = '$' . $param->getName();
         }
         $fields = array('file' => $rc->getFileName(), 'line' => $rc->getStartLine(), 'variables' => $rc->getStaticVariables(), 'parameters' => implode(', ', $fields));
     }
     if ($var instanceof SplFileInfo) {
         $fields = array('path' => $var->getPathname());
     }
     if ($var instanceof SplObjectStorage) {
         $fields = array();
         foreach (clone $var as $obj) {
             $fields[] = array('object' => $obj, 'data' => $var[$obj]);
         }
     }
     if ($var instanceof KObjectInterface) {
         unset($fields['__methods']);
     }
     if ($var instanceof KObjectManager) {
         $fields = array();
     }
     if ($var instanceof KObjectConfigInterface) {
         $fields = $var->toArray();
     }
     $result = '';
     $result .= '<span class="koowa-dump-object">' . get_class($var) . '</span>';
     if ($var instanceof KObjectInterface) {
         $result .= '<span class="koowa-dump-identifier">(' . $var->getIdentifier() . ')</span>';
     }
     $result .= '<span class="koowa-dump-hash">#' . substr(md5(spl_object_hash($var)), 0, 4) . '</span>';
     static $list = array();
     if (!empty($fields)) {
         if (!in_array($var, $list, true)) {
             if ($level < $config->object_depth || $var instanceof Closure) {
                 $collapsed = $level ? count($var) >= 7 : false;
                 $result = '<span class="koowa-toggle' . ($collapsed ? ' koowa-collapsed' : '') . '">' . $result . '</span>';
                 $result .= '<div' . ($collapsed ? ' class="koowa-collapsed"' : '') . '>';
                 $list[] = $var;
                 foreach ($fields as $key => $value) {
                     $vis = '';
                     if ($key[0] === "") {
                         $vis = ' <span class="koowa-dump-visibility">' . ($key[1] === '*' ? 'protected' : 'private') . '</span>';
                         $key = substr($key, strrpos($key, "") + 1);
                     }
                     $result .= '<span class="koowa-dump-indent">   ' . str_repeat('|  ', $level) . '</span>';
                     $result .= '<span class="koowa-dump-key">' . (preg_match('#^\\w+\\z#', $key) ? $key : $this->getTemplate()->escape($key)) . '</span> ' . $vis . ' => ';
                     $result .= $this->_dumpVar($value, $config, $level + 1);
                 }
                 array_pop($list);
                 $result .= '</div>';
             } else {
                 $result .= ' { ... }' . "\n";
             }
         } else {
             $result .= ' { <i>RECURSION</i> }' . "\n";
         }
     } else {
         $result .= "\n";
     }
     return $result;
 }
开发者ID:daodaoliang,项目名称:nooku-framework,代码行数:74,代码来源:debug.php

示例14: cacheFun

 /**
  * cache function result and return it
  * @param $function closure to cache 
  * @return object     
  */
 public function cacheFun($function)
 {
     if ($this->getConfig('debug') && !is_callable($function)) {
         echo "no valid function";
     }
     $r = new ReflectionFunction($function);
     $id = null;
     foreach ($r->getStaticVariables() as $key => $var) {
         if ($key == 'key') {
             $id = $var;
         }
     }
     if (is_object($id)) {
         $id = $this->getIDfromOjb($id);
     }
     if ($id == null && $this->getConfig('debug')) {
         echo "no caching key";
         return $function();
     }
     $cachefile = $this->getConfig('cacheDir') . '/' . utf8_decode($id);
     $cachetime = $this->getConfig('cacheTime');
     if (file_exists($cachefile) && time() - $cachetime < fileatime($cachefile)) {
         $ser = file_get_contents($cachefile);
         $val = bzdecompress(unserialize($ser));
         return $val;
     } else {
         $value = $function();
         $ser = serialize(bzcompress($value));
         file_put_contents($cachefile, $ser);
         return $value;
     }
     if ($this->getConfig('debug')) {
         echo "no caching";
     }
 }
开发者ID:christianklisch,项目名称:phpcache,代码行数:40,代码来源:PHPCache.class.php

示例15: getMemoryBreakdown

 /**
  * Get a memory usage breakdown
  * @return array
  */
 function getMemoryBreakdown()
 {
     $memStats = array();
     foreach ($GLOBALS as $name => $value) {
         $memStats['$' . $name] = strlen(serialize($value));
     }
     $classes = get_declared_classes();
     foreach ($classes as $class) {
         $rc = new ReflectionClass($class);
         $props = $rc->getStaticProperties();
         $memStats[$class] = strlen(serialize($props));
         $methods = $rc->getMethods();
         foreach ($methods as $method) {
             $memStats[$class] += strlen(serialize($method->getStaticVariables()));
         }
     }
     $functions = get_defined_functions();
     foreach ($functions['user'] as $function) {
         $rf = new ReflectionFunction($function);
         $memStats["{$function}()"] = strlen(serialize($rf->getStaticVariables()));
     }
     asort($memStats);
     return $memStats;
 }
开发者ID:huatuoorg,项目名称:mediawiki,代码行数:28,代码来源:NewParserTest.php


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