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


PHP ReflectionClass::hasConstant方法代码示例

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


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

示例1: execute

 public function execute(&$value, &$error)
 {
     $class_name = $this->getParameter('class_name');
     $field_const_name = $this->getParameter('field_const_name');
     $form_field_name = $this->getParameter('form_field_name');
     $form_field_value = $this->getContext()->getRequest()->getParameter($form_field_name);
     $form_id_name = $this->getParameter('form_id_name');
     if ($form_id_name) {
         $form_id_value = $this->getContext()->getRequest()->getParameter($form_id_name);
     }
     $class = new ReflectionClass($class_name);
     if ($class->hasConstant($field_const_name)) {
         $criteria = new Criteria();
         $criteria->add($class->getConstant($field_const_name), $form_field_value);
         if (isset($form_id_value) && $form_id_value && $class->hasConstant('ID')) {
             $criteria->add($class->getConstant('ID'), $form_id_value, Criteria::NOT_EQUAL);
         }
         if ($class->hasMethod('doSelectOne')) {
             $ref_method = $class->getMethod('doSelectOne');
             $object = $ref_method->invoke(null, $criteria);
             if (!$object) {
                 return true;
             }
         }
         sfContext::getInstance()->getLogger()->info('Buraya geldi');
     }
     $error = $this->getParameter('unique_error');
     return false;
 }
开发者ID:hoydaa,项目名称:snippets.hoydaa.org,代码行数:29,代码来源:myUniqueValidator.class.php

示例2: processModule

 /**
  * @param  \SplFileInfo[]   $templates
  * @param $resourcesPath
  * @param $moduleCode
  * @throws \Exception
  * @throws \SmartyException
  */
 protected function processModule($templates, $resourcesPath, $modulePath, $moduleCode)
 {
     foreach ($templates as $template) {
         $fileName = str_replace("__MODULE__", $moduleCode, $template->getFilename());
         $fileName = str_replace("FIX", "", $fileName);
         $relativePath = str_replace($resourcesPath, "", $template->getPath() . DS);
         $completeFilePath = $modulePath . $relativePath . DS . $fileName;
         $isFix = false !== strpos($template->getFilename(), "FIX");
         // Expect special rule for Module\Module
         $isModuleClass = $modulePath . $relativePath . DS . $moduleCode . ".php" === $completeFilePath;
         if ($isFix && !file_exists($completeFilePath) || !$isFix) {
             if ($isModuleClass && is_file($completeFilePath)) {
                 $caught = false;
                 try {
                     $reflection = new \ReflectionClass("{$moduleCode}\\{$moduleCode}");
                 } catch (\ReflectionException $e) {
                     $caught = true;
                     // The class is not valid
                 }
                 if (!$caught && $reflection->hasConstant("MESSAGE_DOMAIN")) {
                     continue;
                     // If the class already have the constant, don't override it
                 }
             }
             $fetchedTemplate = $this->parser->fetch($template->getRealPath());
             $this->writeFile($completeFilePath, $fetchedTemplate, true, true);
         }
     }
 }
开发者ID:Alban-io,项目名称:TheliaStudio,代码行数:36,代码来源:ModulePhpGenerator.php

示例3: getClassAnnotation

 protected static function getClassAnnotation(ReflectionClass $reflector, $name)
 {
     if ($reflector->hasConstant($name)) {
         return $reflector->getConstant($name);
     }
     return null;
 }
开发者ID:nowelium,项目名称:Hermit,代码行数:7,代码来源:HermitAnnoteConst.php

示例4: __construct

 /**
  * Constructor. By passing needed values in constructor, you can quickly contruct instances of FormField in one line of code.
  *
  * @param string $name Field name
  * @param string $field_type Field type. Must be a member of FORM_FIELD_TYPE
  * @param string $title Field title as it will appear on the form
  * @param bool $isrequired Either field must be filled by the user.
  * @param array $options Flat key=>value array to draw SELECT HTML control values. Only applicable if FormFieldType is FORM_FIELD_TYPE::SELECT
  * @param string $default_value Default value that will be in the field when form is drawn.
  * @param string $value Filed Value. The same as default_value
  * @param string $hint  Inline help that will appear as yellow hint after the field.
  */
 public function __construct($name, $field_type, $title, $isrequired = false, $options = array(), $default_value = null, $value = null, $hint = null, $allow_multiple_choice = false)
 {
     // Defalts if we blindly pass nullz
     if ($options == null) {
         $options = array();
     }
     if ($isrequired == null) {
         $isrequired = false;
     }
     // Validation
     // type
     $Reflect = new ReflectionClass("FORM_FIELD_TYPE");
     if (!$Reflect->hasConstant(strtoupper($field_type))) {
         throw new Exception("field_type must be of type FORM_FIELD_TYPE");
     }
     $this->Name = $name;
     $this->FieldType = $field_type;
     $this->Title = $title;
     $this->DefaultValue = $default_value;
     if ($allow_multiple_choice) {
         $this->Value = explode(",", $value);
     } else {
         $this->Value = $value;
     }
     $this->IsRequired = $isrequired;
     $this->Hint = $hint;
     $this->Options = $options;
     $this->AllowMultipleChoice = $allow_multiple_choice;
 }
开发者ID:recipe,项目名称:scalr,代码行数:41,代码来源:class.DataFormField.php

示例5: getEnumValue

 /**
  * Get variant of ENUM value
  *
  * @param string      $enumConst ENUM value
  * @param string|null $enumType  ENUM type
  *
  * @throws EnumTypeIsNotRegisteredException
  * @throws NoRegisteredEnumTypesException
  * @throws ConstantIsFoundInFewRegisteredEnumTypesException
  * @throws ConstantIsNotFoundInAnyRegisteredEnumTypeException
  *
  * @return string
  */
 public function getEnumValue($enumConst, $enumType = null)
 {
     if (!empty($this->registeredEnumTypes) && is_array($this->registeredEnumTypes)) {
         // If ENUM type was set, e.g. {{ player.position|readable('BasketballPositionType') }}
         if (!empty($enumType)) {
             if (!isset($this->registeredEnumTypes[$enumType])) {
                 throw new EnumTypeIsNotRegisteredException(sprintf('ENUM type "%s" is not registered', $enumType));
             }
             return constant($this->registeredEnumTypes[$enumType] . '::' . $enumConst);
         } else {
             // If ENUM type wasn't set, e.g. {{ player.position|readable }}
             $occurrences = [];
             // Check if value exists in registered ENUM types
             foreach ($this->registeredEnumTypes as $registeredEnumType) {
                 $refl = new \ReflectionClass($registeredEnumType);
                 if ($refl->hasConstant($enumConst)) {
                     $occurrences[] = $registeredEnumType;
                 }
             }
             // If found only one occurrence, then we know exactly which ENUM type
             if (count($occurrences) == 1) {
                 $enumClassName = array_pop($occurrences);
                 return constant($enumClassName . '::' . $enumConst);
             } elseif (count($occurrences) > 1) {
                 throw new ConstantIsFoundInFewRegisteredEnumTypesException(sprintf('Constant "%s" is found in few registered ENUM types. You should manually set the appropriate one', $enumConst));
             } else {
                 throw new ConstantIsNotFoundInAnyRegisteredEnumTypeException(sprintf('Constant "%s" wasn\'t found in any registered ENUM type', $enumConst));
             }
         }
     } else {
         throw new NoRegisteredEnumTypesException('There are no registered ENUM types');
     }
 }
开发者ID:bigfoot90,项目名称:DoctrineEnumBundle,代码行数:46,代码来源:EnumValueExtension.php

示例6: testAddConstant

 /**
  */
 public function testAddConstant()
 {
     $prop = new ReflectionConstant('test', "value");
     $this->assertFalse($this->object->hasConstant('test'));
     $this->object->addConstant($prop);
     $this->assertTrue($this->object->hasConstant('test'));
 }
开发者ID:neiluJ,项目名称:Documentor,代码行数:9,代码来源:ReflectionClassTest.php

示例7: pack

 /**
  * Convert packable object to an array.
  * 
  * @param  PackableInterface $object
  * @return array
  */
 public static function pack(PackableInterface $object)
 {
     $reflect = new \ReflectionClass(get_class($object));
     $data = array();
     foreach ($object as $key => $value) {
         // we don't want to send null variables
         if ($value === null) {
             continue;
         }
         // run the packer over packable objects
         if ($value instanceof PackableInterface) {
             $value = self::pack($value);
         }
         // find packing strategy
         $strategy = sprintf('%s_PACKER_STRATEGY', $key);
         $strategy = $reflect->hasConstant($strategy) ? $reflect->getConstant($strategy) : self::SINGLE_KEY_STRATEGY;
         // execute
         $strategy::pack($data, $key, $value);
     }
     // default actions
     foreach ($data as $key => $value) {
         // make sure all objects have been packed
         if ($value instanceof PackableInterface) {
             $value = self::pack($value);
         }
         // compress any remaining data structures
         if (is_array($value)) {
             Compress::pack($data, $key, $value);
         }
     }
     return $data;
 }
开发者ID:markey-magic,项目名称:tractionphp,代码行数:38,代码来源:Packer.php

示例8: testGeneratePostActivation

 public function testGeneratePostActivation()
 {
     // Touch a new "insert.sql" file and copy a "create.sql" file
     /** @var \org\bovigo\vfs\vfsStreamFile $file */
     $configDir = $this->stream->getChild("Config");
     $file = vfsStream::newFile("create.sql")->at($configDir);
     $file->setContent(file_get_contents(__DIR__ . "/../" . static::TEST_MODULE_PATH . "Config" . DS . "thelia.sql"));
     vfsStream::newFile("insert.sql")->at($configDir);
     // Then run the generator
     $generator = new ModulePhpGenerator($this->getSmarty());
     $generator->doGenerate($this->event);
     // Read the class
     include $this->getStreamPath("TheliaStudioTestModule.php");
     $reflection = new \ReflectionClass("TheliaStudioTestModule\\TheliaStudioTestModule");
     $this->assertTrue($reflection->hasConstant("MESSAGE_DOMAIN"));
     $this->assertEquals("theliastudiotestmodule", $reflection->getConstant("MESSAGE_DOMAIN"));
     $this->assertTrue($reflection->hasMethod("postActivation"));
     // get a method closure
     $method = $reflection->getMethod("postActivation");
     $closure = $method->getClosure($reflection->newInstance());
     // Test that the table doesn't exist
     /** @var \Propel\Runtime\DataFetcher\PDODataFetcher $stmt */
     $stmt = $this->con->query("SHOW TABLES LIKE 'example_table'");
     $this->assertEquals(0, $stmt->count());
     // Execute the method
     $closure($this->con);
     // Now it exists
     /** @var \Propel\Runtime\DataFetcher\PDODataFetcher $stmt */
     $stmt = $this->con->query("SHOW TABLES LIKE 'example_table'");
     $this->assertEquals(1, $stmt->count());
 }
开发者ID:Alban-io,项目名称:TheliaStudio,代码行数:31,代码来源:ModulePhpGeneratorTest.php

示例9: __callStatic

 public static function __callStatic($name, $arguments)
 {
     $reflectionClass = new \ReflectionClass(get_called_class());
     if (!$reflectionClass->hasConstant($name)) {
         throw new InvalidKey($name);
     }
     return new static($reflectionClass->getConstant($name), false);
 }
开发者ID:teenager19,项目名称:vacasol-php-sdk,代码行数:8,代码来源:Enum.php

示例10: __callStatic

 /**
  * Static factory (ex. ExampleEnum::ONE())
  *
  * @param $method
  * @param $arguments
  *
  * @throws \BadMethodCallException When given constant is undefined
  *
  * @return Enum
  */
 public static function __callStatic($method, $arguments)
 {
     $class = get_called_class();
     $refl = new \ReflectionClass($class);
     if (!$refl->hasConstant($method)) {
         throw new \BadMethodCallException(sprintf('Undefined class constant "%s" in "%s"', $method, $class));
     }
     return new static($refl->getConstant($method), false);
 }
开发者ID:netteam,项目名称:ddd,代码行数:19,代码来源:Enum.php

示例11: getConstantWithPrefixForChoice

/**
 * @param string|object $class
 * @param string $prefix
 * @return array
 * @throws \Exception
 */
function getConstantWithPrefixForChoice($class, $prefix, $value)
{
    $reflection = new \ReflectionClass($class);
    $labelPrefixConstantName = 'LABELPREFIX_' . rtrim($prefix, '_');
    if (!$reflection->hasConstant($labelPrefixConstantName)) {
        throw new \Exception(sprintf('A constant with name: %s is needed as labelprefix', $labelPrefixConstantName));
    }
    $labelPrefix = $reflection->getConstant($labelPrefixConstantName);
    return $labelPrefix . $value;
}
开发者ID:dominikzogg,项目名称:helper-functions,代码行数:16,代码来源:class_functions.php

示例12: instantiate

 public function instantiate($className, array $constructorArgs)
 {
     $class = new \ReflectionClass($this->qualifyClassName($className));
     array_unshift($constructorArgs, $this->dataStore);
     $newClass = $class->newInstanceArgs($constructorArgs);
     if ($class->hasConstant("CUSTOM_DATA")) {
         $newClass->customData;
     }
     return $newClass;
 }
开发者ID:InfinityCCS,项目名称:stormpath-sdk-php,代码行数:10,代码来源:DefaultResourceFactory.php

示例13: GetValue

 public static function GetValue($class_name, $key)
 {
     //property_exists
     $ReflectionClassThis = new ReflectionClass($class_name);
     if ($ReflectionClassThis->hasConstant($key)) {
         return $ReflectionClassThis->getConstant($key);
     } else {
         throw new Exception(sprintf(_("Called %s::GetValue('%s') for non-existent property %s"), $class_name, $key, $key));
     }
 }
开发者ID:rchicoria,项目名称:epp-drs,代码行数:10,代码来源:class.EnumFactory.php

示例14: on

 /**
  * {@inheritdoc}
  */
 public function on($class, ...$args)
 {
     $reflection = new \ReflectionClass($class);
     if (false === $reflection->hasConstant('NAME')) {
         throw new Exception\InvalidEventNameException($class);
     }
     if (false === $reflection->isSubclassOf(EventInterface::class)) {
         throw new Exception\EventInterfaceImplementationException($class);
     }
     $this->push(['class' => $class, 'args' => $args]);
 }
开发者ID:symfony-bundles,项目名称:event-queue-bundle,代码行数:14,代码来源:Dispatcher.php

示例15: table

 public static function table($name)
 {
     $name = strtoupper($name);
     $ret = self::$prefix . '_';
     $reflection = new \ReflectionClass(__CLASS__);
     if ($reflection->hasConstant($name)) {
         return strtolower($ret . $reflection->getConstant($name));
     } else {
         return strtolower($ret . $name);
     }
 }
开发者ID:dominios,项目名称:alien-framework,代码行数:11,代码来源:DBConfig.php


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