This is the CLI interface for sabre-vobject.
More...
This is the CLI interface for sabre-vobject.
- Copyright
- Copyright (C) fruux GmbH (https://fruux.com/)
- Author
- Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License
Definition at line 15 of file Cli.php.
◆ color()
Sabre\VObject\Cli::color |
( |
|
$vObj | ) |
|
|
protected |
◆ colorize()
Sabre\VObject\Cli::colorize |
( |
|
$color, |
|
|
|
$str, |
|
|
|
$resetTo = 'default' |
|
) |
| |
|
protected |
◆ convert()
Sabre\VObject\Cli::convert |
( |
|
$vObj | ) |
|
|
protected |
Converts a vObject file to a new format.
- Parameters
-
- Returns
- int
Definition at line 427 of file Cli.php.
References Sabre\VObject\Document\VCARD21, Sabre\VObject\Document\VCARD30, and Sabre\VObject\Document\VCARD40.
430 $convertVersion = null;
433 switch ($this->format) {
436 if ($vObj->name ===
'VCARD') {
442 $forceInput =
'VCARD';
447 $forceInput =
'VCALENDAR';
466 if ($forceInput && $vObj->name !== $forceInput) {
467 throw new \Exception(
'You cannot convert a ' . strtolower($vObj->name) .
' to ' . $this->format);
469 if ($convertVersion) {
470 $vObj = $vObj->convert($convertVersion);
475 $jsonOptions = JSON_PRETTY_PRINT;
477 fwrite($this->stdout, json_encode($vObj->jsonSerialize(), $jsonOptions));
479 fwrite($this->stdout, $vObj->serialize());
◆ cWrite()
Sabre\VObject\Cli::cWrite |
( |
|
$color, |
|
|
|
$str |
|
) |
| |
|
protected |
◆ log()
Sabre\VObject\Cli::log |
( |
|
$msg, |
|
|
|
$color = 'default' |
|
) |
| |
|
protected |
◆ main()
Sabre\VObject\Cli::main |
( |
array |
$argv | ) |
|
Main function.
- Returns
- int
Definition at line 99 of file Cli.php.
References Sabre\VObject\$input, $name, PHPMailer\PHPMailer\$options, Sabre\VObject\Cli\colorize(), Sabre\VObject\Cli\log(), Sabre\VObject\Cli\parseArguments(), Sabre\VObject\Cli\readInput(), Sabre\VObject\Cli\showHelp(), and Sabre\VObject\Version\VERSION.
104 if (!$this->stderr) {
105 $this->stderr =
fopen(
'php://stderr',
'w');
107 if (!$this->stdout) {
108 $this->stdout =
fopen(
'php://stdout',
'w');
111 $this->stdin =
fopen(
'php://stdin',
'r');
158 $this->format = $value;
167 if (version_compare(PHP_VERSION,
'5.4.0') >= 0) {
168 $this->pretty =
true;
172 $this->forgiving =
true;
180 $this->inputFormat =
'json';
192 $this->inputFormat =
'mimedir';
207 if (count($positional) === 0) {
212 if (count($positional) === 1) {
216 if (count($positional) > 3) {
220 if (!in_array($positional[0], [
'validate',
'repair',
'convert',
'color'])) {
226 $this->
log(
'Error: ' . $e->getMessage(),
'red');
230 $command = $positional[0];
232 $this->inputPath = $positional[1];
233 $this->outputPath = isset($positional[2]) ? $positional[2] :
'-';
235 if ($this->outputPath !==
'-') {
236 $this->stdout =
fopen($this->outputPath,
'w');
239 if (!$this->inputFormat) {
240 if (substr($this->inputPath, -5) ===
'.json') {
241 $this->inputFormat =
'json';
243 $this->inputFormat =
'mimedir';
246 if (!$this->format) {
247 if (substr($this->outputPath, -5) ===
'.json') {
248 $this->format =
'json';
250 $this->format =
'mimedir';
261 $returnCode = $this->$command(
$input);
262 if ($returnCode !== 0) $realCode = $returnCode;
266 }
catch (EofException $e) {
269 $this->
log(
'Error: ' . $e->getMessage(),
'red');
colorize($color, $str, $resetTo='default')
Returns an ansi color string for a color name.
readInput()
Reads the input file.
const VERSION
Full version number.
parseArguments(array $argv)
Parses the list of arguments.
log($msg, $color='default')
Sends a message to STDERR.
showHelp()
Shows the help message.
◆ parseArguments()
Sabre\VObject\Cli::parseArguments |
( |
array |
$argv | ) |
|
|
protected |
Parses the list of arguments.
- Parameters
-
- Returns
- void
Definition at line 690 of file Cli.php.
References $ii, and PHPMailer\PHPMailer\$options.
Referenced by Sabre\VObject\Cli\main().
698 if (
$ii === 0)
continue;
702 if (substr($v, 0, 2) ===
'--') {
704 $optionName = substr($v, 2);
706 if (strpos($optionName,
'=')) {
707 list($optionName, $optionValue) = explode(
'=', $optionName);
709 $options[$optionName] = $optionValue;
710 } elseif (substr($v, 0, 1) ===
'-' && strlen($v) > 1) {
712 foreach (str_split(substr($v, 1)) as $option) {
◆ readInput()
Sabre\VObject\Cli::readInput |
( |
| ) |
|
|
protected |
Reads the input file.
- Returns
- Component
Definition at line 735 of file Cli.php.
References Sabre\VObject\Reader\OPTION_FORGIVING.
Referenced by Sabre\VObject\Cli\main().
737 if (!$this->parser) {
738 if ($this->inputPath !==
'-') {
739 $this->stdin =
fopen($this->inputPath,
'r');
742 if ($this->inputFormat ===
'mimedir') {
749 return $this->parser->parse();
const OPTION_FORGIVING
If this option is passed to the reader, it will be less strict about the validity of the lines...
◆ repair()
◆ serializeComponent()
Sabre\VObject\Cli::serializeComponent |
( |
Component |
$vObj | ) |
|
|
protected |
Gives a component a 'score' for sorting purposes.
This is solely used by the childrenSort method.
A higher score means the item will be lower in the list. To avoid score collisions, each "score category" has a reasonable space to accomodate elements. The $key is added to the $score to preserve the original relative order of elements.
- Parameters
-
- Returns
- int
Definition at line 535 of file Cli.php.
References $key, Sabre\VObject\Component\children(), Sabre\VObject\Cli\cWrite(), and Sabre\VObject\Cli\serializeProperty().
Referenced by Sabre\VObject\Cli\color().
537 $this->
cWrite(
'cyan',
'BEGIN');
538 $this->
cWrite(
'red',
':');
539 $this->
cWrite(
'yellow', $vObj->name .
"\n");
556 $sortScore =
function(
$key, $array) {
562 if ($array[
$key]->name ===
'VTIMEZONE') {
564 return $score +
$key;
567 return $score +
$key;
572 if ($array[
$key] instanceof Property) {
573 if ($array[
$key]->name ===
'VERSION') {
575 return $score +
$key;
579 return $score +
$key;
586 $children = $vObj->children();
590 function($a, $b) use ($sortScore, $tmp) {
592 $sA = $sortScore($a, $tmp);
593 $sB = $sortScore($b, $tmp);
600 foreach ($children as $child) {
601 if ($child instanceof Component) {
608 $this->
cWrite(
'cyan',
'END');
609 $this->
cWrite(
'red',
':');
610 $this->
cWrite(
'yellow', $vObj->name .
"\n");
cWrite($color, $str)
Writes out a string in specific color.
serializeComponent(Component $vObj)
serializeProperty(Property $property)
Colorizes a property.
◆ serializeProperty()
Sabre\VObject\Cli::serializeProperty |
( |
Property |
$property | ) |
|
|
protected |
Colorizes a property.
- Parameters
-
- Returns
- void
Definition at line 621 of file Cli.php.
References Sabre\VObject\Cli\colorize(), Sabre\VObject\Cli\cWrite(), Sabre\VObject\Property\getParts(), Sabre\VObject\Property\getValue(), and Sabre\VObject\Property\parameters().
Referenced by Sabre\VObject\Cli\serializeComponent().
623 if ($property->group) {
624 $this->
cWrite(
'default', $property->group);
625 $this->
cWrite(
'red',
'.');
628 $this->
cWrite(
'yellow', $property->name);
630 foreach ($property->parameters as $param) {
632 $this->
cWrite(
'red',
';');
633 $this->
cWrite(
'blue', $param->serialize());
636 $this->
cWrite(
'red',
':');
638 if ($property instanceof Property\Binary) {
640 $this->
cWrite(
'default',
'embedded binary stripped. (' . strlen($property->getValue()) .
' bytes)');
644 $parts = $property->getParts();
647 foreach ($parts as $part) {
651 $this->
cWrite(
'red', $property->delimiter);
655 foreach ((array)$part as $subPart) {
660 $this->
cWrite(
'red',
',');
666 '\\' => $this->
colorize(
'purple',
'\\\\',
'green'),
667 ';' => $this->
colorize(
'purple',
'\;',
'green'),
668 ',' => $this->
colorize(
'purple',
'\,',
'green'),
669 "\n" => $this->
colorize(
'purple',
"\\n\n\t",
'green'),
674 $this->
cWrite(
'green', $subPart);
679 $this->
cWrite(
"default",
"\n");
colorize($color, $str, $resetTo='default')
Returns an ansi color string for a color name.
cWrite($color, $str)
Writes out a string in specific color.
◆ showHelp()
Sabre\VObject\Cli::showHelp |
( |
| ) |
|
|
protected |
Shows the help message.
- Returns
- void
Definition at line 282 of file Cli.php.
References Sabre\VObject\Cli\colorize(), and Sabre\VObject\Cli\log().
Referenced by Sabre\VObject\Cli\main().
284 $this->
log(
'Usage:',
'yellow');
285 $this->
log(
" vobject [options] command [arguments]");
287 $this->
log(
'Options:',
'yellow');
288 $this->
log($this->
colorize(
'green',
' -q ') .
"Don't output anything.");
289 $this->
log($this->
colorize(
'green',
' -help -h ') .
"Display this help message.");
290 $this->
log($this->
colorize(
'green',
' --format ') .
"Convert to a specific format. Must be one of: vcard, vcard21,");
291 $this->
log($this->
colorize(
'green',
' --forgiving ') .
"Makes the parser less strict.");
292 $this->
log(
" vcard30, vcard40, icalendar20, jcal, jcard, json, mimedir.");
293 $this->
log($this->
colorize(
'green',
' --inputformat ') .
"If the input format cannot be guessed from the extension, it");
294 $this->
log(
" must be specified here.");
296 if (version_compare(PHP_VERSION,
'5.4.0') >= 0) {
297 $this->
log($this->
colorize(
'green',
' --pretty ') .
"json pretty-print.");
300 $this->
log(
'Commands:',
'yellow');
301 $this->
log($this->
colorize(
'green',
' validate') .
' source_file Validates a file for correctness.');
302 $this->
log($this->
colorize(
'green',
' repair') .
' source_file [output_file] Repairs a file.');
303 $this->
log($this->
colorize(
'green',
' convert') .
' source_file [output_file] Converts a file.');
304 $this->
log($this->
colorize(
'green',
' color') .
' source_file Colorize a file, useful for debbugging.');
308 If source_file
is set as
'-', STDIN will be used.
309 If output_file
is omitted, STDOUT will be used.
310 All other output
is sent to STDERR.
315 $this->
log(
'Examples:',
'yellow');
316 $this->
log(
' vobject convert contact.vcf contact.json');
317 $this->
log(
' vobject convert --format=vcard40 old.vcf new.vcf');
318 $this->
log(
' vobject convert --inputformat=json --format=mimedir - -');
319 $this->
log(
' vobject color calendar.ics');
321 $this->
log(
'https://github.com/fruux/sabre-vobject',
'purple');
colorize($color, $str, $resetTo='default')
Returns an ansi color string for a color name.
log($msg, $color='default')
Sends a message to STDERR.
◆ validate()
Sabre\VObject\Cli::validate |
( |
Component |
$vObj | ) |
|
|
protected |
Validates a VObject file.
- Parameters
-
- Returns
- int
Definition at line 332 of file Cli.php.
References $warnings, Sabre\VObject\Cli\log(), and Sabre\VObject\Component\validate().
336 switch ($vObj->name) {
338 $this->
log(
"iCalendar: " . (
string)$vObj->VERSION);
341 $this->
log(
"vCard: " . (
string)$vObj->VERSION);
347 $this->
log(
" No warnings!");
359 if ($warn[
'node'] instanceof Property) {
360 $extra =
' (property: "' . $warn[
'node']->name .
'")';
362 $this->
log(
" [" . $levels[$warn[
'level']] .
'] ' . $warn[
'message'] . $extra);
log($msg, $color='default')
Sends a message to STDERR.
◆ $forgiving
Sabre\VObject\Cli::$forgiving = false |
|
protected |
◆ $format
Sabre\VObject\Cli::$format |
|
protected |
◆ $inputFormat
Sabre\VObject\Cli::$inputFormat |
|
protected |
◆ $inputPath
Sabre\VObject\Cli::$inputPath |
|
protected |
◆ $outputPath
Sabre\VObject\Cli::$outputPath |
|
protected |
◆ $parser
Sabre\VObject\Cli::$parser |
|
protected |
◆ $pretty
Sabre\VObject\Cli::$pretty |
|
protected |
◆ $quiet
Sabre\VObject\Cli::$quiet = false |
|
protected |
◆ $showHelp
Sabre\VObject\Cli::$showHelp = false |
|
protected |
◆ $stderr
Sabre\VObject\Cli::$stderr |
|
protected |
◆ $stdin
Sabre\VObject\Cli::$stdin |
|
protected |
◆ $stdout
Sabre\VObject\Cli::$stdout |
|
protected |
The documentation for this class was generated from the following file:
- libs/composer/vendor/sabre/vobject/lib/Cli.php