/** * Applies filter chain to the $value. * Depending on the type of the $value, different filter handler classes are used. * Their apply() methods will return here to decide the handler class for the next filter in the chain * * @param $value * @param $filters * @param array $params * * @return string */ public static function applyModifier($value, $filters, $params = array()) { if (is_object($value)) { return ObjectModifier::apply($value, $filters, $params); } else { if (is_array($value)) { return ArrayModifier::apply($value, $filters, $params); } else { if (is_numeric($value)) { return NumericModifier::apply($value, $filters, $params); } else { return ScalarModifier::apply($value, $filters, $params); } } } }
public function establishLinks(Schema $schema, ObjectModifier $objectModifier, Audit $audit) { if ($this->scope->includes(Scope::TAG_ASSOCIATES) == Scope::INCLUDES_NONE) { return; } // Create and/or delete all remaining relationships. // Group all relationships per relatedEntity. $relatedEntityObjectsMap = array(); foreach ($this->relatedObjects as $relatedObject) { $relatedEntityName = $relatedObject->entity->getName(); if (!array_key_exists($relatedEntityName, $relatedEntityObjectsMap)) { $relatedEntityObjectsMap[$relatedEntityName] = array(); } $relatedEntityObjectsMap[$relatedEntityName][] = $relatedObject; } // Now add or delete links corresponding to the specifoed relatedObjects. $processedLinkRelationships = array(); foreach ($relatedEntityObjectsMap as $relatedEntityName => $relatedObjects) { $linkRelationship = $schema->getLinkRelationship($this->entity, $schema->getObjectEntity($relatedEntityName), FALSE); if ($linkRelationship != NULL) { $otherIds = array(); foreach ($relatedObjects as $relatedObject) { $otherIds[] = $relatedObject->id; } $objectModifier->establishLinks($schema, $linkRelationship->getFkEntity(), $linkRelationship->getFkColumnName($this->entity), $this->id, $linkRelationship->getFkColumnName($relatedObject->entity), $otherIds, $audit); // Remove the reversed direction of the links, so they won't be processed twice. foreach ($relatedObjects as $relatedObject) { $relatedObject->removeRelatedObject($this); } // Keep track of all processed link-relationships. $processedLinkRelationships[] = $linkRelationship; } } // Delete any link that was NOT specified in the ParsedObject. foreach ($this->entity->getRelationships() as $relationship) { $oppositeEntity = $relationship->getOppositeEntity($this->entity); if (!$relationship->getFkEntity()->isObjectEntity() and $oppositeEntity->isObjectEntity() and array_search($relationship, $processedLinkRelationships) === FALSE) { // Call establishLinks() with an empty list of referring id's, so any persisted link will be deleted. $objectModifier->establishLinks($schema, $relationship->getFkEntity(), $relationship->getFkColumnName($this->entity), $this->id, $relationship->getFkColumnName($oppositeEntity), array(), $audit); } } }