/** * 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; }
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; }
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; }
/** * @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; }
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; }
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')); }
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; }
/** * 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]); } }
/** * 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; }
/** * 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"); }
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()); }
public function imprimeProdutos() { $reflection = new ReflectionClass(__CLASS__); for ($i = 1; $i <= count($reflection->getConstants()); $i++) { echo $reflection->getConstant("PRODUTO{$i}") . PHP_EOL; } }
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(); } } }
/** * 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); }
/** * 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; }
/** * 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; }
function Main() { try { $obj = new ReflectionClass("Comuns"); $tabela = $_POST['t']; $tabela = $obj->getConstant($tabela); $registro = base64_decode($_POST['r']); $sql = "SELECT Ativo FROM " . $tabela . " WHERE Codigo = :pcod;"; $cnn = Conexao2::getInstance(); $q = $cnn->prepare($sql); $q->bindParam(":pcod", $registro, PDO::PARAM_INT); $q->execute(); $rs = $q->fetch(PDO::FETCH_OBJ); if ($rs->Ativo == 1) { $status = 0; } else { $status = 1; } $q->closeCursor(); $sql = "UPDATE " . $tabela . " SET Ativo = :pnovo WHERE Codigo = :pcod;"; $q = $cnn->prepare($sql); $q->bindParam(":pnovo", $status, PDO::PARAM_INT); $q->bindParam(":pcod", $registro, PDO::PARAM_INT); $q->execute(); echo $status; } catch (PDOException $ex) { echo $ex->getMessage(); } }
protected static function getClassAnnotation(ReflectionClass $reflector, $name) { if ($reflector->hasConstant($name)) { return $reflector->getConstant($name); } return null; }
public function getTableName() { if (empty($this->tableName)) { $classRef = new \ReflectionClass($this->className); $this->tableName = $classRef->getConstant('TABLE_NAME'); } return $this->tableName; }
public function getConstant($name) { try { return new Method($this->reflectionClass->getConstant(String::asNative($name))); } catch (\ReflectionException $e) { throw new NoSuchFieldException($e->getMessage(), $e->getCode()); } }
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); }
public static function validate($name) { $constClass = new ReflectionClass(__CLASS__); if (false !== $constClass->getConstant(strtoupper($name))) { return true; } return false; }
public static function FromType($type) { $schema = GetDBSchema(); $xtable = $schema->el('//table[naming/type="' . $type . '"]'); $privilege = $xtable->privilege; $reflect = new ReflectionClass('Privileges'); return $reflect->getConstant($privilege); }
public static function getDriverOptions($config) { $optionsArray = array(); $pdoClass = new ReflectionClass('PDO'); foreach ($config as $key => $value) { $optionsArray[$pdoClass->getConstant($key)] = $value; } return $optionsArray; }
/** * filter 実装 */ public function filter() { list($controller, $method) = explode('@', \Route::currentRouteAction()); $reflectionClass = new \ReflectionClass($controller); $constant = $reflectionClass->getConstant('SESSION_KEY'); if (!\Session::get($constant)) { return \Redirect::route($this->redirectForm()); } }
public final function getGroupKey() { $class = new ReflectionClass($this); $const = $class->getConstant('ACTIONGROUPKEY'); if ($const === false) { throw new Exception(pht('"%s" class "%s" must define a "%s" property.', __CLASS__, get_class($this), 'ACTIONGROUPKEY')); } return $const; }
/** * 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); }
/** * Cache masks. */ protected function updateMasks() { $permissions = $this->getPermissions(); $reflectionClass = new \ReflectionClass(new $this->maskBuilderClass()); $this->masks = array(); foreach ($permissions as $permission) { $this->masks[$permission] = $reflectionClass->getConstant('MASK_' . $permission); } }
public function isSympalEnabled() { if ($application = sfConfig::get('sf_app')) { $reflection = new ReflectionClass($application . 'Configuration'); if ($reflection->getConstant('disableSympal')) { return false; } } return true; }
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)); } }