Doctrine\ODM\PHPCR\UnitOfWork::getLocalesFor PHP Метод

getLocalesFor() публичный Метод

Get all locales in which this document currently exists in storage.
public getLocalesFor ( object $document ) : array
$document object A managed document
Результат array list of locales of this document
    public function getLocalesFor($document)
    {
        $metadata = $this->dm->getClassMetadata(get_class($document));
        if (!$this->isDocumentTranslatable($metadata)) {
            throw new MissingTranslationException('This document is not translatable: : ' . self::objToStr($document, $this->dm));
        }
        $oid = spl_object_hash($document);
        if ($this->contains($oid)) {
            try {
                $node = $this->session->getNode($this->getDocumentId($document));
                $locales = $this->dm->getTranslationStrategy($metadata->translator)->getLocalesFor($document, $node, $metadata);
            } catch (PathNotFoundException $e) {
                $locales = array();
            }
        } else {
            $locales = array();
        }
        if (isset($this->documentTranslations[$oid])) {
            foreach ($this->documentTranslations[$oid] as $locale => $value) {
                if (!in_array($locale, $locales)) {
                    if ($value) {
                        $locales[] = $locale;
                    }
                } elseif (!$value) {
                    $key = array_search($locale, $locales);
                    unset($locales[$key]);
                }
            }
            $locales = array_values($locales);
        }
        return $locales;
    }

Usage Example

Пример #1
0
 /**
  * Get the list of locales that exist for the specified document,
  * including those not yet flushed, but bound
  *
  * @param $document the document to get the locales for
  *
  * @return array of strings with all locales existing for this particular document
  *
  * @throws PHPCRException if the document is not translatable
  */
 public function getLocalesFor($document)
 {
     if (!is_object($document)) {
         throw new \InvalidArgumentException(gettype($document));
     }
     $this->errorIfClosed();
     return $this->unitOfWork->getLocalesFor($document);
 }
All Usage Examples Of Doctrine\ODM\PHPCR\UnitOfWork::getLocalesFor
UnitOfWork