Kdyby\Doctrine\EntityManager::clear PHP Method

clear() public method

public clear ( $entityName = null ) : EntityManager
return EntityManager
    public function clear($entityName = null)
    {
        foreach (is_array($entityName) ? $entityName : func_get_args() + [0 => NULL] as $item) {
            parent::clear($item);
        }
        return $this;
    }

Usage Example

コード例 #1
0
 /**
  * @param Listing $listing
  * @param bool $withItems
  * @param array|null $valuesForNewListing
  * @return Listing
  * @throws \Exception
  */
 public function establishListingCopy(Listing $listing, $withItems = true, array $valuesForNewListing = null)
 {
     Validators::assert($withItems, 'boolean');
     $newListing = clone $listing;
     if (isset($valuesForNewListing)) {
         $newListing->setDescription($valuesForNewListing['description']);
         $newListing->setHourlyWage($valuesForNewListing['hourlyWage']);
     }
     $this->em->persist($newListing);
     if ($withItems === true) {
         $copies = $this->getItemsCopies($listing);
         if (!empty($copies)) {
             foreach ($copies as $copy) {
                 $copy->setListing($newListing);
                 $this->em->persist($copy);
             }
         }
     }
     try {
         $this->em->flush();
         $this->em->clear();
     } catch (\Exception $e) {
         $this->onError('establishListingCopy', $e, self::class);
         throw $e;
     }
     return $newListing;
 }
All Usage Examples Of Kdyby\Doctrine\EntityManager::clear