예제 #1
0
 /**
  * @group default
  */
 public function testFromTextIterates()
 {
     $substitution = Substitution::fromText('key, #n');
     $this->assertInstanceOf('EVought\\vCardTools\\Substitution', $substitution);
     $this->assertTrue($substitution->hasFragment());
     $this->assertEquals('key', $substitution->getFragment());
     $this->assertFalse($substitution->hasQuest());
     $this->assertFalse($substitution->shouldLookUp());
     $this->assertTrue($substitution->iterates());
     $this->assertEquals('n', $substitution->getIterOver());
 }
예제 #2
0
 /**
  * Process and return the requested fragment, making further substitutions
  * as necessary.
  * @param VCard $vcard The card to look up values in. Not null.
  * @param string $fragmentKey The key to the fragment to output, not null.
  * @param string $iterOver The name of any property being iterated over,
  * or null.
  * @param string $iterItem The current value of any property being iterated
  * over, or null.
  * @return string
  */
 private function i_processFragment(VCard $vcard, $fragmentKey, $iterOver = null, $iterItem = null)
 {
     assert(null !== $vcard);
     assert(null !== $fragmentKey);
     assert(is_string($fragmentKey));
     $fragment = $this->i_findFragment($fragmentKey);
     $value = '';
     if (null !== $fragment) {
         $low = 0;
         while (($high = strpos($fragment, '{{', $low)) !== false) {
             // Strip and output until we hit a template marker
             $value .= substr($fragment, $low, $high - $low);
             // strip the front marker
             $low = $high + 2;
             $high = strpos($fragment, '}}', $low);
             // Remove and process the new marker
             $newSubstitution = Substitution::fromText(substr($fragment, $low, $high - $low));
             $high += 2;
             $low = $high;
             $value .= self::i_processSubstitution($vcard, $newSubstitution, $iterOver, $iterItem);
         }
         $value .= substr($fragment, $low);
     }
     // if fragment
     return $value;
 }