/** * Overloaded magic method so that attribute values can be retrieved for display * in CTFs etc. * * @see ViewableData::__get() * @see Product::getCMSFields() */ public function __get($property) { if (strpos($property, 'AttributeValue_') === 0) { return $this->SummaryOfOptionValueForAttribute(str_replace('AttributeValue_', '', $property)); } else { return parent::__get($property); } }
/** * * Dynamically augments any $cacheableClass object with * methods and properties of $model. * * Warning: Uses PHP magic methods __get() and __set(). * * @param DataObject $model * @param string $cacheableClass * @return ViewableData $cacheable */ public static function model2cacheable(DataObject $model, $cacheableClass = null) { if (!$cacheableClass) { $cacheableClass = "Cacheable" . $model->ClassName; } $cacheable = $cacheableClass::create(); $cacheable_fields = $cacheable->get_cacheable_fields(); foreach ($cacheable_fields as $field) { $cacheable->__set($field, $model->__get($field)); } $cacheable_functions = $cacheable->get_cacheable_functions(); foreach ($cacheable_functions as $function) { /* * Running tests inside a project with its own YML config for * cacheable_fields and cacheable_functions will fail if we don't check first */ if ($model->hasMethod($function)) { $cacheable->__set($function, $model->{$function}()); } } return $cacheable; }
/** * Return from the parent object if it's not in here... * * @see sapphire/core/ViewableData#__get($property) */ function __get($prop) { if (isset($this->remoteProperties[$prop])) { return $this->remoteProperties[$prop]; } $val = parent::__get($prop); if (!$val) { if ($this->source) { // get it from there return $this->source->{$prop}; } } return $val; }
/** * Attempts to return the $field from this MenuItem * If $field is not found or it is not set then attempts * to return a similar field on the associated Page * (if there is one) * * @param string $field * @return mixed */ public function __get($field) { $default = parent::__get($field); if ($default || $field === 'ID') { return $default; } else { $page = $this->Page(); if ($page instanceof DataObject) { if ($page->hasMethod($field)) { return $page->{$field}(); } else { return $page->{$field}; } } } }
function __get($key) { return parent::__get($key); }