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


PHP ReflectionClass::getConstants方法代码示例

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


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

示例1: exportCode

 /**
  * Exports the PHP code
  *
  * @return string
  */
 public function exportCode()
 {
     $code_lines = array();
     $code_lines[] = '<?php';
     // Export the namespace
     if ($this->_reflection_class->getNamespaceName()) {
         $code_lines[] = '';
         $code_lines[] = 'namespace ' . $this->_reflection_class->getNamespaceName() . ';';
         $code_lines[] = '';
     }
     // Export the class' signature
     $code_lines[] = sprintf('%s%s%s %s%s%s', $this->_reflection_class->isAbstract() ? 'abstract ' : '', $this->_reflection_class->isFinal() ? 'final ' : '', $this->_reflection_class->isInterface() ? 'interface' : ($this->_reflection_class->isTrait() ? 'trait' : 'class'), $this->getClassName(), $this->_getParentClassName() ? " extends {$this->_getParentClassName()}" : '', $this->_getInterfaceNames() ? " implements " . join(', ', $this->_getInterfaceNames()) : '');
     $code_lines[] = '{';
     $code_lines[] = '';
     // Export constants
     foreach ($this->_reflection_class->getConstants() as $name => $value) {
         $reflection_constant = new ReflectionConstant($name, $value);
         $code_lines[] = "\t" . $reflection_constant->exportCode();
         $code_lines[] = '';
     }
     // Export properties
     foreach ($this->_reflection_class->getProperties() as $property) {
         $reflection_property = new ReflectionProperty($property);
         $code_lines[] = "\t" . $reflection_property->exportCode();
         $code_lines[] = '';
     }
     // Export methods
     foreach ($this->_reflection_class->getMethods() as $method) {
         $reflection_method = new ReflectionMethod($method);
         $code_lines[] = "\t" . $reflection_method->exportCode();
         $code_lines[] = '';
     }
     $code_lines[] = '}';
     return join("\n", $code_lines);
 }
开发者ID:michalkoslab,项目名称:Helpers,代码行数:40,代码来源:ReflectionClass.php

示例2: __construct

 /**
  * Constructor.
  *
  * @param \ReflectionClass $class ReflectionClass object.
  * @param array $options Configuration options.
  */
 public function __construct(\ReflectionClass $class, array $options = array())
 {
     parent::__construct($options);
     $this->class = $class;
     $this->constants = $this->class->getConstants();
     // sort by constant name
     ksort($this->constants);
 }
开发者ID:satooshi,项目名称:object-inspector,代码行数:14,代码来源:ObjectConstantInspector.php

示例3: testAllClassConstantsAreValidTypes

 public function testAllClassConstantsAreValidTypes()
 {
     $reflection = new \ReflectionClass('\\Desk\\Client');
     foreach ($reflection->getConstants() as $constant => $constantValue) {
         $this->assertTrue(Client::isValidType($constantValue), "Desk\\Client::isValidType() returns FALSE for class " . "constant \"{$constant}\", all Desk\\Client class " . "constants should be valid client types");
     }
 }
开发者ID:99designs,项目名称:php-desk,代码行数:7,代码来源:ClientTest.php

示例4: identifiers

 protected function identifiers()
 {
     $refl = new \ReflectionClass($this);
     $constants = $refl->getConstants();
     asort($constants);
     return $constants;
 }
开发者ID:irwtdvoys,项目名称:bolt,代码行数:7,代码来源:Enum.php

示例5: loadValues

 /**
  * @throws Exception\InvalidEnumerationValueException
  * @throws Exception\InvalidEnumerationDefinitionException
  * @internal param string $class
  */
 protected static function loadValues()
 {
     $class = get_called_class();
     if (isset(static::$enumConstants[$class])) {
         return;
     }
     $reflection = new \ReflectionClass($class);
     $constants = $reflection->getConstants();
     $defaultValue = NULL;
     if (isset($constants['__default'])) {
         $defaultValue = $constants['__default'];
         unset($constants['__default']);
     }
     if (empty($constants)) {
         throw new Exception\InvalidEnumerationValueException(sprintf('No enumeration constants defined for "%s"', $class), 1381512807);
     }
     foreach ($constants as $constant => $value) {
         if (!is_int($value) && !is_string($value)) {
             throw new Exception\InvalidEnumerationDefinitionException(sprintf('Constant value must be of type integer or string; constant=%s; type=%s', $constant, is_object($value) ? get_class($value) : gettype($value)), 1381512797);
         }
     }
     $constantValueCounts = array_count_values($constants);
     arsort($constantValueCounts, SORT_NUMERIC);
     $constantValueCount = current($constantValueCounts);
     $constant = key($constantValueCounts);
     if ($constantValueCount > 1) {
         throw new Exception\InvalidEnumerationDefinitionException(sprintf('Constant value is not unique; constant=%s; value=%s; enum=%s', $constant, $constantValueCount, $class), 1381512859);
     }
     if ($defaultValue !== NULL) {
         $constants['__default'] = $defaultValue;
     }
     static::$enumConstants[$class] = $constants;
 }
开发者ID:plan2net,项目名称:TYPO3.CMS,代码行数:38,代码来源:Enumeration.php

示例6: __construct

 /**
  * @return Tx_PtExtbase_Utility_ConstantToSpeakingNameMapper
  */
 public function __construct()
 {
     $className = $this->getClassName();
     $constantsReflection = new ReflectionClass($className);
     $this->originalSpeakingNameToConstantMapping = $constantsReflection->getConstants();
     $this->buildMaps();
 }
开发者ID:beyond-agentur,项目名称:pt_extbase,代码行数:10,代码来源:ConstantToSpeakingNameMapper.php

示例7: __construct

 /**
  * @param \PhpSigep\Model\PreListaDePostagem $plp
  * @param int $idPlpCorreios
  * @param string $logoFile
  * @throws InvalidArgument
  *      Se o arquivo $logoFile não existir.
  */
 public function __construct($plp, $idPlpCorreios, $logoFile, $chancelas = array())
 {
     if ($logoFile && !@getimagesize($logoFile)) {
         throw new InvalidArgument('O arquivo "' . $logoFile . '" não existe.');
     }
     $this->plp = $plp;
     $this->idPlpCorreios = $idPlpCorreios;
     $this->logoFile = $logoFile;
     $rClass = new \ReflectionClass(__CLASS__);
     $tiposChancela = $rClass->getConstants();
     foreach ($chancelas as $chancela) {
         switch ($chancela) {
             case CartaoDePostagem::TYPE_CHANCELA_CARTA:
             case CartaoDePostagem::TYPE_CHANCELA_CARTA_2016:
                 $this->layoutCarta = $chancela;
                 break;
             case CartaoDePostagem::TYPE_CHANCELA_SEDEX:
             case CartaoDePostagem::TYPE_CHANCELA_SEDEX_2016:
                 $this->layoutSedex = $chancela;
                 break;
             case CartaoDePostagem::TYPE_CHANCELA_PAC:
             case CartaoDePostagem::TYPE_CHANCELA_PAC_2016:
                 $this->layoutPac = $chancela;
                 break;
             default:
                 throw new \PhpSigep\Pdf\Exception\InvalidChancelaEntry('O tipo de chancela deve ser uma das constantes da classe');
         }
     }
     $this->init();
 }
开发者ID:stavarengo,项目名称:php-sigep,代码行数:37,代码来源:CartaoDePostagem.php

示例8: imprimeProdutos

 public function imprimeProdutos()
 {
     $reflection = new ReflectionClass(__CLASS__);
     for ($i = 1; $i <= count($reflection->getConstants()); $i++) {
         echo $reflection->getConstant("PRODUTO{$i}") . PHP_EOL;
     }
 }
开发者ID:AmmonMa,项目名称:saladeaula_php,代码行数:7,代码来源:Infraestrutura.php

示例9: niceVarDump

function niceVarDump($obj, $ident = 0)
{
    $data = '';
    $data .= str_repeat(' ', $ident);
    $original_ident = $ident;
    $toClose = false;
    switch (gettype($obj)) {
        case 'object':
            $vars = (array) $obj;
            $data .= gettype($obj) . ' (' . get_class($obj) . ') (' . count($vars) . ") {\n";
            $ident += 2;
            foreach ($vars as $key => $var) {
                $type = '';
                $k = bin2hex($key);
                if (strpos($k, '002a00') === 0) {
                    $k = str_replace('002a00', '', $k);
                    $type = ':protected';
                } elseif (strpos($k, bin2hex("" . get_class($obj) . "")) === 0) {
                    $k = str_replace(bin2hex("" . get_class($obj) . ""), '', $k);
                    $type = ':private';
                }
                $k = hex2bin($k);
                if (is_subclass_of($obj, 'ProtobufMessage') && $k == 'values') {
                    $r = new ReflectionClass($obj);
                    $constants = $r->getConstants();
                    $newVar = [];
                    foreach ($constants as $ckey => $cval) {
                        if (substr($ckey, 0, 3) != 'PB_') {
                            $newVar[$ckey] = $var[$cval];
                        }
                    }
                    $var = $newVar;
                }
                $data .= str_repeat(' ', $ident) . "[{$k}{$type}]=>\n" . niceVarDump($var, $ident) . "\n";
            }
            $toClose = true;
            break;
        case 'array':
            $data .= 'array (' . count($obj) . ") {\n";
            $ident += 2;
            foreach ($obj as $key => $val) {
                $data .= str_repeat(' ', $ident) . '[' . (is_int($key) ? $key : "\"{$key}\"") . "]=>\n" . niceVarDump($val, $ident) . "\n";
            }
            $toClose = true;
            break;
        case 'string':
            $data .= 'string "' . parseText($obj) . "\"\n";
            break;
        case 'NULL':
            $data .= gettype($obj);
            break;
        default:
            $data .= gettype($obj) . '(' . strval($obj) . ")\n";
            break;
    }
    if ($toClose) {
        $data .= str_repeat(' ', $original_ident) . "}\n";
    }
    return $data;
}
开发者ID:Veivan,项目名称:WABuh,代码行数:60,代码来源:test_sessionbuilder.php

示例10: client_commands_array

 public static function client_commands_array()
 {
     $options = array('Test Installation' => array(), 'Testing' => array(), 'Batch Testing' => array(), 'OpenBenchmarking.org' => array(), 'System' => array(), 'Information' => array(), 'Asset Creation' => array(), 'Result Management' => array(), 'Result Analytics' => array(), 'Other' => array());
     foreach (pts_file_io::glob(PTS_COMMAND_PATH . '*.php') as $option_php_file) {
         $option_php = basename($option_php_file, '.php');
         $name = str_replace('_', '-', $option_php);
         if (!in_array(pts_strings::first_in_string($name, '-'), array('dump', 'task'))) {
             include_once $option_php_file;
             $reflect = new ReflectionClass($option_php);
             $constants = $reflect->getConstants();
             $doc_description = isset($constants['doc_description']) ? constant($option_php . '::doc_description') : 'No summary is available.';
             $doc_section = isset($constants['doc_section']) ? constant($option_php . '::doc_section') : 'Other';
             $name = isset($constants['doc_use_alias']) ? constant($option_php . '::doc_use_alias') : $name;
             $skip = isset($constants['doc_skip']) ? constant($option_php . '::doc_skip') : false;
             $doc_args = array();
             if ($skip) {
                 continue;
             }
             if (method_exists($option_php, 'argument_checks')) {
                 $doc_args = call_user_func(array($option_php, 'argument_checks'));
             }
             if (!empty($doc_section) && !isset($options[$doc_section])) {
                 $options[$doc_section] = array();
             }
             array_push($options[$doc_section], array($name, $doc_args, $doc_description));
         }
     }
     return $options;
 }
开发者ID:ShaolongHu,项目名称:phoronix-test-suite,代码行数:29,代码来源:pts_documentation.php

示例11: _setAttributes

 /**
  * Set attributes for a Doctrine_Configurable instance
  *
  * @param   Doctrine_Configurable $object
  * @param   array $attributes
  * @return  void
  * @throws  Zend_Application_Resource_Exception
  */
 protected function _setAttributes(Doctrine_Configurable $object, array $attributes)
 {
     $reflect = new ReflectionClass('ZFDoctrine_Core');
     $doctrineConstants = $reflect->getConstants();
     $attributes = array_change_key_case($attributes, CASE_UPPER);
     foreach ($attributes as $key => $value) {
         if (!array_key_exists($key, $doctrineConstants)) {
             throw new Zend_Application_Resource_Exception("Invalid attribute {$key}.");
         }
         $attrIdx = $doctrineConstants[$key];
         $attrVal = $value;
         if (Doctrine_Core::ATTR_QUERY_CACHE == $attrIdx) {
             $attrVal = $this->_getCache($value);
         } elseif (Doctrine_Core::ATTR_RESULT_CACHE == $attrIdx) {
             $attrVal = $this->_getCache($value);
         } else {
             if (is_string($value)) {
                 $value = strtoupper($value);
                 if (array_key_exists($value, $doctrineConstants)) {
                     $attrVal = $doctrineConstants[$value];
                 }
             }
         }
         $object->setAttribute($attrIdx, $attrVal);
     }
 }
开发者ID:lciolecki,项目名称:zf-doctrine,代码行数:34,代码来源:Doctrine.php

示例12: __construct

 /**
  * Constructor
  *
  * @param    string     $platform    Platform
  * @param    DBFarmRole $DBFarmRole  optional Farm Role object
  * @param    int        $index       optional Server index within the Farm Role scope
  * @param    string     $role_id     optional Identifier of the Role
  */
 public function __construct($platform, DBFarmRole $DBFarmRole = null, $index = null, $role_id = null)
 {
     $this->platform = $platform;
     $this->dbFarmRole = $DBFarmRole;
     $this->index = $index;
     $this->roleId = $role_id === null ? $this->dbFarmRole->RoleID : $role_id;
     if ($DBFarmRole) {
         $this->envId = $DBFarmRole->GetFarmObject()->EnvID;
     }
     //Refletcion
     $Reflect = new ReflectionClass(DBServer::$platformPropsClasses[$this->platform]);
     foreach ($Reflect->getConstants() as $k => $v) {
         $this->platformProps[] = $v;
     }
     if ($DBFarmRole) {
         if (PlatformFactory::isOpenstack($this->platform)) {
             $this->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
         } elseif (PlatformFactory::isCloudstack($this->platform)) {
             $this->SetProperties(array(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
         } else {
             switch ($this->platform) {
                 case SERVER_PLATFORMS::GCE:
                     $this->SetProperties(array(GCE_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
                     break;
                 case SERVER_PLATFORMS::EC2:
                     $this->SetProperties(array(EC2_SERVER_PROPERTIES::REGION => $DBFarmRole->CloudLocation));
                     break;
             }
         }
     }
     $this->SetProperties(array(SERVER_PROPERTIES::SZR_VESION => '0.20.0'));
 }
开发者ID:scalr,项目名称:scalr,代码行数:40,代码来源:class.ServerCreateInfo.php

示例13: getConstants

 /**
  * Uses reflection to find the constants defined in the class and cache
  * them in a local property for performance, before returning them.
  *
  * @param callable|null $keysCallback
  * @param bool          $classPrefixed      True if you want the enum class prefix on each keys, false otherwise.
  * @param string        $namespaceSeparator Only relevant if $classPrefixed is set to true.
  *
  * @return array a hash with your constants and their value. Useful for
  *               building a choice widget
  */
 public static final function getConstants($keysCallback = null, $classPrefixed = false, $namespaceSeparator = null)
 {
     $namespaceSeparator = $namespaceSeparator ?: static::$defaultNamespaceSeparator;
     $enumTypes = static::getEnumTypes();
     $enums = [];
     if (!is_array($enumTypes)) {
         $enumTypes = [$enumTypes];
     }
     foreach ($enumTypes as $key => $enumType) {
         $cacheKey = is_int($key) ? $enumType : $key;
         if (!isset(self::$constCache[$cacheKey])) {
             $reflect = new \ReflectionClass($enumType);
             self::$constCache[$cacheKey] = $reflect->getConstants();
         }
         if (count($enumTypes) > 1) {
             foreach (self::$constCache[$cacheKey] as $subKey => $value) {
                 $subKey = $cacheKey . (is_int($key) ? '::' : '.') . $subKey;
                 $enums[$subKey] = $value;
             }
         } else {
             $enums = self::$constCache[$cacheKey];
         }
     }
     if (is_callable($keysCallback) || $classPrefixed) {
         return array_combine($classPrefixed ? static::getClassPrefixedKeys($keysCallback, $namespaceSeparator) : static::getKeys($keysCallback), $enums);
     }
     return $enums;
 }
开发者ID:greg0ire,项目名称:enum,代码行数:39,代码来源:AbstractEnum.php

示例14: getFeatures

 /**
  * Convenicene method to get readable names of each feature.
  */
 public static function getFeatures()
 {
     $ref = new \ReflectionClass('X10Device');
     $constants = $ref->getConstants();
     $returns = array();
     foreach ($constants as $key => $val) {
         if (substr($key, 0, 2) == 'F_') {
             $r = $key;
             switch ($key) {
                 case 'F_ON':
                     $r = 'On';
                     break;
                 case 'F_OFF':
                     $r = 'Off';
                     break;
                 case 'F_DIM':
                     $r = 'Dim';
                     break;
                 case 'F_BRIGHT':
                     $r = 'Bright';
                     break;
             }
             $returns[$val] = $r;
         }
     }
     return $returns;
 }
开发者ID:marioveyna,项目名称:x10php,代码行数:30,代码来源:X10Device.php

示例15: checkResource

 protected function checkResource($entity, $className)
 {
     $reflect = new ReflectionClass($className);
     if (!in_array($entity, $reflect->getConstants())) {
         throw new TypeException(__CLASS__, __METHOD__);
     }
 }
开发者ID:yagmikita,项目名称:framework,代码行数:7,代码来源:RootClass.php


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