64 if ($referenceEntity instanceof
Entity)
66 $this->refEntity = $referenceEntity;
67 $this->refEntityName = $referenceEntity->getFullName();
75 parent::__construct(
$name);
94 $this->mediatorEntity =
$entity;
95 $this->mediatorEntityName =
$entity->getFullName();
115 $this->mediatorTableName =
$name;
142 $this->localPrimaryNames[$fieldName] = $mediatorFieldName;
156 $this->localReferenceName =
$name;
171 $this->remotePrimaryNames[$fieldName] = $mediatorFieldName;
185 $this->remoteReferenceName =
$name;
197 return $this->getRefEntity();
205 public function getMediatorEntity()
207 if ($this->mediatorEntity ===
null)
209 if (!empty($this->mediatorEntityName) &&
Entity::has($this->mediatorEntityName))
217 if (empty($this->mediatorTableName))
220 'Table Name for mediator entity of relation `%s` between %s and %s was not found',
221 $this->name, $this->
getEntity()->getObjectClass(), $this->getRefEntity()->getObjectClass()
226 if (empty($this->mediatorEntityName))
228 $localEntityName = $this->
getEntity()->getName();
229 $remoteEntityName = $this->getRefEntity()->getName();
233 $this->mediatorEntityName =
"MediatorFrom{$localEntityName}To{$remoteEntityName}Via{$fieldToClassName}Table";
242 foreach ($this->
getEntity()->getPrimaryArray() as $primaryName)
244 $mediatorPrimaryName = $this->localPrimaryNames[$primaryName] ?? $this->
getLocalReferenceName().
'_'.$primaryName;
246 $fieldType = get_class($this->
getEntity()->getField($primaryName));
249 $mediatorPrimary =
new $fieldType($mediatorPrimaryName);
250 $mediatorPrimary->configurePrimary(
true);
252 $fields[] = $mediatorPrimary;
255 $localReferenceConditions->whereColumn(
'this.'.$mediatorPrimaryName,
'ref.'.$primaryName);
261 $fields[] = $localReference;
266 foreach ($this->getRefEntity()->getPrimaryArray() as $primaryName)
268 $mediatorPrimaryName = $this->remotePrimaryNames[$primaryName] ?? $this->
getRemoteReferenceName().
'_'.$primaryName;
270 $fieldType = get_class($this->getRefEntity()->getField($primaryName));
273 $mediatorPrimary =
new $fieldType($mediatorPrimaryName);
274 $mediatorPrimary->configurePrimary(
true);
276 $fields[] = $mediatorPrimary;
279 $remoteReferenceConditions->whereColumn(
'this.'.$mediatorPrimaryName,
'ref.'.$primaryName);
283 $remoteReference = (
new Reference($this->
getRemoteReferenceName(), $this->getRefEntity(), $remoteReferenceConditions))
285 $fields[] = $remoteReference;
291 $this->mediatorEntity = Entity::compileEntity($this->mediatorEntityName, $fields, $parameters);
303 if (empty($this->localReferenceName))
330 if (empty($this->remoteReferenceName))
static normalizeName($entityName)
static getInstance($entityName)
configureRemoteReference($name)
configureTableName($name)
configureMediatorTableName($name)
__construct($name, $referenceEntity)
configureLocalPrimary($fieldName, $mediatorFieldName)
configureRemotePrimary($fieldName, $mediatorFieldName)
configureLocalReference($name)
configureMediatorEntity($entity)