Doctrine\ODM\PHPCR\Mapping\ClassMetadata::isValidNodename PHP 메소드

isValidNodename() 공개 메소드

Check if this node name is valid. Returns null if valid, an exception otherwise.
public isValidNodename ( string $nodeName ) : PHPCR\RepositoryException | null
$nodeName string The node local name
리턴 PHPCR\RepositoryException | null
    public function isValidNodename($nodeName)
    {
        try {
            $parts = explode(':', $nodeName);
            if (1 > count($parts) || 2 < count($parts)) {
                return new RepositoryException("Name contains illegal characters: {$nodeName}");
            }
            if (0 === strlen($parts[0])) {
                return new RepositoryException("Name may not be empty: {$nodeName}");
            }
            PathHelper::assertValidLocalName($parts[0]);
            if (2 == count($parts)) {
                // [0] was the namespace prefix, also check the name
                PathHelper::assertValidLocalName($parts[1]);
                if (0 === strlen($parts[1])) {
                    return new RepositoryException("Local name may not be empty: {$nodeName}");
                }
            }
        } catch (RepositoryException $e) {
            return $e;
        }
        return null;
    }

Usage Example

예제 #1
0
 /**
  * Use the name and parent fields to generate the id
  *
  * {@inheritDoc}
  */
 public function generate($document, ClassMetadata $class, DocumentManager $dm, $parent = null)
 {
     if (null === $parent) {
         $parent = $class->parentMapping ? $class->getFieldValue($document, $class->parentMapping) : null;
     }
     $name = $class->nodename ? $class->getFieldValue($document, $class->nodename) : null;
     $id = $class->getFieldValue($document, $class->identifier);
     if (empty($id)) {
         if (empty($name) && empty($parent)) {
             throw IdException::noIdentificationParameters($document, $class->parentMapping, $class->nodename);
         }
         if (empty($parent)) {
             throw IdException::noIdNoParent($document, $class->parentMapping);
         }
         if (empty($name)) {
             throw IdException::noIdNoName($document, $class->nodename);
         }
     }
     // use assigned ID by default
     if (empty($parent) || empty($name)) {
         return $id;
     }
     if ($exception = $class->isValidNodename($name)) {
         throw IdException::illegalName($document, $class->nodename, $name);
     }
     // determine ID based on the path and the node name
     return $this->buildName($document, $class, $dm, $parent, $name);
 }
All Usage Examples Of Doctrine\ODM\PHPCR\Mapping\ClassMetadata::isValidNodename
ClassMetadata