本文整理汇总了PHP中ReflectionClass::getConstant方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::getConstant方法的具体用法?PHP ReflectionClass::getConstant怎么用?PHP ReflectionClass::getConstant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::getConstant方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addFallbackCriteria
/**
* Add fallback query criteria to $criteria
*
* @param Criteria $criteria
* @param array $options
* @return QubitQuery array of objects
*/
public static function addFallbackCriteria($criteria, $fallbackClassName, $options = array())
{
if (isset($options['culture'])) {
$culture = $options['culture'];
} else {
$culture = sfContext::getInstance()->user->getCulture();
}
// Expose class constants so we can call them using a dynamic class name
$fallbackClass = new ReflectionClass($fallbackClassName);
$fallbackClassI18n = new ReflectionClass("{$fallbackClassName}I18n");
// Add fallback columns (calculated)
$criteria = self::addFallbackColumns($criteria, $fallbackClassI18n->getName());
// Get i18n "CULTURE" column name, with "<tablename>." stripped off the front
$cultureColName = str_replace($fallbackClassI18n->getConstant('TABLE_NAME') . '.', '', $fallbackClassI18n->getConstant('CULTURE'));
// Build join strings
$currentJoinString = 'current.id AND current.' . $cultureColName . ' = \'' . $culture . '\'';
$sourceJoinString = 'source.id AND source.' . $cultureColName . ' = ' . $fallbackClass->getConstant('SOURCE_CULTURE');
$sourceJoinString .= ' AND source.' . $cultureColName . ' <> \'' . $culture . '\'';
// Build fancy criteria to get fallback values
$criteria->addAlias('current', $fallbackClassI18n->getConstant('TABLE_NAME'));
$criteria->addAlias('source', $fallbackClassI18n->getConstant('TABLE_NAME'));
$criteria->addJoin(array($fallbackClass->getConstant('ID'), 'current.' . $cultureColName), array('current.id', '\'' . $culture . '\''), Criteria::LEFT_JOIN);
$criteria->addJoin(array($fallbackClass->getConstant('ID'), 'source.' . $cultureColName), array('source.id', $fallbackClass->getConstant('SOURCE_CULTURE') . ' AND source.' . $cultureColName . ' <> \'' . $culture . '\''), Criteria::LEFT_JOIN);
return $criteria;
}
示例2: executeIndex
public function executeIndex()
{
//perlu di rapihkan
$field_name = $this->name;
$reflection = new ReflectionClass($this->model . 'Peer');
$method = $reflection->getMethod('doSelect');
$c = new Criteria();
$filter_field = strtoupper($this->filter_field);
$filter_content = $this->filter_content;
if (!empty($filter_field)) {
if ($this->case == 'equal') {
$c->add($reflection->getConstant($filter_field), $filter_content, Criteria::EQUAL);
} else {
if ($this->case == 'not_equal') {
$c->add($reflection->getConstant($filter_field), $filter_content, Criteria::NOT_EQUAL);
}
}
}
$order_column = $this->order_column;
$order_type = $this->order_type;
if (!empty($order_column)) {
if ($order_type == 'desc') {
$c->addDescendingOrderByColumn($order_column);
} else {
$c->addAscendingOrderByColumn($order_column);
}
}
$reg_info = $method->invoke($method, $c);
$this->data = $reg_info;
$this->name = $field_name;
$this->desc = !isset($this->desc) ? 'Name' : $this->desc;
}
示例3: 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;
}
示例4: getValue
/**
* @todo ? refactoring visual reflection for Igor
* Get constant value by name
* if const like $strName not exists - exception throwed
*
* @param string $strName
* @throws System_Enum_Exception
* @return mixed
*/
public function getValue($strName)
{
$value = $this->_objReflection->getConstant($strName);
if ($value === FALSE) {
throw new Core_Enum_Exception($strName . ' name not found in ' . $this->_objReflection->getName());
}
return $value;
}
示例5: isUserRecord
public static function isUserRecord($class_name, $record_id, $user_id)
{
$class = new ReflectionClass($class_name);
$c = new Criteria();
$c->add($class->getConstant('USER_ID'), $user_id);
$c->add($class->getConstant('ID'), $record_id);
$record = $class->getMethod('doSelectOne')->invoke(null, $c);
return $record != null;
}
示例6: testProperties
public function testProperties()
{
$this->assertClassHasAttribute('type', ResponseSpeechSO::class);
$this->assertClassHasAttribute('text', ResponseSpeechSO::class);
$this->assertClassHasAttribute('ssml', ResponseSpeechSO::class);
$r = new ReflectionClass(ResponseSpeechSO::class);
$this->assertEquals('PlainText', $r->getConstant('TYPE_PLAIN_TEXT'));
$this->assertEquals('SSML', $r->getConstant('TYPE_SSML'));
$this->assertEquals([$r->getConstant('TYPE_PLAIN_TEXT'), $r->getConstant('TYPE_SSML')], $r->getConstant('ALLOWED_TYPES'));
}
示例7: ReflectionClass
function serverCnct_createDB()
{
global $power;
$C = 'ConstantsControl_p_admin';
$C = new ReflectionClass($C);
if (!isset($mod)) {
$mod = 'dev';
}
$mod = $C->getConstant('CATEGORY');
if ($mod == 'prod') {
$host = $C->getConstant('HOST_prod');
$root = $C->getConstant('ROOT_prod');
$pass = $C->getConstant('PASS_prod');
$db = $C->getConstant('DB_prod');
} else {
$host = $C->getConstant('HOST_dev');
$root = $C->getConstant('ROOT_dev');
$pass = $C->getConstant('PASS_dev');
$db = $C->getConstant('DB_dev');
}
$serv_con = $connect->server_connect($host, $root, $pass);
$data['db'] = $db;
$data['con'] = $serv_con;
$res = $power->create_db($data);
if ($res) {
$cox = $this->cnct();
return $cnx;
}
return false;
}
示例8: processResolverItems
/**
* Processes the form resolvers
*
* @param Definition $definition
* @param \ReflectionClass $refClass
* @param ContainerBuilder $container
*/
protected function processResolverItems(Definition $definition, \ReflectionClass $refClass, ContainerBuilder $container)
{
$tag = $refClass->getConstant('SERVICE_TAG_NAME');
$interface = $refClass->getConstant('INTERFACE_CLASS');
foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) {
$itemDefinition = $container->getDefinition($id);
$refClass = new \ReflectionClass($itemDefinition->getClass());
if (!$refClass->implementsInterface($interface)) {
throw new \InvalidArgumentException(sprintf('Element "%s" tagged with "%s" must implement interface "%s".', $id, $tag, $interface));
}
$definition->addMethodCall('add', [$attributes[0]['alias'], $id]);
}
}
示例9: __get
/**
* Getter.
*
* @param string $name Configuration name
* @return mixed Boolean or config value
*
*/
public function __get($name)
{
// Try configuration store
if (isset($this->config[$name])) {
return $this->config[$name];
// Else, try configuration constants
} else {
$reflection = new \ReflectionClass($this);
if ($reflection->getConstant($name)) {
return $reflection->getConstant($name);
}
}
return false;
}
示例10: GetNumber
/**
* Return a specific number associated with name.
* @access public
* @static
* @param string $name The string part of an enumeration.
* @param bool $casesensitive If the search should be preformed case sensitive. Default value true.
* @return int
*/
public static function GetNumber($name, $casesensitive = true)
{
$reflection = new ReflectionClass(get_called_class());
if ($reflection->hasConstant($name)) {
return $reflection->getConstant($name);
} elseif (!$casesensitive && $reflection->hasConstant(strtolower($name))) {
return $reflection->getConstant(strtolower($name));
} elseif (!$casesensitive && $reflection->hasConstant(strtoupper($name))) {
return $reflection->getConstant(strtoupper($name));
}
/**
* @throws
*/
throw new Exception("Key {$name} not found");
}
示例11: 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());
}
示例12: imprimeProdutos
public function imprimeProdutos()
{
$reflection = new ReflectionClass(__CLASS__);
for ($i = 1; $i <= count($reflection->getConstants()); $i++) {
echo $reflection->getConstant("PRODUTO{$i}") . PHP_EOL;
}
}
示例13: fixChildrenAttribute
static function fixChildrenAttribute($elementType, $name, $value)
{
var_dump('AbstractElement\\Helper::fixChildrenAttribute needs fixed');
exit;
$classPath = '\\AbstractElement\\' . $elementType;
// each element in contents array for this object
foreach ($this->contents as $index => $content) {
// is this an object that extends AbstractElement?
if (is_a($content, '\\Element')) {
// is this of the right element type?
if (is_a($content, $classPath)) {
$content->setAttribute($name, $value);
}
$content->fixChildrenAttribute($elementType, $name, $value);
} elseif (is_string($content) && $fixRawHtml) {
$dom = new \DOMDocument();
$dom->loadHtml($content);
$reflectionClass = new \ReflectionClass($classPath);
$elements = $dom->getElementsByTagName($reflectionClass->getConstant('tag'));
foreach ($elements as $element) {
$element->setAttribute($name, $value);
}
$this->contents[$index] = $dom->saveHTML();
}
}
}
示例14: __construct
/**
* Compares the class SCHEMA and the submitted token.
*
* @param string $token
* @param string $commandClass
*/
public function __construct($token, $commandClass)
{
$ref = new \ReflectionClass($commandClass);
$schema = $ref->getConstant('SCHEMA') ? : "undefined";
$this->message = sprintf(self::MESSAGE, $token, $commandClass, $schema);
}
示例15: generateAlias
/**
* Auto-Generate an alias for an entity.
*
* @param string $alias
* @param \DC_General $dc
*
* @return string
* @throws Exception
*/
public static function generateAlias($alias, \DC_General $dc)
{
/** @var EntityInterface $entity */
$entity = $dc->getCurrentModel()->getEntity();
$autoAlias = false;
// Generate alias if there is none
if (!strlen($alias)) {
$autoAlias = true;
if ($entity->__has('title')) {
$alias = standardize($entity->getTitle());
} elseif ($entity->__has('name')) {
$alias = standardize($entity->getName());
} else {
return '';
}
}
$entityClass = new \ReflectionClass($entity);
$keys = explode(',', $entityClass->getConstant('KEY'));
$entityManager = EntityHelper::getEntityManager();
$queryBuilder = $entityManager->createQueryBuilder();
$queryBuilder->select('COUNT(e.' . $keys[0] . ')')->from($entityClass->getName(), 'e')->where($queryBuilder->expr()->eq('e.alias', ':alias'))->setParameter(':alias', $alias);
static::extendQueryWhereId($queryBuilder, $dc->getCurrentModel()->getID(), $entity);
$query = $queryBuilder->getQuery();
$duplicateCount = $query->getResult(Query::HYDRATE_SINGLE_SCALAR);
// Check whether the news alias exists
if ($duplicateCount && !$autoAlias) {
throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $alias));
}
// Add ID to alias
if ($duplicateCount && $autoAlias) {
$alias .= '-' . $dc->getCurrentModel()->getID();
}
return $alias;
}