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

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

Validate if a document is of the specified class, if the global setting to validate is activated.
public validateClassName ( object $document, string | null $className )
$document object
$className string | null The class name $document must be instanceof. Pass empty to not validate anything.
    public function validateClassName($document, $className)
    {
        if (isset($className) && $this->validateDocumentName) {
            $this->documentClassMapper->validateClassName($this->dm, $document, $className);
        }
    }

Usage Example

Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function findTranslation($className, $id, $locale, $fallback = true)
 {
     try {
         if (UUIDHelper::isUUID($id)) {
             try {
                 $id = $this->session->getNodeByIdentifier($id)->getPath();
             } catch (ItemNotFoundException $e) {
                 return null;
             }
         } elseif (strpos($id, '/') !== 0) {
             $id = '/' . $id;
         }
         $document = $this->unitOfWork->getDocumentById($id);
         if ($document) {
             $this->unitOfWork->validateClassName($document, $className);
             $class = $this->getClassMetadata(get_class($document));
             $this->unitOfWork->doLoadTranslation($document, $class, $locale, $fallback);
             return $document;
         }
         $node = $this->session->getNode($id);
     } catch (PathNotFoundException $e) {
         return null;
     }
     $hints = array('locale' => $locale, 'fallback' => $fallback);
     return $this->unitOfWork->getOrCreateDocument($className, $node, $hints);
 }
UnitOfWork