예제 #1
0
파일: Hooks.php 프로젝트: xeeo/php-services
 private static function callPostSaveHook(AbstractEntity $entity)
 {
     $entity->postSaveHook();
     foreach ($entity->getData() as $fieldInstance) {
         if ($fieldInstance instanceof AbstractEntity) {
             self::callPostSaveHook($fieldInstance);
         }
     }
 }
예제 #2
0
 public static function save(AbstractEntity $entity, array $options = array())
 {
     $collection = self::getCollection();
     $entity->validate();
     self::callPreSaveHook($entity);
     $entityToSave = $entity->toArray();
     try {
         $collection->save($entityToSave, $options);
         $entity->setField('_id', $entityToSave['_id']);
         self::callPostSaveHook($entity);
     } catch (\Exception $e) {
         throw new MapperException($e->getMessage(), $e->getCode(), $e->getPrevious());
     }
     return $entity;
 }