コード例 #1
1
ファイル: TemplateTest.php プロジェクト: evought/vcard-tools
 /**
  * @group default
  * @depends testQuestFNYes
  */
 public function testQuestUndefinedYes()
 {
     $fragments = ['vcard' => '{{output,?x-undefined}}', 'output' => 'Output'];
     $template = new Template($fragments);
     $vcard = new vCard();
     VCard::builder('x-undefined', false)->setValue('test')->pushTo($vcard);
     $output = $template->output($vcard);
     $this->assertEquals('Output', $output);
 }
コード例 #2
0
ファイル: VCardDB.php プロジェクト: evought/vcard-tools
 /**
  * Fetches all records for generic, x-tended properties for which we have
  * no detailed specification.
  * @param string $uid The contact uid records are associated with.
  * Numeric, not null.
  * @return NULL|Property[] Returns an array of associated records, or null
  * if none found.
  */
 private function fetchXtendedProperties($uid)
 {
     assert(isset($this->connection));
     assert(!empty($uid));
     assert(is_string($uid));
     // Fetch each property record in turn
     $stmt = $this->prepareCannedQuery('fetch', 'xtended');
     $stmt->bindValue(':id', $uid);
     $stmt->execute();
     /** @var Property[] */
     $properties = [];
     while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $builder = VCard::builder($result['name'], false);
         $builder->setValue($result['value']);
         // FIXME: Need to store this.
         $propertyID = $result['pid'];
         if (null !== $result['pref']) {
             $builder->setPref($result['pref']);
         }
         if (null !== $result['mediatype']) {
             $builder->setMediaType($result['mediatype']);
         }
         if (null !== $result['valuetype']) {
             $builder->setValueType($result['valuetype']);
         }
         if (null !== $result['propGroup']) {
             $builder->setGroup($result['propGroup']);
         }
         $this->fetchTypesForPropertyID($builder, $propertyID, 'xtended');
         $properties[] = $builder->build();
     }
     $stmt->closeCursor();
     return empty($properties) ? null : $properties;
 }
コード例 #3
0
ファイル: VCardParser.php プロジェクト: evought/vcard-tools
 /**
  * If $vcard has a legacy AGENT property, convert it to a VCard 4.0
  * RELATED property.
  * @param VCard $vcard The card to look for an AGENT in.
  * @return VCard|null If a new VCard was extracted and created, it is
  * returned, otherwise null. Even if there is an AGENT in the card, it
  * may be a text or uri value, in which case no new VCard is created.
  * @throws \DomainException If the AGENT is supposed to contain an
  * embedded card, but we cannot parse it.
  */
 protected function handleAgent(VCard $vcard)
 {
     if (isset($vcard->agent)) {
         /* @var $agent Property */
         $agent = $vcard->agent;
         /* @var $relatedBld TypedPropertyBuilder */
         $relatedBld = VCard::builder('related')->addType('agent');
         if ($agent->getValueType() === 'vcard') {
             $agentText = $agent->getValue();
             $components = $this->getCardBody(\stripcslashes($agentText), self::$agentBodyRegExp);
             // Embedded AGENT VCards might not have VERSION but they only
             // existed in 3.0.
             $components['version'] = '3.0';
             $agentCard = $this->parseCardBody($components);
             $relatedBld->setValueType('uri')->setValue($agentCard->getUID())->pushTo($vcard);
             $this->vcards[$agentCard->getUID()] = $agentCard;
             return $vcard;
         } else {
             $relatedBld->setValue($agent->getValue())->setValueType($agent->getValueType())->pushTo($vcard);
             return null;
         }
     }
 }
コード例 #4
0
 /**
  * @group default
  * @depends testImportVCardOneURL
  */
 public function testImportVCardTwoURLs()
 {
     $url1 = "tweedldee";
     $url2 = "tweedledum";
     $input = self::$vcard_begin . "\r\n" . self::$vcard_version . "\r\n" . "URL:" . $url1 . "\r\n" . "URL:" . $url2 . "\r\n" . self::$vcard_end . "\r\n";
     $vcards = $this->parser->importCards($input);
     $builder = VCard::builder('url');
     $prop1 = $builder->setValue($url1)->build();
     $prop2 = $builder->setValue($url2)->build();
     $this->assertCount(1, $vcards);
     $this->assertCount(2, $vcards[0]->url);
     $this->assertEquals([$prop1, $prop2], $vcards[0]->url);
 }