public function __toString() { $to_string = ""; foreach ($this->supported_gateways as $gateway) { $ref = new ReflectionClass($gateway); $to_string .= $ref->getStaticPropertyValue('display_name') . " - " . $ref->getStaticPropertyValue('homepage_url') . " " . "[" . join(", ", $ref->getStaticPropertyValue('supported_countries')) . "]\n"; } return $to_string; }
static function testing() { $ref = new ReflectionClass('Test'); foreach (array('pub', 'pro', 'pri') as $name) { try { var_dump($ref->getStaticPropertyValue($name)); var_dump($ref->getStaticPropertyValue($name)); $ref->setStaticPropertyValue($name, 'updated'); var_dump($ref->getStaticPropertyValue($name)); } catch (Exception $e) { echo "EXCEPTION\n"; } } }
public static function getStaticVal($className, $propName, $returnArr = true) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $arr = array(); //---------------------------------------------------------- if (!is_null($constant = eval("return " . $className . "::\$" . $propName . ";"))) { $arr['constant'] = $constant; } //---------------------------------------------------------- $class = new ReflectionClass($className); //---------------------------------------------------------- try { $static = $class->getStaticPropertyValue(str_replace("\$", "", $propName)); $arr['static'] = $static; } catch (Exception $e) { //echo 'Caught exception: ', $e->getMessage(), "\n"; } //---------------------------------------------------------- if (sizeof($arr) == 1 || !$returnArr) { reset($arr); return current($arr); } else { return $arr; } }
public function features() { $max = array_map(function ($a) { $gateway = "AktiveMerchant\\Billing\\Gateways\\" . $a; return strlen($gateway::$display_name); }, $this->supported_gateways); $max = max($max) + 1; $max_column = 15; $print = ""; $print .= "[1;36mName" . str_repeat(' ', $max - 4); foreach ($this->actions as $action) { $print .= $action . str_repeat(' ', $max_column - strlen($action)); } $print .= "[0m" . PHP_EOL; foreach ($this->supported_gateways as $gateway) { $ref = new \ReflectionClass('AktiveMerchant\\Billing\\Gateways\\' . $gateway); $display_name = $ref->getStaticPropertyValue('display_name'); $length = $max - strlen($display_name); $print .= "[1;35m" . $display_name . "[0m" . str_repeat(' ', $length > 0 ? $length : 0); foreach ($this->actions as $action) { if ($ref->hasMethod($action)) { $print .= "[1;32m O[0m" . str_repeat(' ', $max_column - 2); } else { $print .= "[1;31m X[0m" . str_repeat(' ', $max_column - 2); } } $print .= PHP_EOL; } echo $print; }
public function main() { $plugin = $this->plugin->getAbsolutePath(); $infoFile = $plugin . '/' . self::INFO_FILE; if (!file_exists($infoFile)) { $message = sprintf('Unable to read plugin_info.php file at "%s"', $plugin); throw new BuildException($message); } require_once $infoFile; $class = new ReflectionClass('plugin_info'); try { $value = $class->getStaticPropertyValue($this->key); } catch (Exception $e) { $message = sprintf('Unable to read property with "%s"', $this->key); throw new BuildException($message, $e); } if (!is_string($value) && !is_int($value) && !is_float($value)) { $value = json_encode($value); } if ($this->to != '') { $this->project->setProperty($this->to, $value); } else { $this->log($value); } }
public function test_RemoveState() { $course = new ReflectionClass('CourseP'); try { $course->getStaticPropertyValue('$OneOff'); $this->fail("OneOff should be removed"); } catch (Exception $e) { } }
/** * Retrieve a TransactionTypeDescription by its name * * @param string name * @return remote.reflect.TransactionTypeDescription */ public static function valueOf($name) { try { $r = new ReflectionClass(__CLASS__); return $r->getStaticPropertyValue($name); } catch (ReflectionException $e) { throw new IllegalArgumentException($name . ': ' . $e->getMessage()); } }
public function init() { $r = new ReflectionClass($this); $o = $r->getStaticPropertyValue("octave"); if ($o->init() === false) { $this->assertEquals("", $o->lastError); return false; } return $o; }
/** */ public function testGetStaticPropertyValue() { $prop = new ReflectionProperty('test'); $propStatic = new ReflectionProperty('testStatic'); $this->object->addProperty($prop); $this->object->addProperty($propStatic); $propStatic->setDefaultValue('testValue'); $propStatic->setStatic(true); $this->assertFalse($this->object->getStaticPropertyValue('test')); $this->assertEquals('testValue', $this->object->getStaticPropertyValue('testStatic')); }
private function getValue() { if ($this->isPublic) { $refl = new ReflectionClass($this->className); $val = $refl->getStaticPropertyValue($this->propertyName); } else { $val = call_user_func(array($this->className, yTest_AddPublicAccessors::getGetterName($this->className, $this->propertyName))); } yTest_debugCC('getValue ' . $this->className . '::' . $this->propertyName . ' = ' . var_export($val, true)); return $val; }
public static function getDefinition() { $class = get_called_class(); //get_class($class); $reflection = new ReflectionClass($class); if (!$reflection->hasProperty('definition')) { return false; } $definition = $reflection->getStaticPropertyValue('definition'); //echo "<pre>";print_r($definition);die; }
function smarty_function_psureport_link($params, &$smarty) { if (!isset($params['wrap'])) { if ($params['include']) { $params['wrap'] = '<li>%s %s</li>'; } else { $params['wrap'] = '<li>%s</li>'; } //end else } //end if $link = ''; if ($params['report']) { $report = 'PSUReport_' . str_replace('-', '_', $params['report']); @(include_once $GLOBALS['BASE_DIR'] . '/includes/reports/' . $report . '.class.php'); if (!class_exists($report)) { return ''; } //end if $reflection = new ReflectionClass($report); try { $name = $reflection->getStaticPropertyValue('name'); if ($reflection->hasMethod('authZ')) { $authz = call_user_func(array($report, 'authZ')); } else { $authz = call_user_func('PSUReport', 'authZ'); } //end else } catch (Exception $err) { $report = new $report('reportlink'); $name = $report->name; $authz = $report->authZ(); } //end catch if ($authz) { $link = '<a href="' . $GLOBALS['BASE_URL'] . '/report/' . str_replace('_', '-', $params['report']) . '/'; if ($params['query_string']) { $link .= '?' . $params['query_string']; } //end if $link .= '">' . ($params['name'] ? $params['name'] : $name) . '</a>'; if ($params['include']) { $link = sprintf($params['wrap'], $link, $params['include']); } else { $link = sprintf($params['wrap'], $link); } //end else } //end if } //end if unset($report); return $link; }
function get_modules_to_load_for($product_id) { $modules = array(); $obj = C_Component_Registry::get_instance()->get_product($product_id); try { $klass = new ReflectionClass($obj); if ($klass->hasMethod('get_modules_to_load')) { $modules = $obj->get_modules_to_load(); } elseif ($klass->hasProperty('modules')) { $modules = $klass->getStaticPropertyValue('modules'); } if (!$modules && $klass->hasMethod('define_modules')) { $modules = $obj->define_modules(); if ($klass->hasProperty('modules')) { $modules = $klass->getStaticPropertyValue('modules'); } } } catch (ReflectionException $ex) { // Oh oh... } return $modules; }
public function __construct($id = '') { parent::__construct(); $this->class = strtolower(get_class($this)); $obj = new ReflectionClass($this->class); $this->data = $obj->getStaticPropertyValue('definitation'); if ($id != '') { $this->where = array($this->data['primary'] => $id); $this->order_by = array($this->data['primary'] => 'desc'); $this->return = 1; $this->getData = $this->select(); } }
static function cli_opts() { $ret = self::$cli_opts; $ff = HTML_FlexyFramework::get(); $a = new Pman(); $mods = $a->modulesList(); foreach ($mods as $m) { $fd = $ff->rootDir . "/Pman/{$m}/UpdateDatabase.php"; if (!file_exists($fd)) { continue; } require_once $fd; $cls = new ReflectionClass('Pman_' . $m . '_UpdateDatabase'); $ret = array_merge($ret, $cls->getStaticPropertyValue('cli_opts')); } return $ret; }
private static function createTable($type) { $class = new ReflectionClass($type); $columns = $class->getStaticPropertyValue('columns', array()); $columns['id'] = 'identifier'; $declarations = ""; foreach ($columns as $name => $typeName) { $declarations .= "`{$name}` " . Type::get($typeName)->mySqlName() . ", "; } $query = "CREATE TABLE `" . self::tableName($type) . "` ("; $query .= $declarations; $query .= "PRIMARY KEY (`id`)"; //// TODO: Put foreign key constraints back when creation of tables can have topological order imposed. //if ($type != __CLASS__) // $query .= ", FOREIGN KEY (`id`) REFERENCES `" . self::tableName($class->getParentClass()->getName()) . "` (`id`) ON DELETE CASCADE"; $query .= ") engine=" . Options::dbEngine() . ";"; Database::query($query, "{$type} table"); }
public function validate() { //Makiavelo::info("== Validating model =="); $class_name = get_class($this); $tmp_entity = new $class_name(); $reflect = new ReflectionClass($class_name); $properties = $reflect->getProperties(); $validates = true; try { $validations = $reflect->getStaticPropertyValue("validations"); } catch (Exception $e) { $props = $reflect->getStaticProperties(); $validations = $props['validations']; } foreach ($properties as $prop) { $attr = $prop->getName(); $value = $this->{$attr}; //$validations = $class_name::$validations; //This sucks, TODO: Fix so it works on php < 5.3 and php >= 5.3 //Makiavelo::info("Validations set for model (" . $class_name .") " . print_r($validations, true)); //Makiavelo::info("-- Validating attr: " . $attr); if (!isset($validations[$attr])) { //Makiavelo::info("-- No validation set"); continue; } $this->errors[$attr] = array(); foreach ($validations[$attr] as $validator) { //Makiavelo::info("-- Validation: " . $validator); $validator_class = ucwords($validator) . "Validator"; $v = new $validator_class(); if (!$v->validate($value)) { $this->errors[$attr][] = $attr . " " . $v->errorMsg(); $validates = false; } } } //Makiavelo::info("== Validation result == "); //Makiavelo::info(print_r($this->errors, true)); return $validates; }
/** * Allows easy setting & backing up of enviroment config * * Option types are checked in the following order: * * * Server Var * * Static Variable * * Config option * * @param array $environment List of environment to set */ function setEnvironment(array $environment) { if (!count($environment)) { return FALSE; } foreach ($environment as $option => $value) { $backup_needed = !array_key_exists($option, $this->environmentBackup); // Handle changing superglobals if (in_array($option, array('_GET', '_POST', '_SERVER', '_FILES'))) { // For some reason we need to do this in order to change the superglobals global ${$option}; if ($backup_needed) { $this->environmentBackup[$option] = ${$option}; } // PHPUnit makes a backup of superglobals automatically ${$option} = $value; } elseif (strpos($option, '::$') !== FALSE) { list($class, $var) = explode('::$', $option, 2); $class = new ReflectionClass($class); if ($backup_needed) { $this->environmentBackup[$option] = $class->getStaticPropertyValue($var); } $class->setStaticPropertyValue($var, $value); } elseif (preg_match('/^[A-Z_-]+$/', $option) or isset($_SERVER[$option])) { if ($backup_needed) { $this->environmentBackup[$option] = isset($_SERVER[$option]) ? $_SERVER[$option] : ''; } $_SERVER[$option] = $value; } else { if ($backup_needed) { $this->environmentBackup[$option] = Kohana::config($option); } list($group, $var) = explode('.', $option, 2); Kohana::config($group)->set($var, $value); } } }
/** * Grabs the route information for a class and a method. * @param $what * @param $method * @return unknown_type */ public static function getRouteRpcInfoFor($what, $method) { if (!class_exists($what, true)) { return false; } $rc = new ReflectionClass($what); $route_okay = $rc->getStaticPropertyValue('route_okay', array()); $real_method = false; $arg_count = null; if (isset($route_okay[$method])) { if (is_array($route_okay[$method])) { if (isset($route_okay[$method]['method'])) { $real_method = $route_okay[$method]['method']; $arg_count = isset($route_okay[$method]['arg_count']) ? $route_okay[$method]['arg_count'] : null; } else { $real_method = $method; } } else { $real_method = $route_okay[$method]; } } else { if (in_array($method, $route_okay)) { $real_method = $method; } else { $parent_class = $rc->getParentClass(); if ($parent_class) { return self::getRouteRpcInfoFor($parent_class->name, $method); } else { return false; } } } $rmethod = $rc->getMethod($real_method); $static = $rmethod->isStatic(); return array('arg_count' => $arg_count, 'method' => $real_method, 'static' => $static); }
} // Retrieve the models for this component if($comp){ $models = array_merge($comp->getModelList(), $comp->getSupplementalModelList()); foreach($models as $key => $file){ $class = new ReflectionClass($key); if($class->isSubclassOf('Model')){ $modelName = strtoupper($key); $schema = $class->getMethod('GetSchema')->invoke(null); $isSupplemental = false; } else{ // This model name needs some trimming performed to chop off the dynamic prefix and "modelsupplemental" suffix. $modelName = strtoupper(substr($key, strpos($key, '_')+1, -17)) . 'MODEL'; $schema = $class->getStaticPropertyValue('Schema', []); $isSupplemental = true; } // Schema now contains the schema for this model! // These should support translation strings foreach($schema as $column => $dat){ if(isset($dat['formtype'])){ $formType = $dat['formtype']; } elseif(isset($dat['form']) && isset($dat['form']['type'])){ $formType = $dat['form']['type']; } else{ $formType = 'text'; }
/** * generates an array with controller's data * @param string $where string for the getPathOfAlias yii method. * @param bool $module if check or not for module names in the controllers path * @param string $mode determinates what kind of array this method returns */ private static function extractControllers($where, $module = false, $mode = 'dataProvider') { foreach (glob(Yii::getPathOfAlias($where) . "/*Controller.php") as $controller) { if ($module) { if (DIRECTORY_SEPARATOR === '/') { // fix for windows machines self::$_moduleName = preg_replace('/^.*\\/modules\\/(.*)\\/controllers.*$/', '$1', $controller); } else { self::$_moduleName = preg_replace('/^.*\\\\modules\\\\(.*)\\\\controllers.*$/', '$1', $controller); } } else { self::$_moduleName = 'Basic'; } $_controllerName = basename($controller, "Controller.php"); // TODO when stop supporting php 5.2 use lcfirst $_controllerName[0] = strtolower($_controllerName[0]); self::$_controllerName = $_controllerName; $controller_class = ucfirst(self::$_controllerName . 'Controller'); // extract the value of permission controller inside the controller if (!in_array($controller_class, self::$_alreadyIncluded)) { // use reflectionClass if a controller with the same class name was not previously included // add the controller class to the alreadyIncluded array self::$_alreadyIncluded[] = $controller_class; if (!in_array($controller_class, self::$_declaredClasses)) { include $controller; } $class = new ReflectionClass($controller_class); if ($class->hasProperty('_permissionControl')) { $permissionControl = $class->getStaticPropertyValue('_permissionControl'); } else { $permissionControl = NULL; } } else { // parse the file if a controller with the same class name was previously included // get the controller file content $controller_file = file_get_contents($controller, false, NULL, 0); // check if there is permissionControl inside it if (strpos($controller_file, 'permissionControl') !== false) { // get portion of the file containing permissionControl $controller_file = substr($controller_file, strpos($controller_file, 'permissionControl')); $controller_file = substr($controller_file, 0, strpos($controller_file, ';')); $permissionControl = eval('return $' . $controller_file . ';'); } else { $permissionControl = NULL; } } // check the value of permissionControl and skip this controller if necessary if ($permissionControl === false || count($permissionControl) === 1 && isset($permissionControl['label']) && $mode === 'dataProvider') { continue; } if ($mode === 'dataProvider') { self::$_rawData[] = array('id' => NULL, 'Module' => self::$_moduleName, 'Controller' => isset($permissionControl['label']) ? $permissionControl['label'] : self::$_controllerName, 'Read' => self::infoButton($permissionControl, 'read'), 'Write' => self::infoButton($permissionControl, 'write'), 'Admin' => self::infoButton($permissionControl, 'admin')); } else { if ($mode === 'homeList') { self::$_rawData['/' . (self::$_moduleName === 'Basic' ? NULL : self::$_moduleName . '/') . self::$_controllerName] = (self::$_moduleName === 'Basic' ? NULL : self::$_moduleName . ': ') . (isset($permissionControl['label']) ? $permissionControl['label'] : self::$_controllerName); } } } }
/** * Returns object definition * * @param string $class Name of object * @param string|null $field Name of field if we want the definition of one field only * * @return array */ public static function getDefinition($class, $field = null) { if (is_object($class)) { $class = get_class($class); } if ($field === null) { $cache_id = 'objectmodel_def_' . $class; } if ($field !== null || !Cache::isStored($cache_id)) { $reflection = new ReflectionClass($class); if (!$reflection->hasProperty('definition')) { return false; } $definition = $reflection->getStaticPropertyValue('definition'); $definition['classname'] = $class; if (!empty($definition['multilang'])) { $definition['associations'][PrestaShopCollection::LANG_ALIAS] = array('type' => self::HAS_MANY, 'field' => $definition['primary'], 'foreign_field' => $definition['primary']); } if ($field) { return isset($definition['fields'][$field]) ? $definition['fields'][$field] : null; } Cache::store($cache_id, $definition); return $definition; } return Cache::retrieve($cache_id); }
/** * Get value of property by it's name * FIXME: Move to parent class Struct, when php will have late static binding * * @param $key Key name * @return string */ public static function GetValue($key) { //property_exists $ReflectionClassThis = new ReflectionClass(__CLASS__); if ($ReflectionClassThis->hasProperty($key)) { return $ReflectionClassThis->getStaticPropertyValue($key); } else { throw new Exception(sprintf(_("Called %s::GetValue('{$key}') for non-existent property {$key}"), __CLASS__)); } }
/** * @param string $property * @return mixed */ public function __get($property) { $class = new \ReflectionClass($this->_staticClassName); return $class->getStaticPropertyValue($property); }
<?php class C { public static $x; } $rc = new ReflectionClass('C'); try { var_dump($rc->getStaticPropertyValue("x", "default value", 'blah')); } catch (Exception $e) { echo $e->getMessage() . "\n"; } try { var_dump($rc->getStaticPropertyValue()); } catch (Exception $e) { echo $e->getMessage() . "\n"; } try { var_dump($rc->getStaticPropertyValue(null)); } catch (Exception $e) { echo $e->getMessage() . "\n"; } try { var_dump($rc->getStaticPropertyValue(1.5, 'def')); } catch (Exception $e) { echo $e->getMessage() . "\n"; } try { var_dump($rc->getStaticPropertyValue(array(1, 2, 3))); } catch (Exception $e) { echo $e->getMessage() . "\n";
print "\n"; print "--- getProperty() ---\n"; # Very verbose. #var_dump( $rb->getProperty('p0'); print "\n"; print "--- getStaticProperties() ---\n"; # Very verbose. #var_dump( $rb->getStaticProperties(); print "\n"; print "--- setStaticPropertyValue() ---\n"; var_dump($rb->setStaticPropertyValue('s0', 'new value for s0')); print "\n"; print "--- getStaticPropertyValue() ---\n"; var_dump($rb->getStaticPropertyValue('s0')); var_dump($rb->getStaticPropertyValue('s4')); print "\n"; print "--- hasConstant() ---\n"; var_dump($rb->hasConstant('C0')); var_dump($rb->hasConstant('C4')); print "\n"; print "--- hasMethod() ---\n"; var_dump($rb->hasMethod('methB')); var_dump($rb->hasMethod('methX')); print "\n"; print "--- hasProperty() ---\n"; var_dump($rb->hasProperty('p0')); var_dump($rb->hasProperty('p4')); print "\n"; print "--- implementsInterface() ---\n";
/** * Get object definition * * @param string $class Name of object * @param string $field Name of field if we want the definition of one field only * @return array */ public static function getDefinition($class, $field = null) { if (is_object($class)) { $class = get_class($class); } if ($field === null) { $cache_id = 'objectmodel_def_' . $class; } if ($field !== null || !Cache::isStored($cache_id)) { $reflection = new ReflectionClass($class); $definition = $reflection->getStaticPropertyValue('definition'); $definition['classname'] = $class; if ($field) { return isset($definition['fields'][$field]) ? $definition['fields'][$field] : null; } Cache::store($cache_id, $definition); return $definition; } return Cache::retrieve($cache_id); }
/** * */ public static function init_entity_data($artifact_name) { $entity_data = array(); $entity_data['has_errors'] = false; // Get the requested artifact name if (EntityStringUtils::is_invalid_string($artifact_name)) { $entity_data['has_errors'] = true; $entity_data['error_message'] = 'Artifact name must be specified'; return $entity_data; } // Check if artifact to entity name mapping exists if (!isset(ArtifactUtils::$artifacts[$artifact_name])) { $entity_data['has_errors'] = true; $entity_data['error_message'] = 'Artifact not found'; return $entity_data; } // Check the type of the artifact $entity_data['entity_artifact_name'] = $artifact_name; $entity_data['entity_name'] = ArtifactUtils::$artifacts[$artifact_name]['name']; $entity_data['artifact_type'] = ArtifactUtils::$artifacts[$artifact_name]['artifact_type']; $entity_data['entity_description'] = ArtifactUtils::$artifacts[$artifact_name]['description']; if ($entity_data['artifact_type'] != 'entity') { return $entity_data; } // Use reflection to get the post name and entity fields from // the model class $entity_name = ArtifactUtils::$artifacts[$artifact_name]['name'] . 'CPT'; $entity_class = new ReflectionClass($entity_name); $post_name = $entity_class->getStaticPropertyValue('post_name'); // Check the ajax request $entity_data['entity_post_name'] = $post_name; $entity_data['entity_fields'] = $entity_class->getStaticPropertyValue('entity_fields'); $entity_data['related_child_entities'] = $entity_class->getStaticPropertyValue('related_child_entities'); $entity_data['is_global_entity'] = $entity_class->getStaticPropertyValue('is_global_entity'); return $entity_data; }
private function instantiate($name, $class, $config) { $module = $this->di->instantiate($class, [$this, $config], false); $this->modules[$name] = $module; if (!$this->active[$name]) { // if module is not active, its actions should not be included into actor class return $module; } if ($module instanceof DependsOnModule) { $this->injectDependentModule($name, $module); } $class = new \ReflectionClass($module); $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { $inherit = $class->getStaticPropertyValue('includeInheritedActions'); $only = $class->getStaticPropertyValue('onlyActions'); $exclude = $class->getStaticPropertyValue('excludeActions'); // exclude methods when they are listed as excluded if (in_array($method->name, $exclude)) { continue; } if (!empty($only)) { // skip if method is not listed if (!in_array($method->name, $only)) { continue; } } else { // skip if method is inherited and inheritActions == false if (!$inherit && $method->getDeclaringClass() != $class) { continue; } } // those with underscore at the beginning are considered as hidden if (strpos($method->name, '_') === 0) { continue; } if ($module instanceof PartedModule && isset($config['part'])) { if (!$this->moduleActionBelongsToPart($module, $method->name, $config['part'])) { continue; } } $this->actions[$method->name] = $name; } return $module; }
/** * Gets an object class property * * @param type $property * @param type $default */ public static function get($property, $default = NULL) { $object = new \ReflectionClass(Object::class); $value = $object->getStaticPropertyValue($property); //If there is no value return the default return empty($value) ? $default : $value; }