本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectManager::detach方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::detach方法的具体用法?PHP ObjectManager::detach怎么用?PHP ObjectManager::detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::detach方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildEntity
public function buildEntity($value)
{
$parent = null;
$child = null;
try {
/* @var $parent \Giosh94mhz\GeonamesBundle\Entity\Toponym */
$parent = $this->toponymRepository->find($value[0]);
/* @var $child \Giosh94mhz\GeonamesBundle\Entity\Toponym */
$child = $this->toponymRepository->find($value[1]);
if (!$parent || !$child) {
throw new MissingToponymException("HierarchyLink not imported due to missing toponym '{$value['0']}=>{$value['1']}'");
}
/* @var $link \Giosh94mhz\GeonamesBundle\Entity\HierarchyLink */
$link = $this->repository->find(array('parent' => $parent->getId(), 'child' => $child->getId())) ?: new HierarchyLink($parent, $child);
$link->setType($value[2]);
return $link;
} catch (\Exception $e) {
if ($parent !== null) {
$this->om->detach($parent);
}
if ($child !== null) {
$this->om->detach($child);
}
throw $e;
}
}
示例2: get
/**
* {@inheritdoc}
*/
public function get($name, $locale = null, $default = null)
{
if (null === $locale) {
if (null === $this->requests || !($request = $this->requests->getMasterRequest())) {
throw new MissingLocaleException('Could not get content because locale is missing. Try passing it as a parameter.');
}
$locale = $request->getLocale();
}
$content = $this->om->getRepository(Content::class)->findOneBy(['name' => $name, 'locale' => $locale]);
if (!$content) {
if (null === $default) {
$default = $name;
}
$content = $this->create($name, $default, $locale);
}
$this->om->detach($content);
return $content;
}
示例3: buildMenuFromRepository
/**
* Build menu.
*
* @param string $menuCode Menu code
*
* @return MenuInterface Menu
*
* @throws Exception
*/
private function buildMenuFromRepository($menuCode)
{
$menu = $this->menuRepository->findOneBy(['code' => $menuCode, 'enabled' => true]);
if (!$menu instanceof MenuInterface) {
throw new Exception(sprintf('Menu "%s" not found', $menuCode));
}
$this->menuObjectManager->detach($menu);
return $menu;
}
示例4: load
/**
* Load meta object by provided type and parameters.
*
* @MetaLoaderDoc(
* description="Article Loader loads articles from Content Repository",
* parameters={
* contentPath="SINGLE|required content path",
* slug="SINGLE|required content slug",
* pageName="COLLECTiON|name of Page for required articles"
* }
* )
*
* @param string $type object type
* @param array $parameters parameters needed to load required object type
* @param int $responseType response type: single meta (LoaderInterface::SINGLE) or collection of metas (LoaderInterface::COLLECTION)
*
* @return Meta|Meta[]|bool false if meta cannot be loaded, a Meta instance otherwise
*
* @throws \Exception
*/
public function load($type, $parameters = [], $responseType = LoaderInterface::SINGLE)
{
$criteria = new Criteria();
if ($responseType === LoaderInterface::SINGLE) {
if (array_key_exists('article', $parameters) && $parameters['article'] instanceof ArticleInterface) {
$this->dm->detach($parameters['article']);
$criteria->set('id', $parameters['article']->getId());
} elseif (array_key_exists('slug', $parameters)) {
$criteria->set('slug', $parameters['slug']);
}
try {
return $this->getArticleMeta($this->articleProvider->getOneByCriteria($criteria));
} catch (NotFoundHttpException $e) {
return;
}
} elseif ($responseType === LoaderInterface::COLLECTION) {
$currentPage = $this->context->getCurrentPage();
$route = null;
if (null !== $currentPage) {
$route = $currentPage->getValues();
}
if (array_key_exists('route', $parameters)) {
if (null === $route || $route instanceof RouteInterface && $route->getId() !== $parameters['route']) {
if (is_int($parameters['route'])) {
$route = $this->routeProvider->getOneById($parameters['route']);
} elseif (is_string($parameters['route'])) {
$route = $this->routeProvider->getOneByStaticPrefix($parameters['route']);
}
}
}
if ($route instanceof RouteInterface) {
$criteria->set('route', $route);
} else {
return;
}
$criteria = $this->applyPaginationToCriteria($criteria, $parameters);
$articles = $this->articleProvider->getManyByCriteria($criteria);
if ($articles->count() > 0) {
$metaCollection = new MetaCollection();
$metaCollection->setTotalItemsCount($this->articleProvider->getCountByCriteria($criteria));
foreach ($articles as $article) {
$articleMeta = $this->getArticleMeta($article);
if (null !== $articleMeta) {
$metaCollection->add($articleMeta);
}
}
unset($articles, $route, $criteria);
return $metaCollection;
}
}
return;
}
示例5: load
public function load(ObjectManager $manager)
{
// Retrieve the Faker service
$faker = $this->container->get('faker.generator');
// Retrieve the password encoder
$encoder = $this->container->get('security.encoder_factory')->getEncoder('KingFoo\\BookmarkerBundle\\Entity\\User');
// Create some tags
$labels = array('doctrine', 'symfony', 'twig', 'kingfoo', 'training', 'yaml', 'php', 'mvc');
$tags = array();
foreach ($labels as $label) {
$tag = new Tag($label);
$manager->persist($tag);
$tags[] = $tag;
}
$manager->flush();
$popular = array('http://symfony.com/', 'http://www.doctrine-project.org/', 'http://twig.sensiolabs.org/', 'http://www.google.com/');
for ($i = 0; $i < 20; $i++) {
// Create a new user
$user = new User();
$user->setUsername($faker->username)->setEmail($faker->email)->setPassword($encoder->encodePassword($user->getUsername(), $user->getSalt()));
$manager->persist($user);
// Add a popular bookmark
$bookmark = new Bookmark();
$bookmark->setUser($user)->setUrl($faker->randomElement($popular))->setDescription($faker->paragraph)->setCreatedAt($faker->dateTimeThisMonth);
// Add some tags
shuffle($tags);
for ($j = 0; $j < rand(1, count($tags)); $j++) {
$tag = $tags[($i + $j) % count($tags)];
$bookmark->addTag($tag);
}
$manager->persist($bookmark);
// Create some random bookmarks for every user
for ($j = 0; $j < 50; $j++) {
$bookmark = new Bookmark();
$bookmark->setUser($user)->setUrl($faker->url)->setDescription($faker->paragraph)->setCreatedAt($faker->dateTimeThisYear);
// Add some tags
shuffle($tags);
for ($k = 0; $k < rand(1, count($tags)); $k++) {
$tag = $tags[($i + $j + $k) % count($tags)];
$bookmark->addTag($tag);
}
$manager->persist($bookmark);
}
$manager->flush();
$manager->detach($user);
$manager->clear('KingFoo\\BookmarkerBundle\\Entity\\Bookmark');
}
}
示例6: load
/**
* @param BlockInterface $block
*/
public function load(BlockInterface $block)
{
$this->form = $this->formFactory->create(SubscribeType::class, $this->subscription);
$this->form->handleRequest($this->request);
if ($this->form->isValid()) {
foreach ($this->getMailingLists($block) as $mailingList) {
$this->subscription->setMailingList($mailingList);
$this->em->persist($this->subscription);
$this->em->flush($this->subscription);
// Reset to add to another mailing list
$this->em->detach($this->subscription);
$this->subscription = clone $this->subscription;
$this->subscription->setId(null);
}
$this->subscribed = true;
}
}
示例7: detach
/**
* @param ResourceInterface $resource
*/
public function detach(ResourceInterface $resource)
{
$this->manager->detach($resource);
}
示例8: detach
/**
* @param \Symfony\Component\Security\Core\User\UserInterface $user
* @return self
*/
public function detach(UserInterface $user)
{
$this->em->detach($user);
return $this;
}
示例9: insertUsers
/**
* Insert new users
*
* @param Collection $users
*/
private function insertUsers(Collection $users)
{
set_time_limit(60);
$this->manager->getConnection()->getConfiguration()->setSQLLogger(null);
// Get existan user from DB
$existantUsers = $this->repository->findBy(['email' => $this->extractEmails($users)->toArray()]);
// Create an array of emails
$existantEmails = array_map(function ($user) {
return $user->getEmail();
}, $existantUsers);
unset($existantUsers);
// Get not existant users ready to import
$nonExistantUsers = $users->filter(function ($user) use($existantEmails) {
return !in_array($user->getEmail(), $existantEmails);
});
unset($existantEmails);
foreach ($nonExistantUsers as $user) {
$user->addRole('ROLE_USER');
$this->manager->persist($user);
$this->manager->flush();
$this->manager->clear();
$this->manager->detach($user);
gc_enable();
gc_collect_cycles();
}
}