protected function setMediaTypeFromLine(VCardLine $line)
 {
     if ($line->hasParameter('mediatype')) {
         $mediaTypes = $line->getParameter('mediatype');
         if (count($mediaTypes) > 1) {
             throw new Exceptions\MalformedParameterException('Multiple MEDIATYPE parameters supplied for ' . $this->getName());
         } else {
             $this->setMediaType($mediaTypes[0]);
         }
     }
 }
 protected function setFieldsFromLine(VCardLine $line)
 {
     /* @var $fields array */
     $fields = $this->fields();
     /* @var $fieldStrs array */
     $fieldStrs = \preg_split(VCardLine::SEMICOLON_SPLIT, $line->getValue());
     if (\count($fieldStrs) > \count($fields)) {
         throw new \DomainException('Field count, ' . \count($fieldStrs) . 'is greater than the number of fields defined (' . \count($fields) . ') for property ' . $this->getName() . " : " . $line->getValue());
     }
     foreach ($fieldStrs as $index => $value) {
         if (0 !== \strlen($value)) {
             $this->setField($fields[$index], \stripcslashes(\trim($value)));
         }
     }
 }
 /**
  * @group default
  * @param \EVought\vCardTools\PropertySpecification $specification
  * @depends testSetAndBuild
  */
 public function testSetFromVCardLineNoTypes(PropertySpecification $specification)
 {
     $vcardLine = new VCardLine('4.0');
     $vcardLine->setName('tel')->setValue('+1-888-GET-PAID');
     /* @var PropertyBuilder $builder */
     $builder = $specification->getBuilder();
     $builder->setFromVCardLine($vcardLine);
     $this->assertEquals('+1-888-GET-PAID', $builder->getValue());
     $this->assertEmpty($builder->getTypes());
 }
예제 #4
0
 protected function setBuilderFromLine(VCardLine $vcardLine)
 {
     \assert($this->getName() === $vcardLine->getName());
     $this->group = empty($vcardLine->getGroup()) ? null : $vcardLine->getGroup();
     if ($vcardLine->hasParameter('pref')) {
         if (!$this->getSpecification()->isCardinalityToN()) {
             throw new \DomainException('PREF not allowed for *1 or 1 cardinality: ' . $this->getName());
         }
         $prefs = $vcardLine->getParameter('pref');
         if (count($prefs) > 1) {
             throw new Exceptions\MalformedParameterException('Multiple PREF parameters provided for : ' . $this->getName());
         } else {
             $this->pref = $prefs[0];
         }
     }
     if ($vcardLine->hasParameter('value')) {
         $valueTypes = $vcardLine->getParameter('value');
         if (count($valueTypes) != 1) {
             throw new Exceptions\MalformedParameterException('Muliple VALUE parameters provided for : ' . $this->getName());
         }
         $this->setValueType($valueTypes[0]);
     }
     return $this;
 }
 /**
  * @group default
  * @depends testSetAndBuild
  * @expectedException EVought\vCardTools\Exceptions\MalformedParameterException
  * @expectedExceptionMessage jpeg
  */
 public function testSetFromVCardLineBadMediaType()
 {
     $url = 'https://www.example.com/foo.jpg';
     $vcardLine = new VCardLine('4.0');
     $vcardLine->setName('logo')->setValue($url)->setParameter('mediatype', ['jpeg']);
     $builder = $this->specification->getBuilder();
     $builder->setFromVCardLine($vcardLine);
 }
 /**
  * @group default
  * @param \EVought\vCardTools\PropertySpecification $specification
  * @depends testSetFromVCardLine
  */
 public function testSetFromVCardLineValueType(PropertySpecification $specification)
 {
     $vcardLine = new VCardLine('4.0');
     $vcardLine->setName('url')->setValue('http://abc.es')->pushParameter('value', 'uri');
     $builder = $specification->getBuilder();
     $builder->setFromVCardLine($vcardLine);
     $this->assertEquals('uri', $builder->getValueType());
     $this->assertEquals('http://abc.es', $builder->getValue());
 }
예제 #7
0
 /**
  * Parses a vcard from the output of getCardBpdy (or from an iteration
  * over getCardBodies) and returns the resulting VCard instance.
  * This method is exposed primarily for diagnostic and testing purpose to
  * help identify problems in failed vcards. *Do not depend on its API.*
  * Use importCards() and importFromFile() instead.
  * @param type $components
  * @return \EVought\vCardTools\VCard
  * @throws Exceptions\UndefinedPropertyException
  * @see importCards()
  * @see importFromFile()
  */
 public function parseCardBody($components)
 {
     $vcard = new VCard();
     if ('2.1' === $components['version']) {
         $unfoldedData = self::unfold21($components['body']);
     } else {
         $unfoldedData = self::unfold4($components['body']);
     }
     $lines = \explode("\n", $unfoldedData);
     foreach ($lines as $line) {
         // FIXME: Make sure that TYPE, ENCODING, CHARSET are dealt
         // with by PropertyBuilder
         $vcardLine = VCardLine::fromLineText($line, $components['version']);
         if (null === $vcardLine) {
             continue;
         }
         $specification = VCard::getSpecification($vcardLine->getName(), false);
         if ($specification->allowsCommaProperties()) {
             // Deal with the possibility of multiple values
             $origValue = $vcardLine->getValue();
             $values = \str_getcsv($origValue);
             foreach ($values as $value) {
                 $vcardLine->setValue($value);
                 $specification->getBuilder()->setFromVCardLine($vcardLine)->pushTo($vcard);
             }
         } else {
             $specification->getBuilder()->setFromVCardLine($vcardLine)->pushTo($vcard);
         }
     }
     $vcard->checkSetUID();
     return $vcard;
 }
 protected function setTypesFromLine(VCardLine $line)
 {
     if (!empty($line->getParameter('type'))) {
         $this->setTypes($line->getParameter('type'));
     }
 }
 /**
  * @group default
  * @param \EVought\vCardTools\PropertySpecification $specification
  * @depends testSetAndBuild
  * @expectedException \DomainException
  */
 public function testSetFromVCardLineTooManyFields(PropertySpecification $specification)
 {
     $vcardLine = new VCardLine('4.0');
     $vcardLine->setName('adr')->setValue(';;;;;');
     /* @var StructuredPropertyBuilder $builder */
     $builder = $specification->getBuilder();
     $builder->setFromVCardLine($vcardLine);
 }
 /**
  * This method will extract the value component from a pre-parsed line of
  * raw VCard text.
  * @param \EVought\vCardTools\VCardLine $line A line of raw VCard text
  * which has already been parsed into its component structures.
  * @return SimpleProperty $this
  */
 protected function setValueFromLine(VCardLine $line)
 {
     $this->value = \stripcslashes($line->getValue());
     return $this;
 }
 /**
  * @group default
  * @param \EVought\vCardTools\PropertySpecification $specification
  * @depends testSetAndBuild
  */
 public function testSetFromVCardLine(PropertySpecification $specification)
 {
     $vcardLine = new VCardLine('4.0');
     $vcardLine->setGroup('glurg')->setName('adr')->setValue('value1;value2')->setParameter('type', ['work']);
     $builder = $specification->getBuilder();
     $builder->setFromVCardLine($vcardLine);
     $this->assertEquals('glurg', $builder->getGroup());
     $this->assertEquals(['work'], $builder->getTypes());
     $this->assertEquals(['Locality' => 'value1', 'Region' => 'value2'], $builder->getValue());
 }