set() public method

public set ( string $field, mixed $value, boolean $modified = true )
$field string
$value mixed
$modified boolean
示例#1
0
 /**
  * Load an entity relation object into the entity object
  *
  * @param \Spot\Entity $entity
  * @param string $field
  * @param \Spot\Entity\Relation\AbstractRelation
  * @param \Spot\Mapper $mapper
  * @param bool $reload
  * @return \Spot\Entity\EntityInterface
  * @throws \InvalidArgumentException
  */
 protected function loadRelationObject($entity, $field, $relation, Mapper $mapper, $reload = false)
 {
     $entityName = $entity instanceof ResultsetInterface ? $entity->getEntityName() : $entity->toString();
     if (empty($entityName)) {
         throw new \InvalidArgumentException("Cannot load relation with a null \$entityName");
     }
     if (isset($entity->{$field}) && !$reload) {
         return $entity->{$field};
     }
     $relationEntity = isset($relation['entity']) ? $relation['entity'] : false;
     if (!$relationEntity) {
         throw new \InvalidArgumentException("Entity for '" . $field . "' relation has not been defined.");
     }
     // Self-referencing entity relationship?
     $relationEntity == ':self' && ($relationEntity = $entityName);
     // Load relation class to lazy-loading relations on demand
     $relationClass = '\\Spot\\Entity\\Relation\\' . $relation['type'];
     // Set field equal to relation class instance
     $relation = new $relationClass($mapper, $this->entityManager, $entity, $relation);
     // Inject relation object into entity property
     if (!$entity instanceof ResultsetInterface) {
         $entity->set($field, $relation);
     }
     return $relation;
 }