/** * Check if this node name is valid. Returns null if valid, an exception otherwise. * * @param string $nodeName The node local name * * @return 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; }
/** * @dataProvider dataproviderInvalidLocalNames * @expectedException \PHPCR\RepositoryException */ public function testAssertInvalidLocalName($name) { PathHelper::assertValidLocalName($name); }
private function validateWorkspaceName($name) { $res = PathHelper::assertValidLocalName($name); if (!$res) { throw new RepositoryException(sprintf('Invalid workspace name "%s"', $name)); } }
/** * Minimal check according to the jcr spec to see if this node name * conforms to the specification * * If it can't be avoided, extending transports may overwrite this method to add * additional checks. But this will reduce interchangeability, thus it is better to * properly encode and decode characters that are not natively allowed by the storage. * * @param string $name The name to check * * @return boolean always true, if the name is not valid a RepositoryException is thrown * * @see http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.2.2%20Local%20Names * * @throws RepositoryException if the name contains invalid characters */ public function assertValidName($name) { return PathHelper::assertValidLocalName($name); }