normalizeString() public static méthode

If the result of that removal is an empty string, the default value is returned.
public static normalizeString ( string $string, string $default = '_' ) : string
$string string
$default string
Résultat string
Exemple #1
0
 /**
  * @param \DOMNode|Element $node
  * @param \DOMNode|Document|Element $target
  */
 private function transferNode(\DOMNode $node, \DOMNode $target)
 {
     if ($node->namespaceURI === self::XMLNS_JSONX) {
         if ($target instanceof Document) {
             $normalizedName = $name = 'json:json';
         } else {
             $name = $node->getAttribute('name');
             $normalizedName = QualifiedName::normalizeString($name, self::DEFAULT_QNAME);
         }
         $type = $node->localName;
         $newNode = $target->appendElement($normalizedName);
         if ($name !== $normalizedName && $name !== '') {
             $newNode->setAttribute('json:name', $name);
         }
         switch ($type) {
             case 'object':
                 if ($node('count(*) > 0')) {
                     foreach ($node('*') as $childNode) {
                         $this->transferNode($childNode, $newNode);
                     }
                     return;
                 }
                 break;
             case 'array':
                 foreach ($node('*') as $childNode) {
                     $this->transferNode($childNode, $newNode);
                 }
                 break;
             case 'string':
                 $newNode->append((string) $node);
                 return;
             default:
                 $newNode->append((string) $node);
                 break;
         }
         $newNode->setAttribute('json:type', $type);
     }
 }
Exemple #2
0
 /**
  * @param Element $parent
  * @param string $name
  * @param string $value
  */
 private function appendField(Element $parent, $name, $value)
 {
     $qname = QualifiedName::normalizeString($name, self::DEFAULT_QNAME);
     $child = $parent->appendElement($qname, $value);
     if ($qname !== $name) {
         $child->setAttributeNS(self::XMLNS, 'json:name', $name);
     }
 }
Exemple #3
0
 /**
  * Get a valid qualified name (tag name) using the property name/key.
  *
  * @param string $key
  * @param string $default
  * @param bool $isArrayElement
  * @return string
  */
 private function getQualifiedName($key, $default, $isArrayElement = FALSE)
 {
     if ($callback = $this->onMapKey()) {
         $key = $callback($key, $isArrayElement);
     } elseif ($isArrayElement) {
         $key = $default;
     }
     return QualifiedName::normalizeString($key, self::DEFAULT_QNAME);
 }