當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DocumentManager::getLocalesFor方法代碼示例

本文整理匯總了PHP中Doctrine\ODM\PHPCR\DocumentManager::getLocalesFor方法的典型用法代碼示例。如果您正苦於以下問題:PHP DocumentManager::getLocalesFor方法的具體用法?PHP DocumentManager::getLocalesFor怎麽用?PHP DocumentManager::getLocalesFor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ODM\PHPCR\DocumentManager的用法示例。


在下文中一共展示了DocumentManager::getLocalesFor方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testFindTranslationNonPersisted

 public function testFindTranslationNonPersisted()
 {
     $a = new Article();
     $a->id = '/functional/' . $this->testNodeName;
     $a->title = 'Hello';
     $this->dm->persist($a);
     $translations = array('en' => array('topic' => 'Welcome', 'assoc_value' => 'in en'), 'fr' => array('topic' => 'Bienvenue', 'assoc_value' => 'in fr'), 'de' => array('topic' => 'Wilkommen', 'assoc_value' => 'in de'));
     foreach ($translations as $locale => $values) {
         $a->topic = $values['topic'];
         $a->assoc = array('key' => $values['assoc_value']);
         $this->dm->bindTranslation($a, $locale);
     }
     foreach ($translations as $locale => $values) {
         $trans = $this->dm->findTranslation('Doctrine\\Tests\\Models\\Translation\\Article', '/functional/' . $this->testNodeName, $locale);
         $this->assertNotNull($trans, 'Finding translation with locale "' . $locale . '"');
         $this->assertInstanceOf('Doctrine\\Tests\\Models\\Translation\\Article', $trans);
         $this->assertEquals($values['topic'], $trans->topic);
         $this->assertEquals($values['assoc_value'], $trans->assoc['key']);
         $this->assertEquals($locale, $trans->locale);
     }
     $locales = $this->dm->getLocalesFor($a);
     $this->assertEquals(array('en', 'fr', 'de'), $locales);
 }
開發者ID:steffenbrem,項目名稱:phpcr-odm,代碼行數:23,代碼來源:DocumentManagerTest.php

示例2: updateLocale

 /**
  * Update the locale of a route if $id starts with the prefix and has a
  * valid locale right after.
  *
  * @param Route           $doc   The route object
  * @param string          $id    The id (in move case, this is not the current
  *                               id of $route).
  * @param DocumentManager $dm    The document manager to get locales from if
  *                               the setAvailableTranslations option is
  *                               enabled.
  * @param boolean         $force Whether to update the locale even if the
  *                               route already has a locale.
  */
 protected function updateLocale(Route $doc, $id, DocumentManager $dm, $force = false)
 {
     $matches = array();
     // only update if the prefix matches, to allow for more than one
     // listener and more than one route root.
     if (!preg_match('#(' . implode('|', $this->getPrefixes()) . ')/([^/]+)(/|$)#', $id, $matches)) {
         return;
     }
     if (in_array($locale = $matches[2], $this->locales)) {
         if ($force || !$doc->getDefault('_locale')) {
             $doc->setDefault('_locale', $locale);
         }
         if ($force || !$doc->getRequirement('_locale')) {
             $doc->setRequirement('_locale', $locale);
         }
     } else {
         if ($this->addLocalePattern) {
             $doc->setOption('add_locale_pattern', true);
         }
         if ($this->updateAvailableTranslations && $dm->isDocumentTranslatable($doc) && !$doc->getRequirement('_locale')) {
             $locales = $dm->getLocalesFor($doc, true);
             $doc->setRequirement('_locale', implode('|', $locales));
         }
     }
 }
開發者ID:saberyounis,項目名稱:Sonata-Project,代碼行數:38,代碼來源:LocaleListener.php


注:本文中的Doctrine\ODM\PHPCR\DocumentManager::getLocalesFor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。