本文整理汇总了PHP中ReflectionClass::getStaticProperties方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::getStaticProperties方法的具体用法?PHP ReflectionClass::getStaticProperties怎么用?PHP ReflectionClass::getStaticProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::getStaticProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_function
/**
* @return void
*/
public function test_function()
{
// prepare
Base::init([]);
$reflection = new \ReflectionClass('\\DbMockLibrary\\Base');
$staticProperties = $reflection->getStaticProperties();
// test
$this->assertInstanceOf('\\DbMockLibrary\\Base', $staticProperties['instance']);
// invoke logic
Base::getInstance()->destroy();
// prepare
$staticProperties = $reflection->getStaticProperties();
// test
$this->assertNull($staticProperties['instance']);
}
示例2: addTestFile
public function addTestFile($file, $internalcall = false)
{
global $CFG;
if ($this->performcoverage) {
$refinfo = moodle_reflect_file($file);
require_once $file;
if ($refinfo->classes) {
foreach ($refinfo->classes as $class) {
$reflection = new ReflectionClass($class);
if ($staticprops = $reflection->getStaticProperties()) {
if (isset($staticprops['includecoverage']) && is_array($staticprops['includecoverage'])) {
foreach ($staticprops['includecoverage'] as $toinclude) {
$this->add_coverage_include_path($toinclude);
}
}
if (isset($staticprops['excludecoverage']) && is_array($staticprops['excludecoverage'])) {
foreach ($staticprops['excludecoverage'] as $toexclude) {
$this->add_coverage_exclude_path($toexclude);
}
}
}
}
// Automatically add the test dir itself, so nothing will be covered there
$this->add_coverage_exclude_path(dirname($file));
}
}
parent::addTestFile($file, $internalcall);
}
示例3: testRegisterValidator
public function testRegisterValidator()
{
Comfort::registerValidator('flex', ComfortTestCustomerValidator::class);
$reflClass = new \ReflectionClass(Comfort::class);
$staticProperties = $reflClass->getStaticProperties();
$this->assertEquals(['registeredValidators' => ['flex' => ComfortTestCustomerValidator::class]], $staticProperties);
}
示例4: __toString
/**
* Dump all class members to array including objects
*
* @return string print_r() formatted array string;
*/
public function __toString()
{
# Dump all object vars to string
# Recursively list all object vars
$members = function ($object) use(&$members) {
# Recursive closure... cool!
if (!is_object($object) && !is_array($object)) {
# We've found an actual member value
return is_array($object) ? print_r($object) : $object;
}
# We've found a member that's an object, explore it's properties
if (is_object($object)) {
# Duplicate our object for inspection
$reflection = new \ReflectionClass($object);
# Get dynamic members
$dynamics = get_object_vars($object);
# Get constant members
$constants = $reflection->getConstants();
# Get static members
$statics = $reflection->getStaticProperties();
# = array_diff(get_class_vars(get_class($object)), $dynamic); # alternate method
# Merge them
$object = array_merge($constants, $statics, $dynamics);
}
# Recurse to check if the array has any further objects
return array_map($members, $object);
};
# All done build our string!
return '<pre>' . print_r($members($this), true) . '</pre>';
}
示例5: testCounterNotNull
/**
* Test the initialization of the static counter (!== 0)
*/
public function testCounterNotNull()
{
$rand = new MicroTime();
$reflection_class = new \ReflectionClass("RandomLib\\Source\\MicroTime");
$static = $reflection_class->getStaticProperties();
$this->assertTrue($static['counter'] !== 0);
}
示例6: load
public static function load($path = '')
{
if (!empty($path) and !in_array($path, self::$loaded)) {
$path = !empty($path) ? '\\' . trim($path, '\\') : '';
$lang_class = '\\GCore' . $path . '\\Locales\\EnGb\\Lang';
$cutsom_lang = '\\GCore' . $path . '\\Locales\\' . Str::camilize(str_replace('-', '_', strtolower(Base::getConfig('site_language', 'en-gb')))) . '\\Lang';
if (class_exists($cutsom_lang)) {
if (class_exists($lang_class)) {
//load default language as well
$lang_class_loaded = new \ReflectionClass($lang_class);
self::$translations = array_merge((array) self::$translations, $lang_class_loaded->getConstants(), $lang_class_loaded->getStaticProperties());
self::$loaded[] = $path;
}
$lang_class = $cutsom_lang;
}
if (!class_exists($lang_class)) {
return false;
}
$lang_class_loaded = new \ReflectionClass($lang_class);
self::$translations = array_merge((array) self::$translations, $lang_class_loaded->getConstants(), $lang_class_loaded->getStaticProperties());
self::$loaded[] = $path;
return true;
}
return false;
}
示例7: setFormat
public function setFormat($f)
{
//use reflection to valid value
$ref = new ReflectionClass(__CLASS__);
if (in_array($f, $ref->getStaticProperties())) {
$this->_format = $f;
}
}
示例8: rewind
public function rewind()
{
$class_name = get_class($this);
$reflection = new \ReflectionClass($class_name);
$this->staticFieldIteratorData = $reflection->getStaticProperties();
$this->staticFieldIteratorKey = 0;
reset($this->staticFieldIteratorData);
}
示例9: testBasicValidSchemes
public function testBasicValidSchemes()
{
$mirror = new \ReflectionClass(Url::class);
$validSchemes = $mirror->getStaticProperties()['validSchemes'];
foreach ($validSchemes as $scheme) {
$this->assertTrue(Url::isValidScheme($scheme));
}
}
示例10: testCounterNotNull
/**
* Test the initialization of the static counter (!== 0)
*/
public function testCounterNotNull()
{
$class = static::getTestedClass();
$rand = new $class();
$reflection_class = new \ReflectionClass($class);
$static = $reflection_class->getStaticProperties();
$this->assertTrue($static['counter'] !== 0);
}
示例11: get_all
/**
* Get all the states in an array.
* @return of question_state objects.
*/
public static function get_all()
{
$states = array();
$us = new ReflectionClass('question_state');
foreach ($us->getStaticProperties() as $name => $notused) {
$states[] = self::${$name};
}
return $states;
}
示例12: testLoadVendorDatabaseFromFile
public function testLoadVendorDatabaseFromFile()
{
// Clear database first to ensure that data actually gets loaded
MacAddress::loadVendorDatabase(array());
// Pass default database. It should load without errors.
MacAddress::loadVendorDatabaseFromFile(\Library\Module::getPath('data/MacAddress/manuf'));
$reflectionClass = new \ReflectionClass('Library\\MacAddress');
$this->assertNotEmpty($reflectionClass->getStaticProperties()['_vendorList']);
}
示例13: testExitCode
public function testExitCode()
{
$ref = new ReflectionClass("Application");
$static_values = $ref->getStaticProperties();
// $success_code = $ref->getStaticPropertyValue("SUCCESS");
$this->assertEquals(0, $static_values["SUCCESS"]);
// $error_code = $ref->getStaticPropertyValue("ERROR");
$this->assertEquals(1, $static_values["ERROR"]);
}
示例14: GetKeys
/**
* List all available properties through reflection
* FIXME: Move to parent class Struct, when php will have late static binding
*
* @return array or names
*/
public static function GetKeys()
{
$retval = array();
$ReflectionClassThis = new ReflectionClass(__CLASS__);
foreach($ReflectionClassThis->getStaticProperties() as $Property)
{
$retval[] = $Property->name;
}
return($retval);
}
示例15: importGlobals
/**
* A function to be used for compatibility with legacy code: it gets the values of all global variables which used
* to be declared, such as library version etc... and sets them to php classes.
* It should be used by code which changed the values of those global variables to alter the working of the library.
* Example code:
* 1. include xmlrpc.inc
* 2. set the values, e.g. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
* 3. import them: PhpXmlRpc\PhpXmlRpc::importGlobals();
* 4. run your own code.
*/
public static function importGlobals()
{
$reflection = new \ReflectionClass('PhpXmlRpc\\PhpXmlRpc');
$staticProperties = $reflection->getStaticProperties();
foreach ($staticProperties as $name => $value) {
if (isset($GLOBALS[$name])) {
self::${$name} = $GLOBALS[$name];
}
}
}