/** * @param RecordSchema $entity * @param ClassElement $element * @param ManyToMorphedSchema $relation */ protected function renderManyToMorphedRelation(RecordSchema $entity, ClassElement $element, ManyToMorphedSchema $relation) { //Rendering relation method $relationElement = new ClassElement($elementName = $this->createName($entity->getName(), $relation->getTarget(), 'relation')); //Clone schema from appropriate relation $relationClass = $this->builder->config()['relations'][$relation->getType()]['class']; $relationElement->cloneSchema($relationClass); $this->cleanElement($relationElement); $relationElement->setParent('\\' . $relationClass)->setInterfaces([]); //Let's render sub relations foreach ($relation->outerRecords() as $record) { $related = '\\' . $record->getName() . '[]'; if ($relation->isMultiple()) { $related .= '|' . $this->helper('iterator', $record->getName()); } $name = Inflector::pluralize($record->getRole()); $relationElement->property($name, "@var {$related}")->setAccess(AbstractElement::ACCESS_PUBLIC); //Nested relation $relationElement->method($name, ["@return " . $this->renderNestedMany($record)]); } $name = $relation->getTarget(); $relationElement->replaceComments(Record::class, $name); $relationElement->replaceComments("Record", '\\' . $name); $fullName = $this->addClass($relationElement); $element->property($relation->getName(), "@var {$fullName}")->setAccess(AbstractElement::ACCESS_PUBLIC); $element->method($relation->getName(), "@return {$fullName}"); }
/** * {@inheritdoc} */ protected function parentSchema() { if (!$this->builder->hasRecord($this->getParentClass()->getName())) { return null; } return $this->builder->record($this->getParentClass()->getName()); }
/** * Get RecordSchema to be associated with, method must throw an exception if outer record not * found. * * @return RecordSchema * @throws RelationSchemaException * @throws SchemaException * @throws RecordSchemaException */ protected function outerRecord() { if (!$this->builder->hasRecord($this->target)) { throw new RelationSchemaException("Undefined outer record '{$this->target}' in relation '{$this->record}'.'{$this}'."); } return $this->builder->record($this->target); }