本文整理汇总了PHP中Cli::writeError方法的典型用法代码示例。如果您正苦于以下问题:PHP Cli::writeError方法的具体用法?PHP Cli::writeError怎么用?PHP Cli::writeError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cli
的用法示例。
在下文中一共展示了Cli::writeError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUploadFormData
/**
* Puts together the POST body when uploading files
*
* @param array $postData
* @param array $files An array of files like `[string $fileName => string|resource|array $file]`.
* In case $file is an array it provides additional control on file name and contents type.
* Available keys are `path`, `fileContents`, `fileName` and `contentType`. One of `path` or
* `fileContents` is required.
* If `path` is set then `fileName` and `contentType` are optional.
* If `fileContents` is set then `fileName` and `contentType` are required.
*
* examples:
* <ul>
* <li>['file1' => ['path' => '/tmp/file.php']]</li>
* <li>['file1' => ['path' => '/tmp/file.php'], 'file2' => ['path' => '/tmp/file2.png']]</li>
* <li>['file1' => ['fileContents' => '<?php echo 1;', 'fileName' => 'o.png', 'contentType' => 'image/png']]</li>
* </ul>
* @param string $formBoundary
*
* @return string
* @author Panagiotis Vagenas <pan.vagenas@gmail.com>
* @since 0-dev
*/
protected static function getUploadFormData($postData = [], $files = [], $formBoundary = '__FORM_BOUNDARY__')
{
$postData = (array) $postData;
$formBoundary = preg_replace('/\\W/', '', $formBoundary);
$payload = [];
foreach ($postData as $paramName => $value) {
$payload[] = '--' . $formBoundary;
$payload[] = 'Content-Disposition: form-data; name="' . $paramName . '"';
$payload[] = '';
$payload[] = $value;
}
/** @var resource|string|array $file */
foreach ($files as $paramName => $file) {
$fileData = self::getFileData($file);
if (isset($fileData['error'])) {
Cli::writeError("Something went wrong with file {$paramName} (error: {$fileData['error']}), skipping...");
continue;
}
$payload[] = '--' . $formBoundary;
$payload[] = 'Content-Disposition: form-data; name="' . $paramName . '"; filename="' . $fileData['fileName'] . '"';
$payload[] = "Content-Type: {$fileData['contentType']}";
$payload[] = '';
$payload[] = $fileData['fileContents'];
$payload[] = '';
}
$payload[] = '--' . $formBoundary;
$payload[] = '';
return implode(CRLF, $payload);
}
示例2: exitWithFailedRequest
/**
* @param string $msg A message to display before exiting
*
* @author Panagiotis Vagenas <pan.vagenas@gmail.com>
* @since 0-dev
*/
public static function exitWithFailedRequest($msg = '')
{
if ($msg) {
Cli::writeError($msg);
}
self::exitWith(self::EXIT_CODE_VALID_REQUEST_FAILED);
}