本文整理汇总了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;
}
示例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);
}
}
}
示例3: getClassAnnotation
protected static function getClassAnnotation(ReflectionClass $reflector, $name)
{
if ($reflector->hasConstant($name)) {
return $reflector->getConstant($name);
}
return null;
}
示例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;
}
示例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');
}
}
示例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'));
}
示例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;
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
}
示例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]);
}
示例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);
}
}