當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。