/**
  * Parse attribute key recursively
  *
  * @param array        $parsedFields Reference to array of parsed fields
  * @param StringObject $key Current key to parse
  */
 private function buildFields(&$parsedFields, StringObject $key)
 {
     if ($key->contains('.')) {
         $parts = $key->explode('.', 2)->val();
         if (!isset($parsedFields[$parts[0]])) {
             $parsedFields[$parts[0]] = [];
         }
         $this->buildFields($parsedFields[$parts[0]], $this->str($parts[1]));
     } else {
         $parsedFields[$key->val()] = '';
     }
 }
Exemple #2
0
 private function validateSection(StringObject $section)
 {
     $tmp = $section->explode($this->delimiter);
     if ($tmp->first()->contains('-') || $this->isNumber($tmp->first()->val())) {
         throw new ConfigException(sprintf('Invalid config key "%s"', $section->val()));
     }
 }
 /**
  * Set url path.
  *
  * @param StringObject|string $path Url path.
  *
  * @throws UrlObjectException
  * @return $this
  */
 public function setPath($path)
 {
     try {
         $path = new StringObject($path);
     } catch (\Exception $e) {
         throw new UrlObjectException($e->getMessage());
     }
     if ($path != '') {
         $path->trimLeft('/');
         $this->path = '/' . $path->val();
     } else {
         $this->path = $path->val();
     }
     $this->rebuildUrl();
     return $this;
 }
 public function testTruncate2()
 {
     $s = new StringObject('A very long word.');
     $s->truncate(10, '...');
     $this->assertSame('A very...', $s->val());
 }