本文整理汇总了PHP中Sabre\VObject\Component::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Component::validate方法的具体用法?PHP Component::validate怎么用?PHP Component::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\VObject\Component
的用法示例。
在下文中一共展示了Component::validate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validates the node for correctness.
*
* The following options are supported:
* Node::REPAIR - May attempt to automatically repair the problem.
* Node::PROFILE_CARDDAV - validate the vCard for CardDAV purposes.
* Node::PROFILE_CALDAV - validate the iCalendar for CalDAV purposes.
*
* This method returns an array with detected problems.
* Every element has the following properties:
*
* * level - problem level.
* * message - A human-readable string describing the issue.
* * node - A reference to the problematic node.
*
* The level means:
* 1 - The issue was repaired (only happens if REPAIR was turned on).
* 2 - A warning.
* 3 - An error.
*
* @param int $options
* @return array
*/
function validate($options = 0)
{
$result = parent::validate($options);
if (isset($this->DTEND) && isset($this->DURATION)) {
$result[] = array('level' => 3, 'message' => 'DTEND and DURATION cannot both be present', 'node' => $this);
}
return $result;
}
示例2: validate
/**
* Validates the node for correctness.
*
* The following options are supported:
* Node::REPAIR - May attempt to automatically repair the problem.
* Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
* Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
*
* This method returns an array with detected problems.
* Every element has the following properties:
*
* * level - problem level.
* * message - A human-readable string describing the issue.
* * node - A reference to the problematic node.
*
* The level means:
* 1 - The issue was repaired (only happens if REPAIR was turned on).
* 2 - A warning.
* 3 - An error.
*
* @param int $options
*
* @return array
*/
function validate($options = 0)
{
$result = parent::validate($options);
if (isset($this->DTEND) && isset($this->DURATION)) {
$result[] = ['level' => 3, 'message' => 'DTEND and DURATION cannot both be present', 'node' => $this];
}
if (isset($this->DURATION) && !isset($this->DTSTART)) {
$result[] = ['level' => 3, 'message' => 'DURATION must be declared with a DTSTART.', 'node' => $this];
}
return $result;
}
示例3: validate
/**
* Validates the node for correctness.
*
* The following options are supported:
* - Node::REPAIR - If something is broken, and automatic repair may
* be attempted.
*
* An array is returned with warnings.
*
* Every item in the array has the following properties:
* * level - (number between 1 and 3 with severity information)
* * message - (human readable message)
* * node - (reference to the offending node)
*
* @param int $options
* @return array
*/
public function validate($options = 0)
{
$warnings = array();
$version = $this->select('VERSION');
if (count($version) !== 1) {
$warnings[] = array('level' => 1, 'message' => 'The VERSION property must appear in the VCARD component exactly 1 time', 'node' => $this);
if ($options & self::REPAIR) {
$this->VERSION = self::DEFAULT_VERSION;
}
} else {
$version = (string) $this->VERSION;
if ($version !== '2.1' && $version !== '3.0' && $version !== '4.0') {
$warnings[] = array('level' => 1, 'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.', 'node' => $this);
if ($options & self::REPAIR) {
$this->VERSION = '4.0';
}
}
}
$fn = $this->select('FN');
if (count($fn) !== 1) {
$warnings[] = array('level' => 1, 'message' => 'The FN property must appear in the VCARD component exactly 1 time', 'node' => $this);
if ($options & self::REPAIR && count($fn) === 0) {
// We're going to try to see if we can use the contents of the
// N property.
if (isset($this->N)) {
$value = explode(';', (string) $this->N);
if (isset($value[1]) && $value[1]) {
$this->FN = $value[1] . ' ' . $value[0];
} else {
$this->FN = $value[0];
}
// Otherwise, the ORG property may work
} elseif (isset($this->ORG)) {
$this->FN = (string) $this->ORG;
}
}
}
return array_merge(parent::validate($options), $warnings);
}
示例4: validate
/**
* Validates the node for correctness.
*
* The following options are supported:
* Node::REPAIR - May attempt to automatically repair the problem.
*
* This method returns an array with detected problems.
* Every element has the following properties:
*
* * level - problem level.
* * message - A human-readable string describing the issue.
* * node - A reference to the problematic node.
*
* The level means:
* 1 - The issue was repaired (only happens if REPAIR was turned on)
* 2 - An inconsequential issue
* 3 - A severe issue.
*
* @param int $options
* @return array
*/
public function validate($options = 0)
{
$result = parent::validate($options);
if (isset($this->DUE) && isset($this->DTSTART)) {
$due = $this->DUE;
$dtStart = $this->DTSTART;
if ($due->getValueType() !== $dtStart->getValueType()) {
$result[] = array('level' => 3, 'message' => 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART', 'node' => $due);
} elseif ($due->getDateTime() < $dtStart->getDateTime()) {
$result[] = array('level' => 3, 'message' => 'DUE must occur after DTSTART', 'node' => $due);
}
}
return $result;
}
示例5: repair
/**
* Repairs a VObject file
*
* @param Component $vObj
* @return int
*/
protected function repair($vObj)
{
$returnCode = 0;
switch ($vObj->name) {
case 'VCALENDAR':
$this->log("iCalendar: " . (string) $vObj->VERSION);
break;
case 'VCARD':
$this->log("vCard: " . (string) $vObj->VERSION);
break;
}
$warnings = $vObj->validate(Node::REPAIR);
if (!count($warnings)) {
$this->log(" No warnings!");
} else {
$levels = [1 => 'REPAIRED', 2 => 'WARNING', 3 => 'ERROR'];
$returnCode = 2;
foreach ($warnings as $warn) {
$extra = '';
if ($warn['node'] instanceof Property) {
$extra = ' (property: "' . $warn['node']->name . '")';
}
$this->log(" [" . $levels[$warn['level']] . '] ' . $warn['message'] . $extra);
}
}
fwrite($this->stdout, $vObj->serialize());
return $returnCode;
}
示例6: repair
/**
* Repairs a VObject file
*
* @param Component $vObj
* @return int
*/
protected function repair($vObj)
{
$returnCode = 0;
switch ($vObj->name) {
case 'VCALENDAR':
$this->log("iCalendar: " . (string) $vObj->VERSION);
break;
case 'VCARD':
$this->log("vCard: " . (string) $vObj->VERSION);
break;
}
$warnings = $vObj->validate(Node::REPAIR);
if (!count($warnings)) {
$this->log(" No warnings!");
} else {
foreach ($warnings as $warn) {
$returnCode = 2;
$this->log(" " . $warn['message']);
}
}
fwrite($this->stdout, $vObj->serialize());
return $returnCode;
}