File_IMC
[ class tree: File_IMC ] [ index: File_IMC ] [ all elements ]

Class: File_IMC_Build

Source Location: /File_IMC-0.3/File/IMC/Build.php

Class Overview


This class helps build files in the vCard and vCalendar formats.


Author(s):

Variables

Methods


Child classes:

File_IMC_Build_vCard
This class helps build files in the vCard and vCalendar formats.

Inherited Variables

Inherited Methods


Class Details

[line 41]
This class helps build files in the vCard and vCalendar formats.

General note: we use the terms "set" "add" and "get" as function prefixes.

"Set" means there is only one iteration of a component, and it has only one value repetition, so you set the whole thing at once.

"Add" means eith multiple iterations of a component are allowed, or that there is only one iteration allowed but there can be multiple value repetitions, so you add iterations or repetitions to the current stack.

"Get" returns the full vCard line for a single iteration.



[ Top ]


Class Variables

$autoparam =  null

[line 65]

Tracks which component (N, ADR, TEL, etc) value was last set or added.

Used when adding parameters automatically to the proper component.


Type:   string


[ Top ]

$param = array()

[line 57]

Parameters for vCard components.
  • Access: public

Type:   array


[ Top ]

$value = array()

[line 49]

Values for vCard components.
  • Access: public

Type:   array


[ Top ]



Method Detail

addParam   [line 222]

mixed addParam( string $param_name, string $param_value, [string $comp = null], [mixed $iter = null])

Adds a parameter value for a given component and parameter name.

Note that although vCard 2.1 and vCalendar allow you to specify a parameter value without a name (e.g., "HOME" instead of "TYPE=HOME") this class is not so lenient. ;-) You must specify a parameter name (TYPE, ENCODING, etc) when adding a parameter. Call multiple times if you want to add multiple values to the same parameter. E.g.:

$vcard = File_IMC::build('vCard');

// set "TYPE=HOME,PREF" for the first TEL component $vcard->addParam('TYPE', 'HOME', 'TEL', 0); $vcard->addParam('TYPE', 'PREF', 'TEL', 0);

  • Return: Void on success, or a PEAR_Error object on failure.
  • Access: public

Parameters:

string   $param_name     The parameter name, such as TYPE, VALUE, or ENCODING.
string   $param_value     The parameter value.
string   $comp     The vCard component for which this is a paramter (ADR, TEL, etc). If null, will be the component that was last set or added-to.
mixed   $iter     An integer vCard component iteration that this is a param for. E.g., if you have more than one ADR component, 0 refers to the first ADR, 1 to the second ADR, and so on. If null, the parameter will be added to the last component iteration available.

[ Top ]

addValue   [line 349]

void addValue( string $comp, int $iter, int $part, mixed $text)

Generic, all-purpose method to add a repetition of a string or array in $this->value, in a way suitable for later output as a vCard element. This appends the value to be the passed text or array value, leaving any prior values in place.
  • Access: public

Parameters:

string   $comp     The component to set the value for ('N', 'ADR', etc).
int   $iter     The component-iteration to set the value for.
int   $part     The part number of the component-iteration to set the value for.
mixed   $text     A string or array; the set of repeated values for this component-iteration part.

[ Top ]

escape   [line 158]

mixed escape( mixed &$text)

Prepares a string so it may be safely used as vCard values. DO NOT use this with binary encodings. Operates on text in-place; does not return a value. Recursively descends into arrays.

Escapes a string so that... ; => \; , => \, newline => literal \n

  • Return: Void on success, or a PEAR_Error object on failure.
  • Access: public

Parameters:

mixed   $text     The string or array or strings to escape.

[ Top ]

fetch   [line 521]

string fetch( )

Fetches a full vCard/vCal text block based on $this->value and $this->param.
  • Return: A properly formatted vCard/vCalendar text block.
  • Access: public

Overridden in child classes as:

File_IMC_Build_vCard::fetch()
Fetches a full vCard text block based on $this->value and

[ Top ]

File_IMC_Build_vCard   [line 77]

void File_IMC_Build_vCard( [string $version = '3.0'])

Constructor

Parameters:

string   $version     The vCard version to build; affects which parameters are allowed and which components are returned by fetch().

[ Top ]

getMeta   [line 293]

string getMeta( string $comp, [int $iter = 0])

Gets the left-side/prefix/before-the-colon (metadata) part of a vCard line, including the component identifier, the parameter list, and a colon.
  • Return: The line prefix metadata.
  • Access: public

Parameters:

string   $comp     The component to get metadata for (ADR, TEL, etc).
int   $iter     The vCard component iteration to get the metadata for. E.g., if you have more than one ADR component,
  1. refers to the first ADR, 1 to the second ADR, and
so on.

[ Top ]

getParam   [line 412]

string getParam( string $comp, [int $iter = 0])

Gets back the parameter string for a given component.
  • Access: public

Parameters:

string   $comp     The component to get parameters for (ADR, TEL, etc).
int   $iter     The vCard component iteration to get the param list for. E.g., if you have more than one ADR component, 0 refers to the first ADR, 1 to the second ADR, and so on.

[ Top ]

getValue   [line 376]

string getValue( string $comp, [int $iter = 0], [int $part = 0], [mixed $rept = null])

Generic, all-purpose method to get back the data stored in $this->value.
  • Return: The value, escaped and delimited, of all repetitions in the component-iteration part (or specific repetition within the part).
  • Access: public

Parameters:

string   $comp     The component to set the value for ('N', 'ADR', etc).
int   $iter     The component-iteration to set the value for.
int   $part     The part number of the component-iteration to get the value for.
mixed   $rept     The repetition number within the part to get; if null, get all repetitions of the part within the iteration.

[ Top ]

getVersion   [line 137]

string getVersion( )

Gets back the version of the the vCard. Only one iteration.
  • Return: The data-source of the vCard.
  • Access: public

[ Top ]

raiseError   [line 526]

void raiseError( mixed $msg, mixed $code)


[ Top ]

reset   [line 92]

void reset( [string $version = null])

Resets the vCard values and params to be blank.
  • Access: public

Parameters:

string   $version     The vCard version to reset to ('2.1' or '3.0' -- default is the same version as previously set).

[ Top ]

setFromArray   [line 473]

void setFromArray( array $src)

Builds a vCard/vCal from a parser result array. Only send one vCard from the parse-results.

Usage (to build from first vCard in parsed results):

$parse = File_IMC::parse('vCard'); // new parser $info = $parse->fromFile('sample.vcf'); // parse file

$vcard = File_IMC::build('vCard'); // new builder $vcard->setFromArray($info[0]); // [0] is the first card


Parameters:

array   $src     One vCard entry as parsed using File_IMC::parse()

[ Top ]

setValue   [line 324]

void setValue( string $comp, int $iter, int $part, mixed $text)

Generic, all-purpose method to store a string or array in $this->value, in a way suitable for later output as a vCard element. This forces the value to be the passed text or array value, overriding any prior values.
  • Access: public

Parameters:

string   $comp     The component to set the value for ('N', 'ADR', etc).
int   $iter     The component-iteration to set the value for.
int   $part     The part number of the component-iteration to set the value for.
mixed   $text     A string or array; the set of repeated values for this component-iteration part.

[ Top ]

setVersion   [line 118]

mixed setVersion( string $text)

Sets the version of the specification to use. Only one iteration.

Overload this function in the driver to validate and set the version

  • Return: Void on success, or a PEAR_Error object on failure.
  • Abstract:
  • Access: public

Overridden in child classes as:

File_IMC_Build_vCard::setVersion()
Sets the version of the the vCard. Only one iteration.

Parameters:

string   $text     The text value of the verson text (e.g. '3.0' or '2.1').

[ Top ]

validateParam   [line 274]

mixed validateParam( string $name, string $text, [string $comp = null], [string $iter = null])

Validates parameter names and values
  • Return: Boolean true if the parameter is valid, or a PEAR_Error object if not.
  • Abstract:
  • Access: public

Overridden in child classes as:

File_IMC_Build_vCard::validateParam()
Validates parameter names and values based on the vCard version (2.1 or 3.0).

Parameters:

string   $name     The parameter name (e.g., TYPE or ENCODING).
string   $text     The parameter value (e.g., HOME or BASE64).
string   $comp     Optional, the component name (e.g., ADR or PHOTO). Only used for error messaging.
string   $iter     Optional, the iteration of the component. Only used for error messaging.

[ Top ]


Documentation generated on Sat, 1 May 2004 00:42:13 +0200 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.