/** * @param $key * * @return null */ public function __get($key) { /** * Return value via getter */ if (method_exists($this, 'get' . Convention::toPascal($key) . 'Attribute')) { return $this->{'get' . Convention::toPascal($key) . 'Attribute'}(); } /** * Return value, even if it's null or not set. */ if ($this->keyExists($key)) { return $this->getValue($key); } /** * Return value from existing relation (Collection or Record). */ if ($this->relationExists($key)) { return $this->getRelation($key); } /** * @T00D00 - Entity is needed here just for cache, optimize this ... :/ * $Reflection = new ReflectionProperty(get_class($a), 'a'); */ $entity = $this->getEntity(); if ($entity->getRepository()->getCache()->tableHasField($entity->getTable(), $key)) { return $this->getValue($key); } /** * Return value from empty relation. * * @T00D00 - optimize this */ if (method_exists($entity, $key)) { $relation = $entity->{$key}(); $relation->fillRecord($this); return $this->getRelation($relation->getFill()); } /** * Return value from extension. */ if ($chains = $this->getEntityChains($entity, $key, '__get')) { return chain($chains); } return null; }
public function prepare(Order $order, $handler, Log $logger) { $this->setOrder($order); $this->{'use' . Convention::toPascal($handler) . 'Handler'}(); $this->getHandler()->setLogger($logger)->setEnvironment($this->environment); }
public function getToArrayValues() { $values = []; foreach ($this->toArray as $key) { if ($this->hasKey($key)) { $values[$key] = $this->{$key}; } elseif ($this->hasRelation($key)) { $values[$key] = $this->getRelationIfSet($key); } elseif (method_exists($this, 'get' . Convention::toPascal($key) . 'Attribute')) { $values[$key] = $this->{'get' . Convention::toPascal($key) . 'Attribute'}(); } } return $values; }
protected function transformRecord(RecordInterface $record) { $transformed = []; /** * Table fields */ foreach ($this->getFields() as $key => $field) { $transformed[is_string($key) ? $key : (is_string($field) ? $field : $field->field)] = $this->getRecordValue($field, $record); } /** * Additional fields */ foreach ($this->getFieldTransformations() as $key => $field) { $transformed[is_string($key) ? $key : (is_string($field) ? $field : $field->field)] = $this->getRecordValue($field, $record); } /** * We also need to fetch URLs. */ if (!$this->dataOnly) { foreach ($this->getRecordActions() as $recordAction) { $method = is_string($recordAction) ? $recordAction : $recordAction->slug; if ($method && method_exists($record, 'get' . Convention::toPascal($method) . 'Url')) { $transformed[$method . 'Url'] = $record->{'get' . Convention::toPascal($method) . 'Url'}(); } } $transformed = array_merge($record->getToArrayValues(), $transformed); /*foreach ($record->getToArrayValues() as $key => $value) { $transformed[$key] = $value; }*/ } return $transformed; }