public function testCombinedStatic() { // test basic operation $this->assertEquals(array('test_1', 'test_2', 'test_3'), Object::combined_static('ObjectStaticTest_Combined3', 'first')); // test that null values are ignored, but values on either side are still merged $this->assertEquals(array('test_1', 'test_3'), Object::combined_static('ObjectStaticTest_Combined3', 'second')); // test the $ceiling param $this->assertEquals(array('test_2', 'test_3'), Object::combined_static('ObjectStaticTest_Combined3', 'first', 'ObjectStaticTest_Combined2')); }
/** * Since DataObjectRetroactiveCleanerTask can be destructive, * make sure that only admins can run it. */ public function testAccessRestrictionWithNonAdminMember() { $devServers = Object::combined_static('Director', 'dev_servers'); Director::set_dev_servers(array('example.com')); $response = $this->get("dev/tasks/DataObjectRetroactiveCleanerTask"); $selector = 'form[action="Security/LoginForm"]'; $this->assertTrue((bool)$this->cssParser()->getBySelector($selector), 'Non admin members can run DataObjectRetroactiveCleanerTask.'); Director::set_dev_servers($devServers); }
/** * Return a list of all available keywords in the format * * array( * 'keyword' => 'A description' * ) * * @return array */ public function getAvailableKeywords() { if (!$this->availableKeywords) { $objectFields = Object::combined_static($this->class, 'db'); // $objectFields = array_combine(array_keys($objectFields), array_keys($objectFields)); $objectFields['Created'] = 'Created'; $objectFields['LastEdited'] = 'LastEdited'; $this->availableKeywords = array(); foreach ($objectFields as $key => $value) { $this->availableKeywords[$key] = array('short' => $key, 'long' => $key); } } return $this->availableKeywords; }
/** * Get all updatable relations from $this->owner. * * @return array */ protected function updatableRelations() { $updatableRelations = array(); foreach (array_merge($this->owner->has_many(), $this->getExtensionComponents('has_many')) as $hasManyRelation => $hasManyClass) { $hasOneOnVersioning = (array)Object::combined_static($hasManyClass, 'has_one_on_versioning'); foreach ($hasOneOnVersioning as $onUpdateRelation => $process) { $hasOneClass = singleton($hasManyClass)->has_one($onUpdateRelation); if (in_array($hasOneClass, ClassInfo::ancestry($this->owner->ClassName)) && $process) { $updatableRelations[$hasManyRelation] = array( $hasManyClass, $onUpdateRelation ); } } } return $updatableRelations; }
public function __construct($name, $title = null, $options = array()) { parent::__construct($name, $title); $defaults = Object::combined_static($this->class, 'default_options', 'ItemSetField'); $this->options = array_merge($defaults, $options ? $options : array()); }
/** * Get a unified array of allowed actions on this controller (if such data is available) from both the controller * ancestry and any extensions. * * @return array|null */ public function allowedActions() { $actions = Object::combined_static(get_class($this), 'allowed_actions', 'RequestHandler'); foreach ($this->extension_instances as $extension) { if ($extensionActions = Object::get_static(get_class($extension), 'allowed_actions')) { $actions = array_merge($actions, $extensionActions); } } if ($actions) { // convert all keys and values to lowercase to // allow for easier comparison, unless it is a permission code $actions = array_change_key_case($actions, CASE_LOWER); foreach ($actions as $key => $value) { if (is_numeric($key)) { $actions[$key] = strtolower($value); } } return $actions; } }
/** * Builds out the metadata for the class attribute of the file input tag. This * is later parsed by the jQuery metadata plugin. * * @return string */ public function Metadata() { $ret = array(); $vars = Object::combined_static(get_class($this), "defaults"); foreach ($vars as $setting => $value) { $ret[] = "{$setting} : '" . $this->getSetting($setting) . "'"; } $data = implode(",", $ret); if (!empty($this->extraParams)) { $data .= ", scriptData : { "; $extras = array(); foreach ($this->extraParams as $key => $val) { $extras[] = "'{$key}' : '{$val}'"; } $params = implode(",", $extras); $data .= $params . "}"; } return $data; }
/** * Check that the given action is allowed to be called from a URL. * It will interrogate {@link self::$allowed_actions} to determine this. */ function checkAccessAction($action) { $action = strtolower($action); $allowedActions = Object::combined_static(get_class($this), 'allowed_actions'); $newAllowedActions = array(); // merge in any $allowed_actions from extensions if ($this->extension_instances) { foreach ($this->extension_instances as $extension) { if ($extAccess = $extension->stat('allowed_actions')) { $allowedActions = array_merge($allowedActions, $extAccess); } } } if ($action == 'index') { return true; } if ($allowedActions) { foreach ($allowedActions as $key => $value) { $newAllowedActions[strtolower($key)] = strtolower($value); } $allowedActions = $newAllowedActions; if (isset($allowedActions[$action])) { $test = $allowedActions[$action]; // PHP can be loose about typing; let's give people a break if true becomes 1 or '1' if ($test === true || $test === 1 || $test === '1') { return true; } elseif (substr($test, 0, 2) == '->') { return $this->{substr($test, 2)}(); } elseif (Permission::check($test)) { return true; } } elseif (($key = array_search($action, $allowedActions)) !== false && is_numeric($key)) { return true; } } if ($allowedActions === null || !$this->uninherited('allowed_actions')) { // If no allowed_actions are provided, then we should only let through actions that aren't handled by magic methods // we test this by calling the unmagic method_exists and comparing it to the magic $this->hasMethod(). This will // still let through actions that are handled by templates. return method_exists($this, $action) || !$this->hasMethod($action); } return false; }
/** * Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field * on this object. MODIFIED TO LEAVE FAILOVER ALONE (so it doesn't have to inherit Object). * * @param string $field * @return string */ public function castingHelper($field) { if ($this->hasMethod('db') && ($fieldSpec = $this->db($field))) { return $fieldSpec; } $specs = Object::combined_static(get_class($this), 'casting'); if (isset($specs[$field])) { return $specs[$field]; } //if($this->failover) return $this->failover->castingHelper($field); }
/** * Gets the class of a one-to-many relationship. If no $component is specified then an array of all the one-to-many * relationships and their classes will be returned. * * @param string $component Name of component * @param bool $classOnly If this is TRUE, than any has_many relationships in the form "ClassName.Field" will have * the field data stripped off. It defaults to TRUE. * @return string|array */ public function has_many($component = null, $classOnly = true) { $hasMany = Object::combined_static($this->class, 'has_many', 'DataObject'); if ($component) { if ($hasMany && array_key_exists($component, $hasMany)) { $hasMany = $hasMany[$component]; } else { return false; } } if ($hasMany && $classOnly) { return preg_replace('/(.+)?\\..+/', '$1', $hasMany); } else { return $hasMany ? $hasMany : array(); } }
/** * Probe the given relation, it is necessary to find out * which relations on $class which links back to the given * $ownerRelationName, for each match self::handleRelation() * is called to have it handled. * * @param string $ownerRelationName The name of the current * relation on the owner. * @param string $class The class for $ownerRelationName. */ public function probeRelationClass($ownerRelationName, $class) { $ancestry = ClassInfo::ancestry($this->object->ClassName); foreach ((array)Object::combined_static($class, 'has_one') as $relationName => $relationClass) { if (in_array($relationClass, $ancestry)) $this->handleRelation($ownerRelationName, $class, $relationName); } }
public function __construct() { $this->options = Object::combined_static(get_class($this), 'default_options'); }