框架本地无法运行,修复尝试

This commit is contained in:
wangjinlei
2026-06-04 13:33:13 +08:00
parent bbd690ca0f
commit 0ee7c38000
359 changed files with 2767 additions and 3114 deletions

View File

@@ -0,0 +1,386 @@
<?php
namespace app\api\controller;
use think\Cache;
use app\common\BackgroundCheckService;
/**
* 背景调查控制器
*
* 功能:查询学者公开学术指标 + 撤稿/不端公开记录 + 按领域批量筛查
*
* 接口:
* api/background_check/demo - 快速体验
* api/background_check/searchAuthor - 按姓名搜索学者
* api/background_check/checkProfile - 完整背景调查报告
* api/background_check/checkRetractionByDoi - 单篇 DOI 撤稿详情CrossRef + RW
* api/background_check/batchScreenByField - 按领域批量筛查专家
*/
class BackgroundCheck extends Base
{
/** @var BackgroundCheckService */
private $service;
public function __construct(\think\Request $request = null)
{
parent::__construct($request);
$this->service = new BackgroundCheckService();
}
// ===================== 公开 API =====================
/**
* Demo快速体验
*
* @param string orcid 可选,默认 0000-0002-2582-7480
*/
public function demo()
{
$orcid = $this->service->cleanOrcid($this->request->param('orcid', '0000-0002-2582-7480'));
$report = $this->buildProfileReport([
'orcid' => $orcid,
'with_crossref_detail'=> 1,
]);
if (!$report['success']) {
return jsonError($report['error']);
}
$report['data']['_demo_note'] = 'Demo 接口,正式使用请调用 checkProfile 或 batchScreenByField';
return jsonSuccess($report['data']);
}
/**
* 按姓名搜索学者
*
* @param string name 学者姓名(必填)
* @param string affiliation 单位关键词(可选)
* @param int limit 返回条数默认5最大20
*/
public function searchAuthor()
{
$name = trim($this->request->param('name', ''));
if ($name === '') {
return jsonError('name不能为空');
}
$affiliation = trim($this->request->param('affiliation', ''));
$limit = min(max(intval($this->request->param('limit', 5)), 1), 20);
$cacheKey = 'bg_search_' . md5($name . $affiliation . $limit);
$cached = Cache::get($cacheKey);
if ($cached) {
return jsonSuccess($cached);
}
$filter = 'display_name.search:' . $name;
if ($affiliation !== '') {
$filter .= ',last_known_institutions.display_name.search:' . $affiliation;
}
$res = $this->service->openAlexGet('/authors', [
'search' => $name,
'filter' => $filter,
'sort' => 'cited_by_count:desc',
'per-page' => $limit,
]);
if (!$res['success']) {
return jsonError($res['error']);
}
$list = [];
foreach ($res['data']['results'] ?? [] as $author) {
$list[] = $this->service->formatAuthorBrief($author);
}
$result = [
'query' => ['name' => $name, 'affiliation' => $affiliation],
'total' => $res['data']['meta']['count'] ?? count($list),
'list' => $list,
];
Cache::set($cacheKey, $result, 1800);
return jsonSuccess($result);
}
/**
* 完整背景调查报告
*
* @param string openalex_id OpenAlex 作者ID
* @param string orcid ORCID
* @param string name 姓名
* @param string affiliation 单位关键词
* @param int user_id 本地用户ID可选
* @param int with_crossref_detail 是否补充 CrossRef 撤稿详情默认1
*/
public function checkProfile()
{
$params = [
'openalex_id' => trim($this->request->param('openalex_id', '')),
'orcid' => $this->service->cleanOrcid($this->request->param('orcid', '')),
'name' => trim($this->request->param('name', '')),
'affiliation' => trim($this->request->param('affiliation', '')),
'user_id' => intval($this->request->param('user_id', 0)),
'with_crossref_detail' => intval($this->request->param('with_crossref_detail', 1)),
];
if ($params['openalex_id'] === '' && $params['orcid'] === '' && $params['name'] === '') {
return jsonError('请至少提供 openalex_id、orcid 或 name 之一');
}
$report = $this->buildProfileReport($params);
if (!$report['success']) {
return jsonError($report['error']);
}
return jsonSuccess($report['data']);
}
/**
* 单篇 DOI 撤稿详情CrossRef + Retraction Watch 来源标记)
*
* @param string doi 文章 DOI必填
*/
public function checkRetractionByDoi()
{
$doi = trim($this->request->param('doi', ''));
if ($doi === '') {
return jsonError('doi不能为空');
}
$res = $this->service->fetchCrossRefWork($doi);
if (!$res['success']) {
return jsonError($res['error']);
}
$detail = $this->service->parseCrossRefRetractionDetail($doi, $res['message']);
$sources = $detail['retraction_detail']['sources'] ?? [];
$fromRw = false;
foreach ($sources as $src) {
if (stripos($src, 'retraction-watch') !== false || stripos($src, 'retraction_watch') !== false) {
$fromRw = true;
break;
}
}
return jsonSuccess([
'doi' => $detail['doi'],
'title' => $detail['title'],
'journal' => $detail['journal'],
'publisher' => $detail['publisher'],
'authors' => $detail['authors'],
'is_retracted' => $detail['is_retracted'],
'from_retraction_watch' => $fromRw || !empty($detail['retraction_detail']['record_ids']),
'retraction_detail' => $detail['retraction_detail'],
'url' => $detail['url'],
'data_sources' => ['CrossRef', 'Retraction Watch'],
]);
}
/**
* 按领域批量筛查专家(含撤稿风险标签)
*
* @param string keyword 领域关键词(必填),如 immunotherapy、cancer
* @param int min_h_index 最低 h-index默认5
* @param int limit 每页数量默认10最大30
* @param int page 页码默认1
* @param int check_retraction 是否检查撤稿默认1
*/
public function batchScreenByField()
{
$keyword = trim($this->request->param('keyword', ''));
if ($keyword === '') {
return jsonError('keyword不能为空');
}
$options = [
'min_h_index' => intval($this->request->param('min_h_index', 5)),
'limit' => min(max(intval($this->request->param('limit', 10)), 1), 30),
'page' => max(intval($this->request->param('page', 1)), 1),
];
$checkRetraction = intval($this->request->param('check_retraction', 1));
$cacheKey = 'bg_batch_' . md5(json_encode([$keyword, $options, $checkRetraction]));
$cached = Cache::get($cacheKey);
if ($cached) {
return jsonSuccess($cached);
}
$searchRes = $this->service->searchAuthorsByField($keyword, $options);
if (!$searchRes['success']) {
return jsonError($searchRes['error']);
}
$data = $searchRes['data'];
$screened = [];
$riskStats = ['low' => 0, 'medium' => 0, 'high' => 0];
foreach ($data['list'] as $author) {
$item = [
'profile' => $author,
'metrics' => [
'works_count' => $author['works_count'],
'cited_by_count' => $author['cited_by_count'],
'h_index' => $author['h_index'],
'level_label' => $this->service->parseAuthorMetrics([
'works_count' => $author['works_count'],
'cited_by_count' => $author['cited_by_count'],
'summary_stats' => ['h_index' => $author['h_index']],
])['level_label'],
],
];
if ($checkRetraction) {
$openAlexId = $author['openalex_id'];
$oaRetractions = $this->service->fetchRetractedWorksOpenAlex($openAlexId);
$rwRetractions = $this->service->fetchRetractionWatchByAuthor($author['name']);
$merged = $this->service->mergeRetractionRecords($oaRetractions, $rwRetractions, false);
$metrics = ['works_count' => $author['works_count']];
$risk = $this->service->assessRisk($metrics, $merged);
$item['retractions'] = [
'count' => $merged['count'],
'openalex_count'=> $merged['openalex_count'],
'rw_count' => $merged['rw_count'],
'rw_only_count' => $merged['rw_only_count'],
'list' => array_slice($merged['list'], 0, 3),
];
$item['risk_assessment'] = $risk;
$riskStats[$risk['level']]++;
} else {
$item['risk_assessment'] = [
'level' => 'unknown',
'level_label' => '未检测',
];
}
$screened[] = $item;
usleep(300000);
}
$result = [
'query' => [
'keyword' => $keyword,
'topic_id' => $data['topic_id'],
'min_h_index' => $options['min_h_index'],
'page' => $options['page'],
'limit' => $options['limit'],
'check_retraction' => $checkRetraction,
],
'total' => $data['total'],
'risk_stats' => $checkRetraction ? $riskStats : null,
'list' => $screened,
'disclaimer' => '批量筛查基于公开数据,同名作者可能存在误匹配,高风险条目需人工复核。',
];
Cache::set($cacheKey, $result, 900);
return jsonSuccess($result);
}
// ===================== 核心逻辑 =====================
/**
* 构建完整背景调查报告
*/
private function buildProfileReport($params)
{
$withCrossRef = !empty($params['with_crossref_detail']);
$author = $this->service->resolveAuthor($params);
if (!$author['success']) {
return $author;
}
$authorData = $author['data'];
$openAlexId = $this->service->extractOpenAlexId($authorData['id']);
$authorName = $authorData['display_name'] ?? '';
$metrics = $this->service->parseAuthorMetrics($authorData);
$topics = $this->service->parseResearchTopics($authorData);
$recentWorks = $this->service->fetchRecentWorks($openAlexId, 5);
// 扩展1: OpenAlex 撤稿
$oaRetractions = $this->service->fetchRetractedWorksOpenAlex($openAlexId);
// 扩展1: Retraction Watch 二次核对CrossRef 来源)
$rwRetractions = $this->service->fetchRetractionWatchByAuthor($authorName);
// 扩展2: 合并并按需补充 CrossRef 撤稿详情
$retractions = $this->service->mergeRetractionRecords(
$oaRetractions,
$rwRetractions,
$withCrossRef
);
$risk = $this->service->assessRisk($metrics, $retractions);
$localInfo = null;
if (!empty($params['user_id'])) {
$localInfo = $this->fetchLocalUserInfo($params['user_id']);
}
$dataSources = ['OpenAlex', 'Retraction Watch (via CrossRef)'];
if ($withCrossRef) {
$dataSources[] = 'CrossRef';
}
return [
'success' => true,
'data' => [
'profile' => $this->service->formatAuthorBrief($authorData),
'metrics' => $metrics,
'research_topics' => $topics,
'recent_works' => $recentWorks,
'retractions' => $retractions,
'risk_assessment' => $risk,
'local_info' => $localInfo,
'data_sources' => $dataSources,
'disclaimer' => '本报告仅基于公开学术数据,不能替代正式背调或机构调查;未公开的不端行为无法检测。',
'generated_at' => date('Y-m-d H:i:s'),
],
];
}
/**
* 合并本地用户信息
*/
private function fetchLocalUserInfo($userId)
{
$user = $this->user_obj->where('user_id', $userId)->find();
if (!$user) {
return null;
}
$reviewer = $this->user_reviewer_info_obj
->where('reviewer_id', $userId)
->where('state', 0)
->find();
$majors = $this->major_to_user_obj
->where('user_id', $userId)
->where('state', 0)
->select();
$majorList = [];
foreach ($majors as $m) {
$majorList[] = [
'major_id' => $m['major_id'],
'path' => getMajorStr($m['major_id']),
];
}
return [
'user_id' => $userId,
'realname' => $user['realname'] ?? '',
'email' => $user['email'] ?? '',
'orcid' => $user['orcid'] ?? '',
'company' => $reviewer['company'] ?? '',
'title' => $reviewer['technical'] ?? '',
'field' => $reviewer['field'] ?? '',
'majors' => $majorList,
];
}
}

View File

@@ -0,0 +1,705 @@
<?php
namespace app\common;
/**
* 背景调查公共服务
* 封装 OpenAlex / CrossRef / Retraction Watch 数据查询
*/
class BackgroundCheckService
{
private $openAlexBase = 'https://api.openalex.org';
private $crossRefBase = 'https://api.crossref.org';
private $mailto = 'publisher@tmrjournals.com';
// ===================== OpenAlex =====================
public function openAlexGet($path, $query = [])
{
$query['mailto'] = $this->mailto;
$url = $this->openAlexBase . $path . '?' . http_build_query($query);
$result = $this->httpGet($url, [
'Accept: application/json',
'User-Agent: TMRJournals-BackgroundCheck/1.0 (mailto:' . $this->mailto . ')',
]);
if (!$result['success']) {
return $result;
}
$data = json_decode($result['body'], true);
if (!is_array($data)) {
return ['success' => false, 'error' => 'OpenAlex返回数据格式异常'];
}
return ['success' => true, 'data' => $data];
}
public function resolveAuthor($params)
{
if (!empty($params['openalex_id'])) {
$id = preg_replace('/^https?:\/\/openalex\.org\//', '', $params['openalex_id']);
$res = $this->openAlexGet('/authors/' . urlencode($id));
if (!$res['success']) {
return ['success' => false, 'error' => $res['error']];
}
return ['success' => true, 'data' => $res['data']];
}
if (!empty($params['orcid'])) {
$orcid = $this->cleanOrcid($params['orcid']);
$res = $this->openAlexGet('/authors/https://orcid.org/' . $orcid);
if (!$res['success']) {
return ['success' => false, 'error' => '未在 OpenAlex 找到该 ORCID 对应学者'];
}
return ['success' => true, 'data' => $res['data']];
}
if (empty($params['name'])) {
return ['success' => false, 'error' => '请提供 openalex_id、orcid 或 name'];
}
$filter = 'display_name.search:' . $params['name'];
if (!empty($params['affiliation'])) {
$filter .= ',last_known_institutions.display_name.search:' . $params['affiliation'];
}
$res = $this->openAlexGet('/authors', [
'search' => $params['name'],
'filter' => $filter,
'sort' => 'cited_by_count:desc',
'per-page' => 1,
]);
if (!$res['success']) {
return ['success' => false, 'error' => $res['error']];
}
$results = $res['data']['results'] ?? [];
if (empty($results)) {
return ['success' => false, 'error' => '未找到匹配学者,请补充 affiliation 或使用 orcid'];
}
return ['success' => true, 'data' => $results[0]];
}
public function fetchRetractedWorksOpenAlex($openAlexId)
{
$res = $this->openAlexGet('/works', [
'filter' => 'authorships.author.id:' . $openAlexId . ',is_retracted:true',
'sort' => 'publication_date:desc',
'per-page' => 25,
]);
if (!$res['success']) {
return ['count' => 0, 'list' => [], 'error' => $res['error']];
}
$list = [];
foreach ($res['data']['results'] ?? [] as $work) {
$list[] = $this->formatOpenAlexWork($work);
}
return ['count' => count($list), 'list' => $list, 'source' => 'openalex'];
}
public function fetchRecentWorks($openAlexId, $limit = 5)
{
$res = $this->openAlexGet('/works', [
'filter' => 'authorships.author.id:' . $openAlexId,
'sort' => 'publication_date:desc',
'per-page' => $limit,
]);
if (!$res['success']) {
return [];
}
$list = [];
foreach ($res['data']['results'] ?? [] as $work) {
$item = $this->formatOpenAlexWork($work);
$item['is_retracted'] = !empty($work['is_retracted']);
$list[] = $item;
}
return $list;
}
/**
* 按领域/关键词批量搜索学者OpenAlex
*/
public function searchAuthorsByField($keyword, $options = [])
{
$minHIndex = intval($options['min_h_index'] ?? 5);
$limit = min(max(intval($options['limit'] ?? 10), 1), 30);
$page = max(intval($options['page'] ?? 1), 1);
$topicId = $this->resolveTopicId($keyword);
$filters = [];
if ($topicId !== '') {
$filters[] = 'topics.id:' . $topicId;
}
if ($minHIndex > 0) {
$filters[] = 'summary_stats.h_index:>' . $minHIndex;
}
$query = [
'sort' => 'cited_by_count:desc',
'per-page' => $limit,
'page' => $page,
];
if (!empty($filters)) {
$query['filter'] = implode(',', $filters);
$query['search'] = $keyword;
} else {
$query['search'] = $keyword;
}
$res = $this->openAlexGet('/authors', $query);
if (!$res['success']) {
return ['success' => false, 'error' => $res['error']];
}
$authors = [];
foreach ($res['data']['results'] ?? [] as $author) {
$authors[] = $this->formatAuthorBrief($author);
}
return [
'success' => true,
'data' => [
'keyword' => $keyword,
'topic_id' => $topicId,
'page' => $page,
'limit' => $limit,
'total' => $res['data']['meta']['count'] ?? count($authors),
'list' => $authors,
],
];
}
private function resolveTopicId($keyword)
{
$res = $this->openAlexGet('/topics', [
'search' => $keyword,
'sort' => 'works_count:desc',
'per-page' => 1,
]);
if (!$res['success']) {
return '';
}
$results = $res['data']['results'] ?? [];
if (empty($results)) {
return '';
}
return $this->extractOpenAlexId($results[0]['id'] ?? '');
}
// ===================== CrossRef =====================
public function cleanDoi($doi)
{
$doi = trim($doi);
$doi = preg_replace('/^https?:\/\/doi\.org\//', '', $doi);
$doi = preg_replace('/^doi:\s*/i', '', $doi);
return trim($doi);
}
public function fetchCrossRefWork($doi)
{
$doi = $this->cleanDoi($doi);
if ($doi === '') {
return ['success' => false, 'error' => 'DOI为空'];
}
$url = $this->crossRefBase . '/works/' . urlencode($doi);
$result = $this->httpGet($url, [
'Accept: application/json',
'User-Agent: TMRJournals-BackgroundCheck/1.0 (mailto:' . $this->mailto . ')',
]);
if (!$result['success']) {
return ['success' => false, 'error' => $result['error']];
}
if ($result['http_code'] == 404) {
return ['success' => false, 'error' => 'DOI在CrossRef中未找到'];
}
if ($result['http_code'] != 200) {
return ['success' => false, 'error' => 'CrossRef返回 HTTP ' . $result['http_code']];
}
$data = json_decode($result['body'], true);
if (!isset($data['message'])) {
return ['success' => false, 'error' => 'CrossRef返回数据格式异常'];
}
return ['success' => true, 'message' => $data['message']];
}
public function parseCrossRefRetractionDetail($doi, $message)
{
$retraction = $this->detectCrossRefRetraction($message);
return [
'doi' => $this->cleanDoi($doi),
'title' => isset($message['title'][0]) ? $message['title'][0] : '',
'is_retracted' => $retraction['is_retracted'],
'retraction_detail' => $retraction['retraction_detail'],
'journal' => isset($message['container-title'][0]) ? $message['container-title'][0] : '',
'publisher' => $message['publisher'] ?? '',
'published_date' => isset($message['published-print']) ? $this->parseDateParts($message['published-print']) : '',
'authors' => $this->parseCrossRefAuthors($message['author'] ?? []),
'url' => $message['URL'] ?? ('https://doi.org/' . $this->cleanDoi($doi)),
];
}
public function enrichRetractionsWithCrossRef($retractionList)
{
$enriched = [];
foreach ($retractionList as $item) {
$doi = $this->cleanDoi($item['doi'] ?? '');
if ($doi === '') {
$item['crossref'] = ['success' => false, 'error' => '无DOI'];
$enriched[] = $item;
continue;
}
$res = $this->fetchCrossRefWork($doi);
if (!$res['success']) {
$item['crossref'] = ['success' => false, 'error' => $res['error']];
} else {
$item['crossref'] = [
'success' => true,
'data' => $this->parseCrossRefRetractionDetail($doi, $res['message']),
];
}
$enriched[] = $item;
usleep(200000);
}
return $enriched;
}
private function detectCrossRefRetraction($message)
{
$isRetracted = false;
$retractionDetail = [
'sources' => [],
'retraction_notices' => [],
'record_ids' => [],
];
foreach (['updated-by', 'update-to'] as $field) {
if (!isset($message[$field]) || !is_array($message[$field])) {
continue;
}
foreach ($message[$field] as $update) {
$updateType = strtolower($update['type'] ?? '');
$updateLabel = strtolower($update['label'] ?? '');
if (strpos($updateType, 'retract') === false && strpos($updateLabel, 'retract') === false) {
continue;
}
$isRetracted = true;
$source = $update['source'] ?? 'publisher';
$retractionDetail['sources'][] = $source;
$notice = [
'type' => $update['type'] ?? '',
'label' => $update['label'] ?? '',
'source' => $source,
'notice_doi'=> $update['DOI'] ?? '',
'date' => isset($update['updated']) ? $this->parseDateParts($update['updated']) : '',
'record_id' => $update['record-id'] ?? '',
];
$retractionDetail['retraction_notices'][] = $notice;
if (!empty($notice['record_id'])) {
$retractionDetail['record_ids'][] = $notice['record_id'];
}
}
}
$type = strtolower($message['type'] ?? '');
$subtype = strtolower($message['subtype'] ?? '');
if (strpos($type, 'retract') !== false || strpos($subtype, 'retract') !== false) {
$isRetracted = true;
$retractionDetail['is_retraction_notice'] = true;
}
if (isset($message['relation']) && is_array($message['relation'])) {
foreach ($message['relation'] as $relType => $relations) {
if (strpos(strtolower($relType), 'retract') !== false) {
$isRetracted = true;
$retractionDetail['relation'] = [$relType => $relations];
break;
}
}
}
$retractionDetail['sources'] = array_values(array_unique($retractionDetail['sources']));
$retractionDetail['record_ids'] = array_values(array_unique($retractionDetail['record_ids']));
return ['is_retracted' => $isRetracted, 'retraction_detail' => $retractionDetail];
}
// ===================== Retraction Watch (via CrossRef) =====================
/**
* 通过 CrossRef 检索 Retraction Watch 来源的撤稿记录(按作者姓名)
*/
public function fetchRetractionWatchByAuthor($authorName)
{
$url = $this->crossRefBase . '/works?' . http_build_query([
'query.author' => $authorName,
'filter' => 'update-type:retraction',
'rows' => 25,
'mailto' => $this->mailto,
]);
$result = $this->httpGet($url, [
'Accept: application/json',
'User-Agent: TMRJournals-BackgroundCheck/1.0 (mailto:' . $this->mailto . ')',
]);
if (!$result['success']) {
return ['count' => 0, 'list' => [], 'error' => $result['error']];
}
if ($result['http_code'] != 200) {
return ['count' => 0, 'list' => [], 'error' => 'CrossRef返回 HTTP ' . $result['http_code']];
}
$data = json_decode($result['body'], true);
$items = $data['message']['items'] ?? [];
$list = [];
foreach ($items as $message) {
$parsed = $this->parseCrossRefRetractionDetail($message['DOI'] ?? '', $message);
if (!$parsed['is_retracted']) {
continue;
}
$rwSources = array_filter($parsed['retraction_detail']['sources'] ?? [], function ($s) {
return stripos($s, 'retraction-watch') !== false || stripos($s, 'retraction_watch') !== false;
});
$list[] = [
'title' => $parsed['title'],
'doi' => $parsed['doi'],
'journal' => $parsed['journal'],
'publisher' => $parsed['publisher'],
'published_date' => $parsed['published_date'],
'is_retracted' => true,
'retraction_detail' => $parsed['retraction_detail'],
'from_retraction_watch' => !empty($rwSources) || !empty($parsed['retraction_detail']['record_ids']),
'source' => 'retraction_watch',
];
}
return [
'count' => count($list),
'list' => $list,
'source' => 'retraction_watch',
];
}
/**
* 合并 OpenAlex + Retraction Watch 撤稿记录(按 DOI 去重)
*/
public function mergeRetractionRecords($openAlexRetractions, $rwRetractions, $withCrossRefDetail = false)
{
$merged = [];
$doiMap = [];
foreach ([$openAlexRetractions, $rwRetractions] as $sourceData) {
foreach ($sourceData['list'] ?? [] as $item) {
$doi = $this->cleanDoi($item['doi'] ?? '');
$key = $doi !== '' ? strtolower($doi) : md5(json_encode($item));
if (!isset($doiMap[$key])) {
$doiMap[$key] = [
'title' => $item['title'] ?? '',
'doi' => $doi,
'journal' => $item['journal'] ?? '',
'publication_date' => $item['publication_date'] ?? ($item['published_date'] ?? ''),
'sources' => [],
'retraction_detail'=> $item['retraction_detail'] ?? [],
'from_retraction_watch' => !empty($item['from_retraction_watch']),
];
}
$src = $item['source'] ?? 'unknown';
if (!in_array($src, $doiMap[$key]['sources'])) {
$doiMap[$key]['sources'][] = $src;
}
if (!empty($item['from_retraction_watch'])) {
$doiMap[$key]['from_retraction_watch'] = true;
}
if (!empty($item['retraction_detail']) && empty($doiMap[$key]['retraction_detail'])) {
$doiMap[$key]['retraction_detail'] = $item['retraction_detail'];
}
}
}
$merged = array_values($doiMap);
if ($withCrossRefDetail) {
$merged = $this->enrichRetractionsWithCrossRef($merged);
}
$rwOnlyCount = 0;
foreach ($merged as $row) {
if (!empty($row['from_retraction_watch']) && count($row['sources'] ?? []) <= 1) {
$rwOnlyCount++;
}
}
return [
'count' => count($merged),
'openalex_count' => intval($openAlexRetractions['count'] ?? 0),
'rw_count' => intval($rwRetractions['count'] ?? 0),
'rw_only_count' => $rwOnlyCount,
'list' => $merged,
];
}
// ===================== 格式化 =====================
public function formatAuthorBrief($author)
{
$institutions = [];
foreach ($author['last_known_institutions'] ?? [] as $inst) {
$institutions[] = [
'name' => $inst['display_name'] ?? '',
'country' => $inst['country_code'] ?? '',
];
}
return [
'openalex_id' => $this->extractOpenAlexId($author['id'] ?? ''),
'name' => $author['display_name'] ?? '',
'orcid' => $this->extractOrcid($author['orcid'] ?? ''),
'works_count' => intval($author['works_count'] ?? 0),
'cited_by_count' => intval($author['cited_by_count'] ?? 0),
'h_index' => intval($author['summary_stats']['h_index'] ?? 0),
'institutions' => $institutions,
'openalex_url' => $author['id'] ?? '',
];
}
public function parseAuthorMetrics($author)
{
$stats = $author['summary_stats'] ?? [];
return [
'works_count' => intval($author['works_count'] ?? 0),
'cited_by_count' => intval($author['cited_by_count'] ?? 0),
'h_index' => intval($stats['h_index'] ?? 0),
'i10_index' => intval($stats['i10_index'] ?? 0),
'two_year_mean_cited' => round(floatval($stats['2yr_mean_citedness'] ?? 0), 2),
'level_label' => $this->getAcademicLevelLabel($stats),
];
}
public function parseResearchTopics($author)
{
$topics = [];
foreach ($author['x_concepts'] ?? [] as $concept) {
if (empty($concept['display_name'])) {
continue;
}
$topics[] = [
'name' => $concept['display_name'],
'score' => round(floatval($concept['score'] ?? 0), 3),
];
}
if (empty($topics)) {
foreach ($author['topics'] ?? [] as $topic) {
if (empty($topic['display_name'])) {
continue;
}
$topics[] = [
'name' => $topic['display_name'],
'score' => round(floatval($topic['score'] ?? 0), 3),
];
}
}
return array_slice($topics, 0, 8);
}
public function assessRisk($metrics, $retractions)
{
$retractionCount = intval($retractions['count'] ?? 0);
$rwOnlyCount = intval($retractions['rw_only_count'] ?? 0);
$level = 'low';
$score = 0;
$reasons = [];
if ($retractionCount === 0) {
$level = 'low';
$score = 10;
$reasons[] = 'OpenAlex 与 Retraction Watch 均未发现撤稿记录';
} elseif ($retractionCount === 1) {
$level = 'medium';
$score = 50;
$reasons[] = '发现 1 篇撤稿论文,建议人工核实撤稿原因';
} else {
$level = 'high';
$score = 80 + min($retractionCount * 5, 20);
$reasons[] = '发现 ' . $retractionCount . ' 篇撤稿论文,存在较高学术风险';
}
if ($rwOnlyCount > 0) {
$reasons[] = 'Retraction Watch 额外发现 ' . $rwOnlyCount . ' 条 OpenAlex 未收录的撤稿记录';
if ($level === 'low') {
$level = 'medium';
$score = max($score, 45);
}
}
$worksCount = max(intval($metrics['works_count'] ?? 0), 1);
$retractionRate = round($retractionCount / $worksCount * 100, 2);
if ($retractionCount > 0 && $retractionRate >= 5) {
$reasons[] = '撤稿率 ' . $retractionRate . '%,比例偏高';
if ($level === 'medium') {
$level = 'high';
$score = max($score, 70);
}
}
return [
'level' => $level,
'level_label' => $this->getRiskLevelLabel($level),
'score' => min($score, 100),
'retraction_count' => $retractionCount,
'retraction_rate' => $retractionRate . '%',
'rw_only_count' => $rwOnlyCount,
'reasons' => $reasons,
];
}
// ===================== 内部工具 =====================
private function formatOpenAlexWork($work)
{
return [
'title' => $work['display_name'] ?? '',
'doi' => $this->extractDoi($work),
'publication_date' => $work['publication_date'] ?? '',
'journal' => $work['primary_location']['source']['display_name'] ?? '',
'cited_by_count' => intval($work['cited_by_count'] ?? 0),
'openalex_url' => $work['id'] ?? '',
'source' => 'openalex',
];
}
private function parseCrossRefAuthors($authorList)
{
if (empty($authorList) || !is_array($authorList)) {
return [];
}
$result = [];
foreach ($authorList as $a) {
$result[] = [
'given' => $a['given'] ?? '',
'family' => $a['family'] ?? '',
'name' => isset($a['name']) ? $a['name'] : trim(($a['given'] ?? '') . ' ' . ($a['family'] ?? '')),
'orcid' => $a['ORCID'] ?? '',
];
}
return $result;
}
private function parseDateParts($dateObj)
{
if (!isset($dateObj['date-parts'][0])) {
return '';
}
$parts = $dateObj['date-parts'][0];
$y = isset($parts[0]) ? $parts[0] : '';
$m = isset($parts[1]) ? sprintf('%02d', $parts[1]) : '';
$d = isset($parts[2]) ? sprintf('%02d', $parts[2]) : '';
if ($y && $m && $d) {
return "{$y}-{$m}-{$d}";
}
if ($y && $m) {
return "{$y}-{$m}";
}
return (string)$y;
}
private function getAcademicLevelLabel($stats)
{
$h = intval($stats['h_index'] ?? 0);
if ($h >= 50) return '国际顶尖学者';
if ($h >= 30) return '资深专家';
if ($h >= 15) return '活跃研究者';
if ($h >= 5) return '青年学者';
if ($h > 0) return '初入领域';
return '暂无足够公开数据';
}
private function getRiskLevelLabel($level)
{
$map = ['low' => '低风险', 'medium' => '中风险', 'high' => '高风险'];
return $map[$level] ?? '未知';
}
public function extractOpenAlexId($id)
{
return preg_replace('/^https?:\/\/openalex\.org\//', '', $id);
}
public function extractOrcid($orcid)
{
if ($orcid === '') return '';
return preg_replace('/^https?:\/\/orcid\.org\//', '', $orcid);
}
public function cleanOrcid($orcid)
{
$orcid = trim($orcid);
$orcid = preg_replace('/^https?:\/\/orcid\.org\//', '', $orcid);
return trim($orcid);
}
private function extractDoi($work)
{
$doi = $work['doi'] ?? '';
return preg_replace('/^https?:\/\/doi\.org\//', '', $doi);
}
private function httpGet($url, $headers = [])
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$body = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
$error = curl_error($ch);
curl_close($ch);
return ['success' => false, 'error' => 'HTTP请求失败: ' . $error];
}
curl_close($ch);
return ['success' => true, 'body' => $body, 'http_code' => $httpCode];
}
}

View File

@@ -44,7 +44,10 @@
"topthink/think-installer": true,
"php-http/discovery": true
},
"secure-http": false
"secure-http": false,
"audit": {
"block-insecure": false
}
},
"repositories": [{
"name": "aliyun",

5
vendor/autoload.php vendored
View File

@@ -14,10 +14,7 @@ if (PHP_VERSION_ID < 50600) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
throw new RuntimeException($err);
}
require_once __DIR__ . '/composer/autoload_real.php';

View File

@@ -6,10 +6,5 @@ $vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'PhpToken' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
'Stringable' => $vendorDir . '/myclabs/php-enum/stubs/Stringable.php',
'UnhandledMatchError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
'ValueError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/ValueError.php',
);

View File

@@ -7,12 +7,12 @@ $baseDir = dirname($vendorDir);
return array(
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
'9c67151ae59aff4788964ce8eb2a0f43' => $vendorDir . '/clue/stream-filter/src/functions_include.php',
'7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
'2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
'8cff32064859f4559445b89279f3199c' => $vendorDir . '/php-http/message/src/filters.php',
'decc78cc4436b1292c6c0d151b19445c' => $vendorDir . '/phpseclib/phpseclib/phpseclib/bootstrap.php',
'6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
'9b552a3cc426e3287cc811caefa3cf53' => $vendorDir . '/topthink/think-helper/src/helper.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php',

View File

@@ -15,12 +15,11 @@ return array(
'ZipStream\\' => array($vendorDir . '/maennchen/zipstream-php/src'),
'Unirest\\' => array($vendorDir . '/apimatic/unirest-php/src'),
'Tectalic\\OpenAi\\' => array($vendorDir . '/tectalic/openai/src'),
'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
'Symfony\\Component\\HttpFoundation\\' => array($vendorDir . '/symfony/http-foundation'),
'Spatie\\DataTransferObject\\' => array($vendorDir . '/spatie/data-transfer-object/src'),
'Psr\\SimpleCache\\' => array($vendorDir . '/psr/simple-cache/src'),
'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
'Psr\\Log\\' => array($vendorDir . '/psr/log/src'),
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-factory/src', $vendorDir . '/psr/http-message/src'),
'Psr\\Http\\Client\\' => array($vendorDir . '/psr/http-client/src'),
'PhpOffice\\PhpWord\\' => array($vendorDir . '/phpoffice/phpword/src/PhpWord'),
@@ -31,7 +30,6 @@ return array(
'ParagonIE\\ConstantTime\\' => array($vendorDir . '/paragonie/constant_time_encoding/src'),
'PHPMailer\\PHPMailer\\' => array($vendorDir . '/phpmailer/phpmailer/src'),
'Nyholm\\Psr7\\' => array($vendorDir . '/nyholm/psr7/src'),
'MyCLabs\\Enum\\' => array($vendorDir . '/myclabs/php-enum/src'),
'Matrix\\' => array($vendorDir . '/markbaker/matrix/classes/src'),
'Http\\Message\\MultipartStream\\' => array($vendorDir . '/php-http/multipart-stream-builder/src'),
'Http\\Message\\' => array($vendorDir . '/php-http/message/src'),
@@ -41,6 +39,7 @@ return array(
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
'Core\\' => array($vendorDir . '/apimatic/core/src'),
'CoreInterfaces\\' => array($vendorDir . '/apimatic/core-interfaces/src'),
'Composer\\Pcre\\' => array($vendorDir . '/composer/pcre/src'),
'Complex\\' => array($vendorDir . '/markbaker/complex/classes/src'),
'Clue\\StreamFilter\\' => array($vendorDir . '/clue/stream-filter/src'),
);

View File

@@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit7020b987d316c2076c2a6f439a1140f9
class ComposerAutoloaderInit2bc4f313dba415539e266f7ac2c87dcd
{
private static $loader;
@@ -22,18 +22,16 @@ class ComposerAutoloaderInit7020b987d316c2076c2a6f439a1140f9
return self::$loader;
}
require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInit7020b987d316c2076c2a6f439a1140f9', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit2bc4f313dba415539e266f7ac2c87dcd', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit7020b987d316c2076c2a6f439a1140f9', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit2bc4f313dba415539e266f7ac2c87dcd', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit7020b987d316c2076c2a6f439a1140f9::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit2bc4f313dba415539e266f7ac2c87dcd::getInitializer($loader));
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit7020b987d316c2076c2a6f439a1140f9::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit2bc4f313dba415539e266f7ac2c87dcd::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@@ -4,17 +4,16 @@
namespace Composer\Autoload;
class ComposerStaticInit7020b987d316c2076c2a6f439a1140f9
class ComposerStaticInit2bc4f313dba415539e266f7ac2c87dcd
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
'9c67151ae59aff4788964ce8eb2a0f43' => __DIR__ . '/..' . '/clue/stream-filter/src/functions_include.php',
'7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
'2cffec82183ee1cea088009cef9a6fc3' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
'8cff32064859f4559445b89279f3199c' => __DIR__ . '/..' . '/php-http/message/src/filters.php',
'decc78cc4436b1292c6c0d151b19445c' => __DIR__ . '/..' . '/phpseclib/phpseclib/phpseclib/bootstrap.php',
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
@@ -51,7 +50,6 @@ class ComposerStaticInit7020b987d316c2076c2a6f439a1140f9
),
'S' =>
array (
'Symfony\\Polyfill\\Php80\\' => 23,
'Symfony\\Polyfill\\Mbstring\\' => 26,
'Symfony\\Component\\HttpFoundation\\' => 33,
'Spatie\\DataTransferObject\\' => 26,
@@ -76,7 +74,6 @@ class ComposerStaticInit7020b987d316c2076c2a6f439a1140f9
),
'M' =>
array (
'MyCLabs\\Enum\\' => 13,
'Matrix\\' => 7,
),
'H' =>
@@ -95,6 +92,7 @@ class ComposerStaticInit7020b987d316c2076c2a6f439a1140f9
array (
'Core\\' => 5,
'CoreInterfaces\\' => 15,
'Composer\\Pcre\\' => 14,
'Complex\\' => 8,
'Clue\\StreamFilter\\' => 18,
),
@@ -140,10 +138,6 @@ class ComposerStaticInit7020b987d316c2076c2a6f439a1140f9
array (
0 => __DIR__ . '/..' . '/tectalic/openai/src',
),
'Symfony\\Polyfill\\Php80\\' =>
array (
0 => __DIR__ . '/..' . '/symfony/polyfill-php80',
),
'Symfony\\Polyfill\\Mbstring\\' =>
array (
0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring',
@@ -162,7 +156,7 @@ class ComposerStaticInit7020b987d316c2076c2a6f439a1140f9
),
'Psr\\Log\\' =>
array (
0 => __DIR__ . '/..' . '/psr/log/Psr/Log',
0 => __DIR__ . '/..' . '/psr/log/src',
),
'Psr\\Http\\Message\\' =>
array (
@@ -205,10 +199,6 @@ class ComposerStaticInit7020b987d316c2076c2a6f439a1140f9
array (
0 => __DIR__ . '/..' . '/nyholm/psr7/src',
),
'MyCLabs\\Enum\\' =>
array (
0 => __DIR__ . '/..' . '/myclabs/php-enum/src',
),
'Matrix\\' =>
array (
0 => __DIR__ . '/..' . '/markbaker/matrix/classes/src',
@@ -245,6 +235,10 @@ class ComposerStaticInit7020b987d316c2076c2a6f439a1140f9
array (
0 => __DIR__ . '/..' . '/apimatic/core-interfaces/src',
),
'Composer\\Pcre\\' =>
array (
0 => __DIR__ . '/..' . '/composer/pcre/src',
),
'Complex\\' =>
array (
0 => __DIR__ . '/..' . '/markbaker/complex/classes/src',
@@ -280,21 +274,16 @@ class ComposerStaticInit7020b987d316c2076c2a6f439a1140f9
);
public static $classMap = array (
'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'PhpToken' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
'Stringable' => __DIR__ . '/..' . '/myclabs/php-enum/stubs/Stringable.php',
'UnhandledMatchError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
'ValueError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/ValueError.php',
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit7020b987d316c2076c2a6f439a1140f9::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit7020b987d316c2076c2a6f439a1140f9::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticInit7020b987d316c2076c2a6f439a1140f9::$prefixesPsr0;
$loader->classMap = ComposerStaticInit7020b987d316c2076c2a6f439a1140f9::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit2bc4f313dba415539e266f7ac2c87dcd::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit2bc4f313dba415539e266f7ac2c87dcd::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticInit2bc4f313dba415539e266f7ac2c87dcd::$prefixesPsr0;
$loader->classMap = ComposerStaticInit2bc4f313dba415539e266f7ac2c87dcd::$classMap;
}, null, ClassLoader::class);
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
'name' => 'topthink/think',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '94b212fe7c6ec47113eeff7ab2125e0e1636d328',
'reference' => 'bbd690ca0f68c671ece05e82edc88ee7a68b82ed',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -11,9 +11,9 @@
),
'versions' => array(
'apimatic/core' => array(
'pretty_version' => '0.3.17',
'version' => '0.3.17.0',
'reference' => 'a48a583f686ee3786432b976c795a2817ec095b3',
'pretty_version' => '0.3.16',
'version' => '0.3.16.0',
'reference' => 'ae4ab4ca26a41be41718f33c703d67b7a767c07b',
'type' => 'library',
'install_path' => __DIR__ . '/../apimatic/core',
'aliases' => array(),
@@ -55,6 +55,15 @@
'aliases' => array(),
'dev_requirement' => false,
),
'composer/pcre' => array(
'pretty_version' => '3.3.2',
'version' => '3.3.2.0',
'reference' => 'b2bed4734f0cc156ee1fe9c0da2550420d99a21e',
'type' => 'library',
'install_path' => __DIR__ . '/./pcre',
'aliases' => array(),
'dev_requirement' => false,
),
'ezyang/htmlpurifier' => array(
'pretty_version' => 'v4.19.0',
'version' => '4.19.0.0',
@@ -83,18 +92,18 @@
'dev_requirement' => false,
),
'guzzlehttp/psr7' => array(
'pretty_version' => '2.9.0',
'version' => '2.9.0.0',
'reference' => '7d0ed42f28e42d61352a7a79de682e5e67fec884',
'pretty_version' => '2.8.0',
'version' => '2.8.0.0',
'reference' => '21dc724a0583619cd1652f673303492272778051',
'type' => 'library',
'install_path' => __DIR__ . '/../guzzlehttp/psr7',
'aliases' => array(),
'dev_requirement' => false,
),
'maennchen/zipstream-php' => array(
'pretty_version' => '2.1.0',
'version' => '2.1.0.0',
'reference' => 'c4c5803cc1f93df3d2448478ef79394a5981cc58',
'pretty_version' => '3.1.2',
'version' => '3.1.2.0',
'reference' => 'aeadcf5c412332eb426c0f9b4485f6accba2a99f',
'type' => 'library',
'install_path' => __DIR__ . '/../maennchen/zipstream-php',
'aliases' => array(),
@@ -118,15 +127,6 @@
'aliases' => array(),
'dev_requirement' => false,
),
'myclabs/php-enum' => array(
'pretty_version' => '1.8.5',
'version' => '1.8.5.0',
'reference' => 'e7be26966b7398204a234f8673fdad5ac6277802',
'type' => 'library',
'install_path' => __DIR__ . '/../myclabs/php-enum',
'aliases' => array(),
'dev_requirement' => false,
),
'nyholm/psr7' => array(
'pretty_version' => '1.8.2',
'version' => '1.8.2.0',
@@ -137,9 +137,9 @@
'dev_requirement' => false,
),
'paragonie/constant_time_encoding' => array(
'pretty_version' => 'v2.8.2',
'version' => '2.8.2.0',
'reference' => 'e30811f7bc69e4b5b6d5783e712c06c8eabf0226',
'pretty_version' => 'v3.1.3',
'version' => '3.1.3.0',
'reference' => 'd5b01a39b3415c2cd581d3bd3a3575c1ebbd8e77',
'type' => 'library',
'install_path' => __DIR__ . '/../paragonie/constant_time_encoding',
'aliases' => array(),
@@ -194,9 +194,9 @@
'dev_requirement' => false,
),
'php-http/message' => array(
'pretty_version' => '1.16.2',
'version' => '1.16.2.0',
'reference' => '06dd5e8562f84e641bf929bfe699ee0f5ce8080a',
'pretty_version' => '1.16.1',
'version' => '1.16.1.0',
'reference' => '5997f3289332c699fa2545c427826272498a2088',
'type' => 'library',
'install_path' => __DIR__ . '/../php-http/message',
'aliases' => array(),
@@ -209,9 +209,9 @@
),
),
'php-http/multipart-stream-builder' => array(
'pretty_version' => '1.4.2',
'version' => '1.4.2.0',
'reference' => '10086e6de6f53489cca5ecc45b6f468604d3460e',
'pretty_version' => '1.3.1',
'version' => '1.3.1.0',
'reference' => 'ed56da23b95949ae4747378bed8a5b61a2fdae24',
'type' => 'library',
'install_path' => __DIR__ . '/../php-http/multipart-stream-builder',
'aliases' => array(),
@@ -227,18 +227,18 @@
'dev_requirement' => false,
),
'phpmailer/phpmailer' => array(
'pretty_version' => 'v6.12.0',
'version' => '6.12.0.0',
'reference' => 'd1ac35d784bf9f5e61b424901d5a014967f15b12',
'pretty_version' => 'v6.11.1',
'version' => '6.11.1.0',
'reference' => 'd9e3b36b47f04b497a0164c5a20f92acb4593284',
'type' => 'library',
'install_path' => __DIR__ . '/../phpmailer/phpmailer',
'aliases' => array(),
'dev_requirement' => false,
),
'phpoffice/math' => array(
'pretty_version' => '0.3.0',
'version' => '0.3.0.0',
'reference' => 'fc31c8f57a7a81f962cbf389fd89f4d9d06fc99a',
'pretty_version' => '0.2.0',
'version' => '0.2.0.0',
'reference' => 'fc2eb6d1a61b058d5dac77197059db30ee3c8329',
'type' => 'library',
'install_path' => __DIR__ . '/../phpoffice/math',
'aliases' => array(),
@@ -254,18 +254,18 @@
'dev_requirement' => false,
),
'phpoffice/phpspreadsheet' => array(
'pretty_version' => '1.25.2',
'version' => '1.25.2.0',
'reference' => 'a317a09e7def49852400a4b3eca4a4b0790ceeb5',
'pretty_version' => '1.30.1',
'version' => '1.30.1.0',
'reference' => 'fa8257a579ec623473eabfe49731de5967306c4c',
'type' => 'library',
'install_path' => __DIR__ . '/../phpoffice/phpspreadsheet',
'aliases' => array(),
'dev_requirement' => false,
),
'phpoffice/phpword' => array(
'pretty_version' => '1.4.0',
'version' => '1.4.0.0',
'reference' => '6d75328229bc93790b37e93741adf70646cea958',
'pretty_version' => '1.3.0',
'version' => '1.3.0.0',
'reference' => '8392134ce4b5dba65130ba956231a1602b848b7f',
'type' => 'library',
'install_path' => __DIR__ . '/../phpoffice/phpword',
'aliases' => array(),
@@ -297,9 +297,9 @@
),
),
'psr/http-factory' => array(
'pretty_version' => '1.1.0',
'version' => '1.1.0.0',
'reference' => '2b4765fddfe3b508ac62f829e852b1501d3f6e8a',
'pretty_version' => '1.0.2',
'version' => '1.0.2.0',
'reference' => 'e616d01114759c4c489f93b099585439f795fe35',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/http-factory',
'aliases' => array(),
@@ -313,9 +313,9 @@
),
),
'psr/http-message' => array(
'pretty_version' => '1.1',
'version' => '1.1.0.0',
'reference' => 'cb6ce4845ce34a8ad9e68117c10ee90a29919eba',
'pretty_version' => '2.0',
'version' => '2.0.0.0',
'reference' => '402d35bcb92c70c026d1a6a9883f06b2ead23d71',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/http-message',
'aliases' => array(),
@@ -329,18 +329,18 @@
),
),
'psr/log' => array(
'pretty_version' => '1.1.4',
'version' => '1.1.4.0',
'reference' => 'd49695b909c3b7628b6289db5479a1c204601f11',
'pretty_version' => '3.0.1',
'version' => '3.0.1.0',
'reference' => '79dff0b268932c640297f5208d6298f71855c03e',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/log',
'aliases' => array(),
'dev_requirement' => false,
),
'psr/simple-cache' => array(
'pretty_version' => '1.0.1',
'version' => '1.0.1.0',
'reference' => '408d5eafb83c57f6365a3ca330ff23aa4a5fa39b',
'pretty_version' => '3.0.0',
'version' => '3.0.0.0',
'reference' => '764e0b3939f5ca87cb904f570ef9be2d78a07865',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/simple-cache',
'aliases' => array(),
@@ -365,41 +365,32 @@
'dev_requirement' => false,
),
'symfony/deprecation-contracts' => array(
'pretty_version' => 'v2.5.4',
'version' => '2.5.4.0',
'reference' => '605389f2a7e5625f273b53960dc46aeaf9c62918',
'pretty_version' => 'v3.6.0',
'version' => '3.6.0.0',
'reference' => '63afe740e99a13ba87ec199bb07bbdee937a5b62',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/deprecation-contracts',
'aliases' => array(),
'dev_requirement' => false,
),
'symfony/http-foundation' => array(
'pretty_version' => 'v5.4.50',
'version' => '5.4.50.0',
'reference' => '1a0706e8b8041046052ea2695eb8aeee04f97609',
'pretty_version' => 'v8.0.1',
'version' => '8.0.1.0',
'reference' => '3690740e2e8b19d877f20d4f10b7a489cddf0fe2',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/http-foundation',
'aliases' => array(),
'dev_requirement' => false,
),
'symfony/polyfill-mbstring' => array(
'pretty_version' => 'v1.37.0',
'version' => '1.37.0.0',
'reference' => '6a21eb99c6973357967f6ce3708cd55a6bec6315',
'pretty_version' => 'v1.32.0',
'version' => '1.32.0.0',
'reference' => '6d857f4d76bd4b343eac26d6b539585d2bc56493',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-mbstring',
'aliases' => array(),
'dev_requirement' => false,
),
'symfony/polyfill-php80' => array(
'pretty_version' => 'v1.37.0',
'version' => '1.37.0.0',
'reference' => 'dfb55726c3a76ea3b6459fcfda1ec2d80a682411',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-php80',
'aliases' => array(),
'dev_requirement' => false,
),
'tectalic/openai' => array(
'pretty_version' => 'v1.6.0',
'version' => '1.6.0.0',
@@ -421,7 +412,7 @@
'topthink/think' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '94b212fe7c6ec47113eeff7ab2125e0e1636d328',
'reference' => 'bbd690ca0f68c671ece05e82edc88ee7a68b82ed',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -437,18 +428,18 @@
'dev_requirement' => false,
),
'topthink/think-helper' => array(
'pretty_version' => 'v3.1.12',
'version' => '3.1.12.0',
'reference' => 'fe277121112a8f1c872e169a733ca80bb11c4acb',
'pretty_version' => 'v3.1.11',
'version' => '3.1.11.0',
'reference' => '1d6ada9b9f3130046bf6922fe1bd159c8d88a33c',
'type' => 'library',
'install_path' => __DIR__ . '/../topthink/think-helper',
'aliases' => array(),
'dev_requirement' => false,
),
'topthink/think-image' => array(
'pretty_version' => 'v1.0.8',
'version' => '1.0.8.0',
'reference' => 'd1d748cbb2fe2f29fca6138cf96cb8b5113892f1',
'pretty_version' => 'v1.0.7',
'version' => '1.0.7.0',
'reference' => '8586cf47f117481c6d415b20f7dedf62e79d5512',
'type' => 'library',
'install_path' => __DIR__ . '/../topthink/think-image',
'aliases' => array(),

View File

@@ -1,25 +0,0 @@
<?php
// platform_check.php @generated by Composer
$issues = array();
if (!(PHP_VERSION_ID >= 70300)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.3.0". You are running ' . PHP_VERSION . '.';
}
if ($issues) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
} elseif (!headers_sent()) {
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
}
}
throw new \RuntimeException(
'Composer detected issues in your platform: ' . implode(' ', $issues)
);
}

View File

@@ -48,7 +48,7 @@ This software is distributed under the [LGPL 2.1](https://www.gnu.org/licenses/o
PHPMailer is available on [Packagist](https://packagist.org/packages/phpmailer/phpmailer) (using semantic versioning), and installation via [Composer](https://getcomposer.org) is the recommended way to install PHPMailer. Just add this line to your `composer.json` file:
```json
"phpmailer/phpmailer": "^6.12.0"
"phpmailer/phpmailer": "^6.11.1"
```
or run

View File

@@ -1 +1 @@
6.12.0
6.11.1

View File

@@ -49,14 +49,15 @@
},
"suggest": {
"decomplexity/SendOauth2": "Adapter for using XOAUTH2 authentication",
"ext-imap": "Needed to support advanced email address parsing according to RFC822",
"ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses",
"ext-openssl": "Needed for secure SMTP sending and DKIM signing",
"greew/oauth2-azure-provider": "Needed for Microsoft Azure XOAUTH2 authentication",
"hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication",
"league/oauth2-google": "Needed for Google XOAUTH2 authentication",
"psr/log": "For optional PSR-3 debug logging",
"thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication",
"symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)"
"symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)",
"thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication"
},
"autoload": {
"psr-4": {
@@ -71,6 +72,7 @@
"license": "LGPL-2.1-only",
"scripts": {
"check": "./vendor/bin/phpcs",
"style": "./vendor/bin/phpcbf",
"test": "./vendor/bin/phpunit --no-coverage",
"coverage": "./vendor/bin/phpunit",
"lint": [

View File

@@ -9,7 +9,7 @@
*/
$PHPMAILER_LANG['authenticate'] = 'Error SMTP: Imposible autentificar.';
$PHPMAILER_LANG['buggy_php'] = 'Tu versión de PHP está afectada por un bug que puede resultar en mensajes corruptos. Para arreglarlo, cambia a enviar usando SMTP, deshabilita la opción mail.add_x_header en tu php.ini, cambia a MacOS o Linux, o actualiza tu PHP a la versión 7.0.17+ o 7.1.3+.';
$PHPMAILER_LANG['buggy_php'] = 'Tu versión de PHP ha sido afectada por un bug que puede resultar en mensajes corruptos. Para arreglarlo, cambia a enviar usando SMTP, deshabilita la opción mail.add_x_header en tu php.ini, cambia a MacOS o Linux, o actualiza tu PHP a la versión 7.0.17+ o 7.1.3+.';
$PHPMAILER_LANG['connect_host'] = 'Error SMTP: Imposible conectar al servidor SMTP.';
$PHPMAILER_LANG['data_not_accepted'] = 'Error SMTP: Datos no aceptados.';
$PHPMAILER_LANG['empty_message'] = 'El cuerpo del mensaje está vacío.';
@@ -18,7 +18,7 @@ $PHPMAILER_LANG['execute'] = 'Imposible ejecutar: ';
$PHPMAILER_LANG['extension_missing'] = 'Extensión faltante: ';
$PHPMAILER_LANG['file_access'] = 'Imposible acceder al archivo: ';
$PHPMAILER_LANG['file_open'] = 'Error de Archivo: Imposible abrir el archivo: ';
$PHPMAILER_LANG['from_failed'] = 'La(s) siguiente(s) direcciones de remitente fallaron: ';
$PHPMAILER_LANG['from_failed'] = 'La siguiente dirección de remitente falló: ';
$PHPMAILER_LANG['instantiate'] = 'Imposible crear una instancia de la función Mail.';
$PHPMAILER_LANG['invalid_address'] = 'Imposible enviar: dirección de email inválido: ';
$PHPMAILER_LANG['invalid_header'] = 'Nombre o valor de encabezado no válido';
@@ -34,3 +34,5 @@ $PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP Connect() falló.';
$PHPMAILER_LANG['smtp_detail'] = 'Detalle: ';
$PHPMAILER_LANG['smtp_error'] = 'Error del servidor SMTP: ';
$PHPMAILER_LANG['variable_set'] = 'No se pudo configurar la variable: ';
$PHPMAILER_LANG['imap_recommended'] = 'No se recomienda usar el analizador de direcciones simplificado. Instala la extensión IMAP de PHP para un análisis RFC822 más completo.';
$PHPMAILER_LANG['deprecated_argument'] = 'El argumento $useimap ha quedado obsoleto';

View File

@@ -561,9 +561,9 @@ class PHPMailer
* string $body the email body
* string $from email address of sender
* string $extra extra information of possible use
* "smtp_transaction_id' => last smtp transaction id
* 'smtp_transaction_id' => last smtp transaction id
*
* @var string
* @var callable|callable-string
*/
public $action_function = '';
@@ -711,7 +711,7 @@ class PHPMailer
*
* @var array
*/
protected $language = [];
protected static $language = [];
/**
* The number of errors encountered.
@@ -768,7 +768,7 @@ class PHPMailer
*
* @var string
*/
const VERSION = '6.12.0';
const VERSION = '6.11.1';
/**
* Error severity: message only, continue processing.
@@ -1102,7 +1102,7 @@ class PHPMailer
//At-sign is missing.
$error_message = sprintf(
'%s (%s): %s',
$this->lang('invalid_address'),
self::lang('invalid_address'),
$kind,
$address
);
@@ -1187,7 +1187,7 @@ class PHPMailer
if (!in_array($kind, ['to', 'cc', 'bcc', 'Reply-To'])) {
$error_message = sprintf(
'%s: %s',
$this->lang('Invalid recipient kind'),
self::lang('Invalid recipient kind'),
$kind
);
$this->setError($error_message);
@@ -1201,7 +1201,7 @@ class PHPMailer
if (!static::validateAddress($address)) {
$error_message = sprintf(
'%s (%s): %s',
$this->lang('invalid_address'),
self::lang('invalid_address'),
$kind,
$address
);
@@ -1220,12 +1220,16 @@ class PHPMailer
return true;
}
} elseif (!array_key_exists(strtolower($address), $this->ReplyTo)) {
$this->ReplyTo[strtolower($address)] = [$address, $name];
} else {
foreach ($this->ReplyTo as $replyTo) {
if (0 === strcasecmp($replyTo[0], $address)) {
return false;
}
}
$this->ReplyTo[] = [$address, $name];
return true;
}
return false;
}
@@ -1238,15 +1242,18 @@ class PHPMailer
* @see https://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation
*
* @param string $addrstr The address list string
* @param bool $useimap Whether to use the IMAP extension to parse the list
* @param null $useimap Deprecated argument since 6.11.0.
* @param string $charset The charset to use when decoding the address list string.
*
* @return array
*/
public static function parseAddresses($addrstr, $useimap = true, $charset = self::CHARSET_ISO88591)
public static function parseAddresses($addrstr, $useimap = null, $charset = self::CHARSET_ISO88591)
{
if ($useimap !== null) {
trigger_error(self::lang('deprecated_argument'), E_USER_DEPRECATED);
}
$addresses = [];
if ($useimap && function_exists('imap_rfc822_parse_adrlist')) {
if (function_exists('imap_rfc822_parse_adrlist')) {
//Use this built-in parser if it's available
$list = imap_rfc822_parse_adrlist($addrstr, '');
// Clear any potential IMAP errors to get rid of notices being thrown at end of script.
@@ -1256,20 +1263,13 @@ class PHPMailer
'.SYNTAX-ERROR.' !== $address->host &&
static::validateAddress($address->mailbox . '@' . $address->host)
) {
//Decode the name part if it's present and encoded
//Decode the name part if it's present and maybe encoded
if (
property_exists($address, 'personal') &&
//Check for a Mbstring constant rather than using extension_loaded, which is sometimes disabled
defined('MB_CASE_UPPER') &&
preg_match('/^=\?.*\?=$/s', $address->personal)
property_exists($address, 'personal')
&& is_string($address->personal)
&& $address->personal !== ''
) {
$origCharset = mb_internal_encoding();
mb_internal_encoding($charset);
//Undo any RFC2047-encoded spaces-as-underscores
$address->personal = str_replace('_', '=20', $address->personal);
//Decode the name
$address->personal = mb_decode_mimeheader($address->personal);
mb_internal_encoding($origCharset);
$address->personal = static::decodeHeader($address->personal, $charset);
}
$addresses[] = [
@@ -1280,40 +1280,51 @@ class PHPMailer
}
} else {
//Use this simpler parser
$list = explode(',', $addrstr);
foreach ($list as $address) {
$address = trim($address);
//Is there a separate name part?
if (strpos($address, '<') === false) {
//No separate name, just use the whole thing
if (static::validateAddress($address)) {
$addresses[] = [
'name' => '',
'address' => $address,
];
}
} else {
list($name, $email) = explode('<', $address);
$email = trim(str_replace('>', '', $email));
$name = trim($name);
if (static::validateAddress($email)) {
//Check for a Mbstring constant rather than using extension_loaded, which is sometimes disabled
//If this name is encoded, decode it
if (defined('MB_CASE_UPPER') && preg_match('/^=\?.*\?=$/s', $name)) {
$origCharset = mb_internal_encoding();
mb_internal_encoding($charset);
//Undo any RFC2047-encoded spaces-as-underscores
$name = str_replace('_', '=20', $name);
//Decode the name
$name = mb_decode_mimeheader($name);
mb_internal_encoding($origCharset);
}
$addresses[] = [
//Remove any surrounding quotes and spaces from the name
'name' => trim($name, '\'" '),
'address' => $email,
];
}
$addresses = static::parseSimplerAddresses($addrstr, $charset);
}
return $addresses;
}
/**
* Parse a string containing one or more RFC822-style comma-separated email addresses
* with the form "display name <address>" into an array of name/address pairs.
* Uses a simpler parser that does not require the IMAP extension but doesnt support
* the full RFC822 spec. For full RFC822 support, use the PHP IMAP extension.
*
* @param string $addrstr The address list string
* @param string $charset The charset to use when decoding the address list string.
*
* @return array
*/
protected static function parseSimplerAddresses($addrstr, $charset)
{
// Emit a runtime notice to recommend using the IMAP extension for full RFC822 parsing
trigger_error(self::lang('imap_recommended'), E_USER_NOTICE);
$addresses = [];
$list = explode(',', $addrstr);
foreach ($list as $address) {
$address = trim($address);
//Is there a separate name part?
if (strpos($address, '<') === false) {
//No separate name, just use the whole thing
if (static::validateAddress($address)) {
$addresses[] = [
'name' => '',
'address' => $address,
];
}
} else {
$parsed = static::parseEmailString($address);
$email = $parsed['email'];
if (static::validateAddress($email)) {
$name = static::decodeHeader($parsed['name'], $charset);
$addresses[] = [
//Remove any surrounding quotes and spaces from the name
'name' => trim($name, '\'" '),
'address' => $email,
];
}
}
}
@@ -1321,6 +1332,42 @@ class PHPMailer
return $addresses;
}
/**
* Parse a string containing an email address with an optional name
* and divide it into a name and email address.
*
* @param string $input The email with name.
*
* @return array{name: string, email: string}
*/
private static function parseEmailString($input)
{
$input = trim((string)$input);
if ($input === '') {
return ['name' => '', 'email' => ''];
}
$pattern = '/^\s*(?:(?:"([^"]*)"|\'([^\']*)\'|([^<]*?))\s*)?<\s*([^>]+)\s*>\s*$/';
if (preg_match($pattern, $input, $matches)) {
$name = '';
// Double quotes including special scenarios.
if (isset($matches[1]) && $matches[1] !== '') {
$name = $matches[1];
// Single quotes including special scenarios.
} elseif (isset($matches[2]) && $matches[2] !== '') {
$name = $matches[2];
// Simplest scenario, name and email are in the format "Name <email>".
} elseif (isset($matches[3])) {
$name = trim($matches[3]);
}
return ['name' => $name, 'email' => trim($matches[4])];
}
return ['name' => '', 'email' => $input];
}
/**
* Set the From and FromName properties.
*
@@ -1334,6 +1381,10 @@ class PHPMailer
*/
public function setFrom($address, $name = '', $auto = true)
{
if (is_null($name)) {
//Helps avoid a deprecation warning in the preg_replace() below
$name = '';
}
$address = trim((string)$address);
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
//Don't validate now addresses with IDN. Will be done in send().
@@ -1345,7 +1396,7 @@ class PHPMailer
) {
$error_message = sprintf(
'%s (From): %s',
$this->lang('invalid_address'),
self::lang('invalid_address'),
$address
);
$this->setError($error_message);
@@ -1601,7 +1652,7 @@ class PHPMailer
&& ini_get('mail.add_x_header') === '1'
&& stripos(PHP_OS, 'WIN') === 0
) {
trigger_error($this->lang('buggy_php'), E_USER_WARNING);
trigger_error(self::lang('buggy_php'), E_USER_WARNING);
}
try {
@@ -1631,7 +1682,7 @@ class PHPMailer
call_user_func_array([$this, 'addAnAddress'], $params);
}
if (count($this->to) + count($this->cc) + count($this->bcc) < 1) {
throw new Exception($this->lang('provide_address'), self::STOP_CRITICAL);
throw new Exception(self::lang('provide_address'), self::STOP_CRITICAL);
}
//Validate From, Sender, and ConfirmReadingTo addresses
@@ -1648,7 +1699,7 @@ class PHPMailer
if (!static::validateAddress($this->{$address_kind})) {
$error_message = sprintf(
'%s (%s): %s',
$this->lang('invalid_address'),
self::lang('invalid_address'),
$address_kind,
$this->{$address_kind}
);
@@ -1670,7 +1721,7 @@ class PHPMailer
$this->setMessageType();
//Refuse to send an empty message unless we are specifically allowing it
if (!$this->AllowEmpty && empty($this->Body)) {
throw new Exception($this->lang('empty_message'), self::STOP_CRITICAL);
throw new Exception(self::lang('empty_message'), self::STOP_CRITICAL);
}
//Trim subject consistently
@@ -1809,8 +1860,10 @@ class PHPMailer
} else {
$sendmailFmt = '%s -oi -f%s -t';
}
} elseif ($this->Mailer === 'qmail') {
$sendmailFmt = '%s';
} else {
//allow sendmail to choose a default envelope sender. It may
//Allow sendmail to choose a default envelope sender. It may
//seem preferable to force it to use the From header as with
//SMTP, but that introduces new problems (see
//<https://github.com/PHPMailer/PHPMailer/issues/2298>), and
@@ -1828,33 +1881,35 @@ class PHPMailer
foreach ($this->SingleToArray as $toAddr) {
$mail = @popen($sendmail, 'w');
if (!$mail) {
throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
throw new Exception(self::lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
$this->edebug("To: {$toAddr}");
fwrite($mail, 'To: ' . $toAddr . "\n");
fwrite($mail, $header);
fwrite($mail, $body);
$result = pclose($mail);
$addrinfo = static::parseAddresses($toAddr, true, $this->CharSet);
$this->doCallback(
($result === 0),
[[$addrinfo['address'], $addrinfo['name']]],
$this->cc,
$this->bcc,
$this->Subject,
$body,
$this->From,
[]
);
$addrinfo = static::parseAddresses($toAddr, null, $this->CharSet);
foreach ($addrinfo as $addr) {
$this->doCallback(
($result === 0),
[[$addr['address'], $addr['name']]],
$this->cc,
$this->bcc,
$this->Subject,
$body,
$this->From,
[]
);
}
$this->edebug("Result: " . ($result === 0 ? 'true' : 'false'));
if (0 !== $result) {
throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
throw new Exception(self::lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
}
} else {
$mail = @popen($sendmail, 'w');
if (!$mail) {
throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
throw new Exception(self::lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
fwrite($mail, $header);
fwrite($mail, $body);
@@ -1871,7 +1926,7 @@ class PHPMailer
);
$this->edebug("Result: " . ($result === 0 ? 'true' : 'false'));
if (0 !== $result) {
throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
throw new Exception(self::lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
}
@@ -2010,17 +2065,19 @@ class PHPMailer
if ($this->SingleTo && count($toArr) > 1) {
foreach ($toArr as $toAddr) {
$result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
$addrinfo = static::parseAddresses($toAddr, true, $this->CharSet);
$this->doCallback(
$result,
[[$addrinfo['address'], $addrinfo['name']]],
$this->cc,
$this->bcc,
$this->Subject,
$body,
$this->From,
[]
);
$addrinfo = static::parseAddresses($toAddr, null, $this->CharSet);
foreach ($addrinfo as $addr) {
$this->doCallback(
$result,
[[$addr['address'], $addr['name']]],
$this->cc,
$this->bcc,
$this->Subject,
$body,
$this->From,
[]
);
}
}
} else {
$result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
@@ -2030,7 +2087,7 @@ class PHPMailer
ini_set('sendmail_from', $old_from);
}
if (!$result) {
throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL);
throw new Exception(self::lang('instantiate'), self::STOP_CRITICAL);
}
return true;
@@ -2116,12 +2173,12 @@ class PHPMailer
$header = static::stripTrailingWSP($header) . static::$LE . static::$LE;
$bad_rcpt = [];
if (!$this->smtpConnect($this->SMTPOptions)) {
throw new Exception($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
throw new Exception(self::lang('smtp_connect_failed'), self::STOP_CRITICAL);
}
//If we have recipient addresses that need Unicode support,
//but the server doesn't support it, stop here
if ($this->UseSMTPUTF8 && !$this->smtp->getServerExt('SMTPUTF8')) {
throw new Exception($this->lang('no_smtputf8'), self::STOP_CRITICAL);
throw new Exception(self::lang('no_smtputf8'), self::STOP_CRITICAL);
}
//Sender already validated in preSend()
if ('' === $this->Sender) {
@@ -2133,7 +2190,7 @@ class PHPMailer
$this->smtp->xclient($this->SMTPXClient);
}
if (!$this->smtp->mail($smtp_from)) {
$this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
$this->setError(self::lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
throw new Exception($this->ErrorInfo, self::STOP_CRITICAL);
}
@@ -2155,7 +2212,7 @@ class PHPMailer
//Only send the DATA command if we have viable recipients
if ((count($this->all_recipients) > count($bad_rcpt)) && !$this->smtp->data($header . $body)) {
throw new Exception($this->lang('data_not_accepted'), self::STOP_CRITICAL);
throw new Exception(self::lang('data_not_accepted'), self::STOP_CRITICAL);
}
$smtp_transaction_id = $this->smtp->getLastTransactionID();
@@ -2186,7 +2243,7 @@ class PHPMailer
foreach ($bad_rcpt as $bad) {
$errstr .= $bad['to'] . ': ' . $bad['error'];
}
throw new Exception($this->lang('recipients_failed') . $errstr, self::STOP_CONTINUE);
throw new Exception(self::lang('recipients_failed') . $errstr, self::STOP_CONTINUE);
}
return true;
@@ -2240,7 +2297,7 @@ class PHPMailer
$hostinfo
)
) {
$this->edebug($this->lang('invalid_hostentry') . ' ' . trim($hostentry));
$this->edebug(self::lang('invalid_hostentry') . ' ' . trim($hostentry));
//Not a valid host entry
continue;
}
@@ -2252,7 +2309,7 @@ class PHPMailer
//Check the host name is a valid name or IP address before trying to use it
if (!static::isValidHost($hostinfo[2])) {
$this->edebug($this->lang('invalid_host') . ' ' . $hostinfo[2]);
$this->edebug(self::lang('invalid_host') . ' ' . $hostinfo[2]);
continue;
}
$prefix = '';
@@ -2272,7 +2329,7 @@ class PHPMailer
if (static::ENCRYPTION_STARTTLS === $secure || static::ENCRYPTION_SMTPS === $secure) {
//Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
if (!$sslext) {
throw new Exception($this->lang('extension_missing') . 'openssl', self::STOP_CRITICAL);
throw new Exception(self::lang('extension_missing') . 'openssl', self::STOP_CRITICAL);
}
}
$host = $hostinfo[2];
@@ -2324,7 +2381,7 @@ class PHPMailer
$this->oauth
)
) {
throw new Exception($this->lang('authenticate'));
throw new Exception(self::lang('authenticate'));
}
return true;
@@ -2374,7 +2431,7 @@ class PHPMailer
*
* @return bool Returns true if the requested language was loaded, false otherwise.
*/
public function setLanguage($langcode = 'en', $lang_path = '')
public static function setLanguage($langcode = 'en', $lang_path = '')
{
//Backwards compatibility for renamed language codes
$renamed_langcodes = [
@@ -2423,6 +2480,9 @@ class PHPMailer
'smtp_error' => 'SMTP server error: ',
'variable_set' => 'Cannot set or reset variable: ',
'no_smtputf8' => 'Server does not support SMTPUTF8 needed to send to Unicode addresses',
'imap_recommended' => 'Using simplified address parser is not recommended. ' .
'Install the PHP IMAP extension for full RFC822 parsing.',
'deprecated_argument' => 'Argument $useimap is deprecated',
];
if (empty($lang_path)) {
//Calculate an absolute path so it can work if CWD is not here
@@ -2489,7 +2549,7 @@ class PHPMailer
}
}
}
$this->language = $PHPMAILER_LANG;
self::$language = $PHPMAILER_LANG;
return $foundlang; //Returns false if language not found
}
@@ -2501,11 +2561,11 @@ class PHPMailer
*/
public function getTranslations()
{
if (empty($this->language)) {
$this->setLanguage(); // Set the default language.
if (empty(self::$language)) {
self::setLanguage(); // Set the default language.
}
return $this->language;
return self::$language;
}
/**
@@ -2928,10 +2988,6 @@ class PHPMailer
//Create unique IDs and preset boundaries
$this->setBoundaries();
if ($this->sign_key_file) {
$body .= $this->getMailMIME() . static::$LE;
}
$this->setWordWrap();
$bodyEncoding = $this->Encoding;
@@ -2963,6 +3019,12 @@ class PHPMailer
if (static::ENCODING_BASE64 !== $altBodyEncoding && static::hasLineLongerThanMax($this->AltBody)) {
$altBodyEncoding = static::ENCODING_QUOTED_PRINTABLE;
}
if ($this->sign_key_file) {
$this->Encoding = $bodyEncoding;
$body .= $this->getMailMIME() . static::$LE;
}
//Use this as a preamble in all multipart message types
$mimepre = '';
switch ($this->message_type) {
@@ -3144,12 +3206,12 @@ class PHPMailer
if ($this->isError()) {
$body = '';
if ($this->exceptions) {
throw new Exception($this->lang('empty_message'), self::STOP_CRITICAL);
throw new Exception(self::lang('empty_message'), self::STOP_CRITICAL);
}
} elseif ($this->sign_key_file) {
try {
if (!defined('PKCS7_TEXT')) {
throw new Exception($this->lang('extension_missing') . 'openssl');
throw new Exception(self::lang('extension_missing') . 'openssl');
}
$file = tempnam(sys_get_temp_dir(), 'srcsign');
@@ -3187,7 +3249,7 @@ class PHPMailer
$body = $parts[1];
} else {
@unlink($signed);
throw new Exception($this->lang('signing') . openssl_error_string());
throw new Exception(self::lang('signing') . openssl_error_string());
}
} catch (Exception $exc) {
$body = '';
@@ -3332,7 +3394,7 @@ class PHPMailer
) {
try {
if (!static::fileIsAccessible($path)) {
throw new Exception($this->lang('file_access') . $path, self::STOP_CONTINUE);
throw new Exception(self::lang('file_access') . $path, self::STOP_CONTINUE);
}
//If a MIME type is not specified, try to work it out from the file name
@@ -3345,7 +3407,7 @@ class PHPMailer
$name = $filename;
}
if (!$this->validateEncoding($encoding)) {
throw new Exception($this->lang('encoding') . $encoding);
throw new Exception(self::lang('encoding') . $encoding);
}
$this->attachment[] = [
@@ -3506,11 +3568,11 @@ class PHPMailer
{
try {
if (!static::fileIsAccessible($path)) {
throw new Exception($this->lang('file_open') . $path, self::STOP_CONTINUE);
throw new Exception(self::lang('file_open') . $path, self::STOP_CONTINUE);
}
$file_buffer = file_get_contents($path);
if (false === $file_buffer) {
throw new Exception($this->lang('file_open') . $path, self::STOP_CONTINUE);
throw new Exception(self::lang('file_open') . $path, self::STOP_CONTINUE);
}
$file_buffer = $this->encodeString($file_buffer, $encoding);
@@ -3563,9 +3625,9 @@ class PHPMailer
$encoded = $this->encodeQP($str);
break;
default:
$this->setError($this->lang('encoding') . $encoding);
$this->setError(self::lang('encoding') . $encoding);
if ($this->exceptions) {
throw new Exception($this->lang('encoding') . $encoding);
throw new Exception(self::lang('encoding') . $encoding);
}
break;
}
@@ -3671,6 +3733,42 @@ class PHPMailer
return trim(static::normalizeBreaks($encoded));
}
/**
* Decode an RFC2047-encoded header value
* Attempts multiple strategies so it works even when the mbstring extension is disabled.
*
* @param string $value The header value to decode
* @param string $charset The target charset to convert to, defaults to ISO-8859-1 for BC
*
* @return string The decoded header value
*/
public static function decodeHeader($value, $charset = self::CHARSET_ISO88591)
{
if (!is_string($value) || $value === '') {
return '';
}
// Detect the presence of any RFC2047 encoded-words
$hasEncodedWord = (bool) preg_match('/=\?.*\?=/s', $value);
if ($hasEncodedWord && defined('MB_CASE_UPPER')) {
$origCharset = mb_internal_encoding();
// Always decode to UTF-8 to provide a consistent, modern output encoding.
mb_internal_encoding($charset);
if (PHP_VERSION_ID < 80300) {
// Undo any RFC2047-encoded spaces-as-underscores.
$value = str_replace('_', '=20', $value);
} else {
// PHP 8.3+ already interprets underscores as spaces. Remove additional
// linear whitespace between adjacent encoded words to avoid double spacing.
$value = preg_replace('/(\?=)\s+(=\?)/', '$1$2', $value);
}
// Decode the header value
$value = mb_decode_mimeheader($value);
mb_internal_encoding($origCharset);
}
return $value;
}
/**
* Check if a string contains multi-byte characters.
*
@@ -3840,7 +3938,7 @@ class PHPMailer
}
if (!$this->validateEncoding($encoding)) {
throw new Exception($this->lang('encoding') . $encoding);
throw new Exception(self::lang('encoding') . $encoding);
}
//Append to $attachment array
@@ -3899,7 +3997,7 @@ class PHPMailer
) {
try {
if (!static::fileIsAccessible($path)) {
throw new Exception($this->lang('file_access') . $path, self::STOP_CONTINUE);
throw new Exception(self::lang('file_access') . $path, self::STOP_CONTINUE);
}
//If a MIME type is not specified, try to work it out from the file name
@@ -3908,7 +4006,7 @@ class PHPMailer
}
if (!$this->validateEncoding($encoding)) {
throw new Exception($this->lang('encoding') . $encoding);
throw new Exception(self::lang('encoding') . $encoding);
}
$filename = (string) static::mb_pathinfo($path, PATHINFO_BASENAME);
@@ -3974,7 +4072,7 @@ class PHPMailer
}
if (!$this->validateEncoding($encoding)) {
throw new Exception($this->lang('encoding') . $encoding);
throw new Exception(self::lang('encoding') . $encoding);
}
//Append to $attachment array
@@ -4231,7 +4329,7 @@ class PHPMailer
}
if (strpbrk($name . $value, "\r\n") !== false) {
if ($this->exceptions) {
throw new Exception($this->lang('invalid_header'));
throw new Exception(self::lang('invalid_header'));
}
return false;
@@ -4255,15 +4353,15 @@ class PHPMailer
if ('smtp' === $this->Mailer && null !== $this->smtp) {
$lasterror = $this->smtp->getError();
if (!empty($lasterror['error'])) {
$msg .= ' ' . $this->lang('smtp_error') . $lasterror['error'];
$msg .= ' ' . self::lang('smtp_error') . $lasterror['error'];
if (!empty($lasterror['detail'])) {
$msg .= ' ' . $this->lang('smtp_detail') . $lasterror['detail'];
$msg .= ' ' . self::lang('smtp_detail') . $lasterror['detail'];
}
if (!empty($lasterror['smtp_code'])) {
$msg .= ' ' . $this->lang('smtp_code') . $lasterror['smtp_code'];
$msg .= ' ' . self::lang('smtp_code') . $lasterror['smtp_code'];
}
if (!empty($lasterror['smtp_code_ex'])) {
$msg .= ' ' . $this->lang('smtp_code_ex') . $lasterror['smtp_code_ex'];
$msg .= ' ' . self::lang('smtp_code_ex') . $lasterror['smtp_code_ex'];
}
}
}
@@ -4388,21 +4486,21 @@ class PHPMailer
*
* @return string
*/
protected function lang($key)
protected static function lang($key)
{
if (count($this->language) < 1) {
$this->setLanguage(); //Set the default language
if (count(self::$language) < 1) {
self::setLanguage(); //Set the default language
}
if (array_key_exists($key, $this->language)) {
if (array_key_exists($key, self::$language)) {
if ('smtp_connect_failed' === $key) {
//Include a link to troubleshooting docs on SMTP connection failure.
//This is by far the biggest cause of support questions
//but it's usually not PHPMailer's fault.
return $this->language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
return self::$language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
}
return $this->language[$key];
return self::$language[$key];
}
//Return the key as a fallback
@@ -4417,7 +4515,7 @@ class PHPMailer
*/
private function getSmtpErrorMessage($base_key)
{
$message = $this->lang($base_key);
$message = self::lang($base_key);
$error = $this->smtp->getError();
if (!empty($error['error'])) {
$message .= ' ' . $error['error'];
@@ -4461,7 +4559,7 @@ class PHPMailer
//Ensure name is not empty, and that neither name nor value contain line breaks
if (empty($name) || strpbrk($name . $value, "\r\n") !== false) {
if ($this->exceptions) {
throw new Exception($this->lang('invalid_header'));
throw new Exception(self::lang('invalid_header'));
}
return false;
@@ -4854,7 +4952,7 @@ class PHPMailer
return true;
}
$this->setError($this->lang('variable_set') . $name);
$this->setError(self::lang('variable_set') . $name);
return false;
}
@@ -4992,7 +5090,7 @@ class PHPMailer
{
if (!defined('PKCS7_TEXT')) {
if ($this->exceptions) {
throw new Exception($this->lang('extension_missing') . 'openssl');
throw new Exception(self::lang('extension_missing') . 'openssl');
}
return '';

View File

@@ -46,7 +46,7 @@ class POP3
*
* @var string
*/
const VERSION = '6.12.0';
const VERSION = '6.11.1';
/**
* Default POP3 port number.

View File

@@ -35,7 +35,7 @@ class SMTP
*
* @var string
*/
const VERSION = '6.12.0';
const VERSION = '6.11.1';
/**
* SMTP line break constant.
@@ -205,6 +205,7 @@ class SMTP
'Haraka' => '/[\d]{3} Message Queued \((.*)\)/',
'ZoneMTA' => '/[\d]{3} Message queued as (.*)/',
'Mailjet' => '/[\d]{3} OK queued as (.*)/',
'Gsmtp' => '/[\d]{3} 2\.0\.0 OK (.*) - gsmtp/',
];
/**
@@ -633,10 +634,41 @@ class SMTP
return false;
}
$oauth = $OAuth->getOauth64();
//Start authentication
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
return false;
/*
* An SMTP command line can have a maximum length of 512 bytes, including the command name,
* so the base64-encoded OAUTH token has a maximum length of:
* 512 - 13 (AUTH XOAUTH2) - 2 (CRLF) = 497 bytes
* If the token is longer than that, the command and the token must be sent separately as described in
* https://www.rfc-editor.org/rfc/rfc4954#section-4
*/
if ($oauth === '') {
//Sending an empty auth token is legitimate, but it must be encoded as '='
//to indicate it's not a 2-part command
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 =', 235)) {
return false;
}
} elseif (strlen($oauth) <= 497) {
//Authenticate using a token in the initial-response part
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
return false;
}
} else {
//The token is too long, so we need to send it in two parts.
//Send the auth command without a token and expect a 334
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2', 334)) {
return false;
}
//Send the token
if (!$this->sendCommand('OAuth TOKEN', $oauth, [235, 334])) {
return false;
}
//If the server answers with 334, send an empty line and wait for a 235
if (
substr($this->last_reply, 0, 3) === '334'
&& $this->sendCommand('AUTH End', '', 235)
) {
return false;
}
}
break;
default:
@@ -1309,7 +1341,16 @@ class SMTP
//stream_select returns false when the `select` system call is interrupted
//by an incoming signal, try the select again
if (stripos($message, 'interrupted system call') !== false) {
if (
stripos($message, 'interrupted system call') !== false ||
(
// on applications with a different locale than english, the message above is not found because
// it's translated. So we also check for the SOCKET_EINTR constant which is defined under
// Windows and UNIX-like platforms (if available on the platform).
defined('SOCKET_EINTR') &&
stripos($message, 'stream_select(): Unable to select [' . SOCKET_EINTR . ']') !== false
)
) {
$this->edebug(
'SMTP -> get_lines(): retrying stream_select',
self::DEBUG_LOWLEVEL

View File

@@ -45,7 +45,6 @@ jobs:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
@@ -76,7 +75,6 @@ jobs:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2

View File

@@ -48,7 +48,7 @@ Math is an open source project licensed under the terms of [MIT](https://github.
| **Simple** | Fraction | :material-check: | :material-check: |
| | Superscript | :material-check: | |
| **Architectural** | Row | :material-check: | :material-check: |
| | Semantics | :material-check: | |
| | Semantics | | |
## Contributing

View File

@@ -57,9 +57,7 @@ nav:
- Writers: 'usage/writers.md'
- Credits: 'credits.md'
- Releases:
- '0.3.0 (WIP)': 'changes/0.3.0.md'
- '0.2.0': 'changes/0.2.0.md'
- '0.1.0': 'changes/0.1.0.md'
- '0.1.0 (WIP)': 'changes/0.1.0.md'
- Developers:
- 'Coveralls': 'https://coveralls.io/github/PHPOffice/Math'
- 'Code Coverage': 'coverage/index.html'

View File

@@ -10,7 +10,6 @@ use PhpOffice\Math\Element;
use PhpOffice\Math\Exception\InvalidInputException;
use PhpOffice\Math\Exception\NotImplementedException;
use PhpOffice\Math\Math;
use PhpOffice\Math\Reader\Security\XmlScanner;
class MathML implements ReaderInterface
{
@@ -23,17 +22,8 @@ class MathML implements ReaderInterface
/** @var DOMXPath */
private $xpath;
/** @var XmlScanner */
private $xmlScanner;
public function __construct()
{
$this->xmlScanner = XmlScanner::getInstance();
}
public function read(string $content): ?Math
{
$content = $this->xmlScanner->scan($content);
$content = str_replace(
[
'&InvisibleTimes;',
@@ -45,7 +35,7 @@ class MathML implements ReaderInterface
);
$this->dom = new DOMDocument();
$this->dom->loadXML($content);
$this->dom->loadXML($content, LIBXML_DTDLOAD);
$this->math = new Math();
$this->parseNode(null, $this->math);

View File

@@ -40,26 +40,6 @@ class MathML implements WriterInterface
{
$tagName = $this->getElementTagName($element);
// Element\AbstractGroupElement
if ($element instanceof Element\Semantics) {
$this->output->startElement($tagName);
// Write elements
foreach ($element->getElements() as $childElement) {
$this->writeElementItem($childElement);
}
// Write annotations
foreach ($element->getAnnotations() as $encoding => $annotation) {
$this->output->startElement('annotation');
$this->output->writeAttribute('encoding', $encoding);
$this->output->text($annotation);
$this->output->endElement();
}
$this->output->endElement();
return;
}
// Element\AbstractGroupElement
if ($element instanceof Element\AbstractGroupElement) {
$this->output->startElement($tagName);
@@ -141,9 +121,6 @@ class MathML implements WriterInterface
if ($element instanceof Element\Operator) {
return 'mo';
}
if ($element instanceof Element\Semantics) {
return 'semantics';
}
throw new NotImplementedException(sprintf(
'%s : The element of the class `%s` has no tag name',

View File

@@ -7,7 +7,6 @@ namespace Tests\PhpOffice\Math\Reader;
use PhpOffice\Math\Element;
use PhpOffice\Math\Exception\InvalidInputException;
use PhpOffice\Math\Exception\NotImplementedException;
use PhpOffice\Math\Exception\SecurityException;
use PhpOffice\Math\Math;
use PhpOffice\Math\Reader\MathML;
use PHPUnit\Framework\TestCase;
@@ -295,15 +294,4 @@ class MathMLTest extends TestCase
$reader = new MathML();
$math = $reader->read($content);
}
public function testReadSecurity(): void
{
$this->expectException(SecurityException::class);
$this->expectExceptionMessage('Detected use of ENTITY in XML, loading aborted to prevent XXE/XEE attacks');
$content = '<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE x SYSTEM "php://filter/convert.base64-decode/zlib.inflate/resource=data:,7Ztdb9owFIbv%2bRVZJ9armNjOZ2k7QUaL%2bRYO2nqFUnBFNQaMptP272cnNFuTsBbSskg1iATZzvGxn/ccX3A4fdfoecS7UsrK1A98hV5Rr9FVjlaz1UmlcnM7D9i6MlkufrB1AK79O2bqKltMllMWt96KL6ADwci7sJ4Yu0vr9/tlwKbqan27CPzrOXvevFGrbRvOGIseaCa7TAxok1x44xahXzQEcdKPKZPevap3RZw920I0VscWGLlU1efPsy0c5cbV1AoI7ZuOMCZW12nkcP9Q2%2bQObBNmL6ajg8s6xJqmJTrq5NIArX6zVk8Zcwwt4fPuLvHnbeBSvpdIQ6g93MvUv3CHqKNrmtEW4EYmCr5gDT5QzyNWE4x6xO1/aqQmgMhGYgaVDFUnScKltbFnaJoKHRuHK0L1pIkuaYselMe9cPUqRmm5C51u00kkhy1S3aBougkl7e4d6RGaTYeSehdCjAG/O/p%2bYfKyQsoLmgdlmsFYQFDjh6GWJyGE0ZfMX08EZtwNTdAYud7nLcksnwppA2UnqpCzgyDo1QadAU3vLOQZ82EHMxAi0KVcq7rzas5xD6AQoeqkYkgk02abukkJ/z%2bNvkj%2bjUy16Ba5d/S8anhBLwt44EgGkoFkIBlIBpKBZCAZSAaSgWQgGUgGkoFkIBlIBpKBZCAZSAaSgWQgGUgGxWOwW2nF7kt%2by7/Kb3ag2GUTUgBvXAAxiKxt4Is3sB4WniVrOvhwzB0CXerg5GN9esGRQv7RgQdMmMO9sIwtc/sIJUOCsY4ee7f7FIWu2Si4euKan8wg58nFsEIXxYGntgZqMog3Z2FrgPhgyzIOlsmijowqwb0jyMqMoGEbarqdOpP/iqFISMkSVFG1Z5p8f3OK%2bxAZ7gClpgUPg70rq0T2RIkcup/0newQ7NbcUXv/DPl4LL/N7hdfn2dp07pmd8v79YSdVVgwqcyWd8HC/8aOzkunf6r%2b2c8bpSxK/6uPmlf%2br/nSnyrHcduH99iqKiz7HwLxTLMgEM0QWUDjb3ji8NdHPslZmV%2bqR%2bfH56Xyxni1VGbV0m8=" []><foo></foo>M';
$reader = new MathML();
$math = $reader->read($content);
}
}

View File

@@ -80,35 +80,6 @@ class MathMLTest extends WriterTestCase
$this->assertIsSchemaMathMLValid($output);
}
public function testWriteSemantics(): void
{
$opTimes = new Element\Operator('&InvisibleTimes;');
$math = new Math();
$semantics = new Element\Semantics();
$semantics->add(new Element\Identifier('y'));
$semantics->addAnnotation('application/x-tex', ' y ');
$math->add($semantics);
$writer = new MathML();
$output = $writer->write($math);
$expected = '<?xml version="1.0" encoding="UTF-8"?>'
. PHP_EOL
. '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">'
. '<math xmlns="http://www.w3.org/1998/Math/MathML">'
. '<semantics>'
. '<mi>y</mi>'
. '<annotation encoding="application/x-tex"> y </annotation>'
. '</semantics>'
. '</math>'
. PHP_EOL;
$this->assertEquals($expected, $output);
$this->assertIsSchemaMathMLValid($output);
}
public function testWriteNotImplemented(): void
{
$this->expectException(NotImplementedException::class);

View File

@@ -1,6 +1,6 @@
PHPWord, a pure PHP library for reading and writing word processing documents.
Copyright (c) 2010-2025 PHPWord.
Copyright (c) 2010-2016 PHPWord.
PHPWord is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3 as published by

View File

@@ -1,11 +1,11 @@
# ![PHPWord](https://rawgit.com/PHPOffice/PHPWord/develop/docs/images/phpword.svg "PHPWord")
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v)](https://packagist.org/packages/phpoffice/phpword)
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword)
[![Coverage Status](https://coveralls.io/repos/github/PHPOffice/PHPWord/badge.svg?branch=master)](https://coveralls.io/github/PHPOffice/PHPWord?branch=master)
[![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads)](https://packagist.org/packages/phpoffice/phpword)
[![License](https://poser.pugx.org/phpoffice/phpword/license)](https://packagist.org/packages/phpoffice/phpword)
Branch Master : [![PHPWord](https://github.com/PHPOffice/PHPWord/actions/workflows/php.yml/badge.svg?branch=master)](https://github.com/PHPOffice/PHPWord/actions/workflows/php.yml)
[![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword)
[![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword)
[![CI](https://github.com/PHPOffice/PHPWord/actions/workflows/ci.yml/badge.svg)](https://github.com/PHPOffice/PHPWord/actions/workflows/ci.yml)
[![Join the chat at https://gitter.im/PHPOffice/PHPWord](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/PHPOffice/PHPWord)
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF), HTML, and PDF.
@@ -81,6 +81,7 @@ The following is a basic usage example of the PHPWord library.
```php
<?php
require_once 'bootstrap.php';
// Creating the new document...
$phpWord = new \PhpOffice\PhpWord\PhpWord();

View File

@@ -8,7 +8,7 @@
],
"homepage": "https://phpoffice.github.io/PHPWord/",
"type": "library",
"license": "LGPL-3.0-only",
"license": "LGPL-3.0",
"authors": [
{
"name": "Mark Baker"
@@ -36,67 +36,20 @@
],
"scripts": {
"test": [
"@php vendor/bin/phpunit --color=always"
"phpunit --color=always"
],
"test-no-coverage": [
"@php vendor/bin/phpunit --color=always --no-coverage"
"phpunit --color=always --no-coverage"
],
"check": [
"@php vendor/bin/php-cs-fixer fix --ansi --dry-run --diff",
"@php vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php",
"php-cs-fixer fix --ansi --dry-run --diff",
"phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=src/PhpWord/Shared/PCLZip --standard=PSR2 -n",
"phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php",
"@test-no-coverage",
"@php vendor/bin/phpstan analyse --ansi"
"phpstan analyse --ansi"
],
"fix": [
"@php vendor/bin/php-cs-fixer fix --ansi"
],
"samples": [
"php samples/Sample_01_SimpleText.php",
"php samples/Sample_02_TabStops.php",
"php samples/Sample_03_Sections.php",
"php samples/Sample_04_Textrun.php",
"php samples/Sample_05_Multicolumn.php",
"php samples/Sample_06_Footnote.php",
"php samples/Sample_07_TemplateCloneRow.php",
"php samples/Sample_08_ParagraphPagination.php",
"php samples/Sample_09_Tables.php",
"php samples/Sample_10_EastAsianFontStyle.php",
"php samples/Sample_11_ReadWord97.php",
"php samples/Sample_11_ReadWord2007.php",
"php samples/Sample_12_HeaderFooter.php",
"php samples/Sample_13_Images.php",
"php samples/Sample_14_ListItem.php",
"php samples/Sample_15_Link.php",
"php samples/Sample_16_Object.php",
"php samples/Sample_17_TitleTOC.php",
"php samples/Sample_18_Watermark.php",
"php samples/Sample_19_TextBreak.php",
"php samples/Sample_20_BGColor.php",
"php samples/Sample_21_TableRowRules.php",
"php samples/Sample_22_CheckBox.php",
"php samples/Sample_23_TemplateBlock.php",
"php samples/Sample_24_ReadODText.php",
"php samples/Sample_25_TextBox.php",
"php samples/Sample_26_Html.php",
"php samples/Sample_27_Field.php",
"php samples/Sample_28_ReadRTF.php",
"php samples/Sample_29_Line.php",
"php samples/Sample_30_ReadHTML.php",
"php samples/Sample_31_Shape.php",
"php samples/Sample_32_Chart.php",
"php samples/Sample_33_FormField.php",
"php samples/Sample_34_SDT.php",
"php samples/Sample_35_InternalLink.php",
"php samples/Sample_36_RTL.php",
"php samples/Sample_37_Comments.php",
"php samples/Sample_38_Protection.php",
"php samples/Sample_39_TrackChanges.php",
"php samples/Sample_40_TemplateSetComplexValue.php",
"php samples/Sample_41_TemplateSetChart.php",
"php samples/Sample_42_TemplateSetCheckbox.php",
"php samples/Sample_43_RTLDefault.php",
"php samples/Sample_44_ExtractVariablesFromReaderWord2007.php",
"php samples/Sample_45_Autoloader.php"
"php-cs-fixer fix --ansi"
]
},
"scripts-descriptions": {
@@ -105,28 +58,34 @@
"check": "Runs PHP CheckStyle and PHP Mess detector",
"fix": "Fixes issues found by PHP-CS"
},
"config": {
"platform": {
"php": "8.0"
}
},
"require": {
"php": "^7.1|^8.0",
"ext-dom": "*",
"ext-gd": "*",
"ext-zip": "*",
"ext-json": "*",
"ext-xml": "*",
"phpoffice/math": "^0.3"
"phpoffice/math": "^0.2"
},
"require-dev": {
"ext-zip": "*",
"ext-gd": "*",
"ext-libxml": "*",
"dompdf/dompdf": "^2.0 || ^3.0",
"friendsofphp/php-cs-fixer": "^3.3",
"mpdf/mpdf": "^7.0 || ^8.0",
"dompdf/dompdf": "^2.0",
"mpdf/mpdf": "^8.1",
"phpmd/phpmd": "^2.13",
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
"phpunit/phpunit": ">=7.0",
"tecnickcom/tcpdf": "^6.5",
"symfony/process": "^4.4 || ^5.0",
"tecnickcom/tcpdf": "^6.5"
"friendsofphp/php-cs-fixer": "^3.3",
"phpstan/phpstan-phpunit": "@stable"
},
"suggest": {
"ext-zip": "Allows writing OOXML and ODF",
"ext-gd2": "Allows adding images",
"ext-xmlwriter": "Allows writing OOXML and ODF",
"ext-xsl": "Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template",
"dompdf/dompdf": "Allows writing PDF"

View File

@@ -63,7 +63,6 @@ nav:
- OLE Object: 'usage/elements/oleobject.md'
- Page Break: 'usage/elements/pagebreak.md'
- Preserve Text: 'usage/elements/preservetext.md'
- Ruby: 'usage/elements/ruby.md'
- Text: 'usage/elements/text.md'
- TextBox: 'usage/elements/textbox.md'
- Text Break: 'usage/elements/textbreak.md'
@@ -88,9 +87,7 @@ nav:
- Credits: 'credits.md'
- Releases:
- '1.x':
- '1.5.0 (WIP)': 'changes/1.x/1.5.0.md'
- '1.4.0': 'changes/1.x/1.4.0.md'
- '1.3.0': 'changes/1.x/1.3.0.md'
- '1.3.0 (WIP)': 'changes/1.x/1.3.0.md'
- '1.2.0': 'changes/1.x/1.2.0.md'
- '1.1.0': 'changes/1.x/1.1.0.md'
- '1.0.0': 'changes/1.x/1.0.0.md'

View File

@@ -375,6 +375,11 @@ parameters:
count: 1
path: src/PhpWord/Shared/Drawing.php
-
message: "#^Binary operation \"\\*\" between string and 50 results in an error\\.$#"
count: 1
path: src/PhpWord/Shared/Html.php
-
message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#"
count: 1
@@ -430,11 +435,6 @@ parameters:
count: 1
path: src/PhpWord/Shared/Html.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Shared\\\\Html\\:\\:parseRuby\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpWord/Shared/Html.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Shared\\\\Html\\:\\:parseStyleDeclarations\\(\\) has no return type specified\\.$#"
count: 1
@@ -447,7 +447,7 @@ parameters:
-
message: "#^Parameter \\#1 \\$attribute of static method PhpOffice\\\\PhpWord\\\\Shared\\\\Html\\:\\:parseStyle\\(\\) expects DOMAttr, DOMNode given\\.$#"
count: 3
count: 1
path: src/PhpWord/Shared/Html.php
-
@@ -685,6 +685,11 @@ parameters:
count: 1
path: src/PhpWord/Style/Cell.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Cell\\:\\:\\$shading is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Cell.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Style\\\\Chart\\:\\:getMajorTickPosition\\(\\) has no return type specified\\.$#"
count: 1
@@ -755,6 +760,41 @@ parameters:
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$allCaps is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$doubleStrikethrough is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$lang is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$paragraph is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$shading is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$smallCaps is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$strikethrough is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Line\\:\\:\\$weight \\(int\\) does not accept float\\|int\\|null\\.$#"
count: 1
@@ -775,6 +815,21 @@ parameters:
count: 1
path: src/PhpWord/Style/Paragraph.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Paragraph\\:\\:\\$indentation is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Paragraph.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Paragraph\\:\\:\\$shading is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Paragraph.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Paragraph\\:\\:\\$spacing is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Paragraph.php
-
message: "#^Result of && is always false\\.$#"
count: 1
@@ -785,6 +840,36 @@ parameters:
count: 1
path: src/PhpWord/Style/Section.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Section\\:\\:\\$lineNumbering is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Section.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Shape\\:\\:\\$extrusion is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Shape.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Shape\\:\\:\\$fill is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Shape.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Shape\\:\\:\\$frame is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Shape.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Shape\\:\\:\\$outline is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Shape.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Shape\\:\\:\\$shadow is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Shape.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Style\\\\TOC\\:\\:setTabLeader\\(\\) should return PhpOffice\\\\PhpWord\\\\Style\\\\TOC but returns PhpOffice\\\\PhpWord\\\\Style\\\\Tab\\.$#"
count: 1
@@ -1035,6 +1120,11 @@ parameters:
count: 1
path: src/PhpWord/Writer/AbstractWriter.php
-
message: "#^PHPDoc tag @param has invalid value \\(\\\\PhpOffice\\\\PhpWord\\\\PhpWord\\)\\: Unexpected token \"\\\\n \\*\", expected variable at offset 78$#"
count: 1
path: src/PhpWord/Writer/AbstractWriter.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\HTML\\\\Element\\\\AbstractElement\\:\\:write\\(\\) has no return type specified\\.$#"
count: 1
@@ -1056,14 +1146,14 @@ parameters:
path: src/PhpWord/Writer/ODText/Element/Table.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\AbstractElement\\:\\:replaceTabs\\(\\) has parameter \\$text with no type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\Text\\:\\:replacetabs\\(\\) has parameter \\$text with no type specified\\.$#"
count: 1
path: src/PhpWord/Writer/ODText/Element/AbstractElement.php
path: src/PhpWord/Writer/ODText/Element/Text.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\AbstractElement\\:\\:replaceTabs\\(\\) has parameter \\$xmlWriter with no type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\Text\\:\\:replacetabs\\(\\) has parameter \\$xmlWriter with no type specified\\.$#"
count: 1
path: src/PhpWord/Writer/ODText/Element/AbstractElement.php
path: src/PhpWord/Writer/ODText/Element/Text.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\Text\\:\\:writeChangeInsertion\\(\\) has parameter \\$start with no type specified\\.$#"
@@ -1225,6 +1315,11 @@ parameters:
count: 1
path: src/PhpWord/Writer/RTF/Style/Border.php
-
message: "#^PHPDoc tag @param has invalid value \\(\\\\PhpOffice\\\\PhpWord\\\\PhpWord\\)\\: Unexpected token \"\\\\n \", expected variable at offset 86$#"
count: 1
path: src/PhpWord/Writer/Word2007.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\Word2007\\\\Element\\\\AbstractElement\\:\\:write\\(\\) has no return type specified\\.$#"
count: 1
@@ -1331,29 +1426,29 @@ parameters:
path: tests/PhpWordTests/AbstractTestReader.php
-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbedded\\:\\:getBaseUrl\\(\\) has no return type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbeddedTest\\:\\:getBaseUrl\\(\\) has no return type specified\\.$#"
count: 1
path: tests/PhpWordTests/AbstractWebServerEmbedded.php
path: tests/PhpWordTests/AbstractWebServerEmbeddedTest.php
-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbedded\\:\\:getRemoteBmpImageUrl\\(\\) has no return type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbeddedTest\\:\\:getRemoteBmpImageUrl\\(\\) has no return type specified\\.$#"
count: 1
path: tests/PhpWordTests/AbstractWebServerEmbedded.php
path: tests/PhpWordTests/AbstractWebServerEmbeddedTest.php
-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbedded\\:\\:getRemoteGifImageUrl\\(\\) has no return type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbeddedTest\\:\\:getRemoteGifImageUrl\\(\\) has no return type specified\\.$#"
count: 1
path: tests/PhpWordTests/AbstractWebServerEmbedded.php
path: tests/PhpWordTests/AbstractWebServerEmbeddedTest.php
-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbedded\\:\\:getRemoteImageUrl\\(\\) has no return type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbeddedTest\\:\\:getRemoteImageUrl\\(\\) has no return type specified\\.$#"
count: 1
path: tests/PhpWordTests/AbstractWebServerEmbedded.php
path: tests/PhpWordTests/AbstractWebServerEmbeddedTest.php
-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbedded\\:\\:\\$httpServer has no type specified\\.$#"
message: "#^Property PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbeddedTest\\:\\:\\$httpServer has no type specified\\.$#"
count: 1
path: tests/PhpWordTests/AbstractWebServerEmbedded.php
path: tests/PhpWordTests/AbstractWebServerEmbeddedTest.php
-
message: "#^Parameter \\#1 \\$width of class PhpOffice\\\\PhpWord\\\\Element\\\\Cell constructor expects int\\|null, string given\\.$#"
@@ -1694,11 +1789,6 @@ parameters:
message: "#^Cannot access property \\$length on DOMNodeList\\<DOMNode\\>\\|false\\.$#"
count: 9
path: tests/PhpWordTests/Writer/HTML/ElementTest.php
-
message: "#^Cannot access property \\$length on DOMNodeList\\<DOMNode\\>\\|false\\.$#"
count: 2
path: tests/PhpWordTests/Writer/HTML/Element/RubyTest.php
-
message: "#^Cannot call method item\\(\\) on DOMNodeList\\<DOMNode\\>\\|false\\.$#"

View File

@@ -14,7 +14,6 @@ outputEscapingEnabled = false
defaultFontName = Arial
defaultFontSize = 10
defaultFontColor = 000000
[Paper]

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -22,7 +21,6 @@ namespace PhpOffice\PhpWord\Collection;
* Collection abstract class.
*
* @since 0.10.0
*
* @template T
*/
abstract class AbstractCollection

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -24,7 +23,6 @@ use PhpOffice\PhpWord\Element\Bookmark;
* Bookmarks collection.
*
* @since 0.12.0
*
* @extends AbstractCollection<Bookmark>
*/
class Bookmarks extends AbstractCollection

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -24,7 +23,6 @@ use PhpOffice\PhpWord\Element\Chart;
* Charts collection.
*
* @since 0.12.0
*
* @extends AbstractCollection<Chart>
*/
class Charts extends AbstractCollection

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -24,7 +23,6 @@ use PhpOffice\PhpWord\Element\Comment;
* Comments collection.
*
* @since 0.12.0
*
* @extends AbstractCollection<Comment>
*/
class Comments extends AbstractCollection

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -24,7 +23,6 @@ use PhpOffice\PhpWord\Element\Endnote;
* Endnotes collection.
*
* @since 0.10.0
*
* @extends AbstractCollection<Endnote>
*/
class Endnotes extends AbstractCollection

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -24,7 +23,6 @@ use PhpOffice\PhpWord\Element\Footnote;
* Footnotes collection.
*
* @since 0.10.0
*
* @extends AbstractCollection<Footnote>
*/
class Footnotes extends AbstractCollection

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -24,7 +23,6 @@ use PhpOffice\PhpWord\Element\Title;
* Titles collection.
*
* @since 0.10.0
*
* @extends AbstractCollection<Title>
*/
class Titles extends AbstractCollection

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -50,7 +49,6 @@ use ReflectionClass;
* @method FormField addFormField(string $type, mixed $fStyle = null, mixed $pStyle = null)
* @method SDT addSDT(string $type)
* @method Formula addFormula(Math $math)
* @method Ruby addRuby(TextRun $baseText, TextRun $rubyText, \PhpOffice\PhpWord\ComplexType\RubyProperties $properties)
* @method \PhpOffice\PhpWord\Element\OLEObject addObject(string $source, mixed $style = null) deprecated, use addOLEObject instead
*
* @since 0.10.0
@@ -60,7 +58,7 @@ abstract class AbstractContainer extends AbstractElement
/**
* Elements collection.
*
* @var AbstractElement[]
* @var \PhpOffice\PhpWord\Element\AbstractElement[]
*/
protected $elements = [];
@@ -82,7 +80,7 @@ abstract class AbstractContainer extends AbstractElement
* @param mixed $function
* @param mixed $args
*
* @return AbstractElement
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
public function __call($function, $args)
{
@@ -92,7 +90,7 @@ abstract class AbstractContainer extends AbstractElement
'Footnote', 'Endnote', 'CheckBox', 'TextBox', 'Field',
'Line', 'Shape', 'Title', 'TOC', 'PageBreak',
'Chart', 'FormField', 'SDT', 'Comment',
'Formula', 'Ruby',
'Formula',
];
$functions = [];
foreach ($elements as $element) {
@@ -132,7 +130,7 @@ abstract class AbstractContainer extends AbstractElement
*
* @param string $elementName
*
* @return AbstractElement
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
protected function addElement($elementName)
{
@@ -151,7 +149,7 @@ abstract class AbstractContainer extends AbstractElement
$elementArgs = $args;
array_shift($elementArgs); // Shift the $elementName off the beginning of array
/** @var AbstractElement $element Type hint */
/** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
$element = $reflection->newInstanceArgs($elementArgs);
// Set parent container
@@ -167,7 +165,7 @@ abstract class AbstractContainer extends AbstractElement
/**
* Get all elements.
*
* @return AbstractElement[]
* @return \PhpOffice\PhpWord\Element\AbstractElement[]
*/
public function getElements()
{
@@ -179,7 +177,7 @@ abstract class AbstractContainer extends AbstractElement
*
* @param int $index
*
* @return null|AbstractElement
* @return null|\PhpOffice\PhpWord\Element\AbstractElement
*/
public function getElement($index)
{
@@ -193,13 +191,13 @@ abstract class AbstractContainer extends AbstractElement
/**
* Removes the element at requested index.
*
* @param AbstractElement|int $toRemove
* @param int|\PhpOffice\PhpWord\Element\AbstractElement $toRemove
*/
public function removeElement($toRemove): void
{
if (is_int($toRemove) && array_key_exists($toRemove, $this->elements)) {
unset($this->elements[$toRemove]);
} elseif ($toRemove instanceof AbstractElement) {
} elseif ($toRemove instanceof \PhpOffice\PhpWord\Element\AbstractElement) {
foreach ($this->elements as $key => $element) {
if ($element->getElementId() === $toRemove->getElementId()) {
unset($this->elements[$key]);
@@ -255,7 +253,7 @@ abstract class AbstractContainer extends AbstractElement
'Footnote' => ['Section', 'TextRun', 'Cell', 'ListItemRun'],
'Endnote' => ['Section', 'TextRun', 'Cell'],
'PreserveText' => ['Section', 'Header', 'Footer', 'Cell'],
'Title' => ['Section', 'Cell', 'Header'],
'Title' => ['Section', 'Cell'],
'TOC' => ['Section'],
'PageBreak' => ['Section'],
'Chart' => ['Section', 'Cell'],

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -149,6 +148,8 @@ abstract class AbstractElement
/**
* Get PhpWord.
*
* @return ?PhpWord
*/
public function getPhpWord(): ?PhpWord
{
@@ -255,7 +256,7 @@ abstract class AbstractElement
*/
public function setElementId(): void
{
$this->elementId = substr(md5((string) mt_rand()), 0, 6);
$this->elementId = substr(md5(mt_rand()), 0, 6);
}
/**
@@ -290,6 +291,8 @@ abstract class AbstractElement
/**
* Get comments start.
*
* @return Comments
*/
public function getCommentsRangeStart(): ?Comments
{
@@ -298,6 +301,8 @@ abstract class AbstractElement
/**
* Get comment start.
*
* @return Comment
*/
public function getCommentRangeStart(): ?Comment
{
@@ -334,6 +339,8 @@ abstract class AbstractElement
/**
* Get comments end.
*
* @return Comments
*/
public function getCommentsRangeEnd(): ?Comments
{
@@ -342,6 +349,8 @@ abstract class AbstractElement
/**
* Get comment end.
*
* @return Comment
*/
public function getCommentRangeEnd(): ?Comment
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -40,7 +39,7 @@ class Cell extends AbstractContainer
/**
* Cell style.
*
* @var ?CellStyle
* @var ?\PhpOffice\PhpWord\Style\Cell
*/
private $style;
@@ -48,7 +47,7 @@ class Cell extends AbstractContainer
* Create new instance.
*
* @param null|int $width
* @param array|CellStyle $style
* @param array|\PhpOffice\PhpWord\Style\Cell $style
*/
public function __construct($width = null, $style = null)
{
@@ -59,7 +58,7 @@ class Cell extends AbstractContainer
/**
* Get cell style.
*
* @return ?CellStyle
* @return ?\PhpOffice\PhpWord\Style\Cell
*/
public function getStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -51,7 +50,7 @@ class Chart extends AbstractElement
/**
* Chart style.
*
* @var ?ChartStyle
* @var ?\PhpOffice\PhpWord\Style\Chart
*/
private $style;
@@ -121,7 +120,7 @@ class Chart extends AbstractElement
/**
* Get chart style.
*
* @return ?ChartStyle
* @return ?\PhpOffice\PhpWord\Style\Chart
*/
public function getStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -90,7 +89,7 @@ class Comment extends TrackChange
/**
* Get the element where this comment starts.
*
* @return AbstractElement
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
public function getStartElement()
{
@@ -109,7 +108,7 @@ class Comment extends TrackChange
/**
* Get the element where this comment ends.
*
* @return AbstractElement
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
public function getEndElement()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -129,16 +128,16 @@ class Field extends AbstractElement
/**
* Font style.
*
* @var Font|string
* @var \PhpOffice\PhpWord\Style\Font|string
*/
protected $fontStyle;
/**
* Set Font style.
*
* @param array|Font|string $style
* @param array|\PhpOffice\PhpWord\Style\Font|string $style
*
* @return Font|string
* @return \PhpOffice\PhpWord\Style\Font|string
*/
public function setFontStyle($style = null)
{
@@ -159,7 +158,7 @@ class Field extends AbstractElement
/**
* Get Font style.
*
* @return Font|string
* @return \PhpOffice\PhpWord\Style\Font|string
*/
public function getFontStyle()
{
@@ -173,7 +172,7 @@ class Field extends AbstractElement
* @param array $properties
* @param array $options
* @param null|string|TextRun $text
* @param array|Font|string $fontStyle
* @param array|\PhpOffice\PhpWord\Style\Font|string $fontStyle
*/
public function __construct($type = null, $properties = [], $options = [], $text = null, $fontStyle = null)
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -30,7 +29,7 @@ class Footnote extends AbstractContainer
/**
* Paragraph style.
*
* @var null|Paragraph|string
* @var null|\PhpOffice\PhpWord\Style\Paragraph|string
*/
protected $paragraphStyle;
@@ -44,7 +43,7 @@ class Footnote extends AbstractContainer
/**
* Create new instance.
*
* @param array|Paragraph|string $paragraphStyle
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $paragraphStyle
*/
public function __construct($paragraphStyle = null)
{
@@ -55,7 +54,7 @@ class Footnote extends AbstractContainer
/**
* Get paragraph style.
*
* @return null|Paragraph|string
* @return null|\PhpOffice\PhpWord\Style\Paragraph|string
*/
public function getParagraphStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -28,7 +27,7 @@ class Line extends AbstractElement
/**
* Line style.
*
* @var ?LineStyle
* @var ?\PhpOffice\PhpWord\Style\Line
*/
private $style;
@@ -45,7 +44,7 @@ class Line extends AbstractElement
/**
* Get line style.
*
* @return ?LineStyle
* @return ?\PhpOffice\PhpWord\Style\Line
*/
public function getStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -44,14 +43,14 @@ class Link extends AbstractElement
/**
* Font style.
*
* @var null|Font|string
* @var null|\PhpOffice\PhpWord\Style\Font|string
*/
private $fontStyle;
/**
* Paragraph style.
*
* @var null|Paragraph|string
* @var null|\PhpOffice\PhpWord\Style\Paragraph|string
*/
private $paragraphStyle;
@@ -99,8 +98,10 @@ class Link extends AbstractElement
/**
* Get link text.
*
* @return string
*/
public function getText(): string
public function getText()
{
return $this->text;
}
@@ -108,7 +109,7 @@ class Link extends AbstractElement
/**
* Get Text style.
*
* @return null|Font|string
* @return null|\PhpOffice\PhpWord\Style\Font|string
*/
public function getFontStyle()
{
@@ -118,7 +119,7 @@ class Link extends AbstractElement
/**
* Get Paragraph style.
*
* @return null|Paragraph|string
* @return null|\PhpOffice\PhpWord\Style\Paragraph|string
*/
public function getParagraphStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -29,14 +28,14 @@ class ListItem extends AbstractElement
/**
* Element style.
*
* @var ?ListItemStyle
* @var ?\PhpOffice\PhpWord\Style\ListItem
*/
private $style;
/**
* Text object.
*
* @var Text
* @var \PhpOffice\PhpWord\Element\Text
*/
private $textObject;
@@ -72,7 +71,7 @@ class ListItem extends AbstractElement
/**
* Get style.
*
* @return ?ListItemStyle
* @return ?\PhpOffice\PhpWord\Style\ListItem
*/
public function getStyle()
{
@@ -82,7 +81,7 @@ class ListItem extends AbstractElement
/**
* Get Text object.
*
* @return Text
* @return \PhpOffice\PhpWord\Element\Text
*/
public function getTextObject()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -33,7 +32,7 @@ class ListItemRun extends TextRun
/**
* ListItem Style.
*
* @var ?ListItemStyle
* @var ?\PhpOffice\PhpWord\Style\ListItem
*/
private $style;
@@ -67,7 +66,7 @@ class ListItemRun extends TextRun
/**
* Get ListItem style.
*
* @return ?ListItemStyle
* @return ?\PhpOffice\PhpWord\Style\ListItem
*/
public function getStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -36,7 +35,7 @@ class OLEObject extends AbstractElement
/**
* Image Style.
*
* @var ?ImageStyle
* @var ?\PhpOffice\PhpWord\Style\Image
*/
private $style;
@@ -101,7 +100,7 @@ class OLEObject extends AbstractElement
/**
* Get object style.
*
* @return ?ImageStyle
* @return ?\PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -37,14 +36,14 @@ class PreserveText extends AbstractElement
/**
* Text style.
*
* @var null|Font|string
* @var null|\PhpOffice\PhpWord\Style\Font|string
*/
private $fontStyle;
/**
* Paragraph style.
*
* @var null|Paragraph|string
* @var null|\PhpOffice\PhpWord\Style\Paragraph|string
*/
private $paragraphStyle;
@@ -70,7 +69,7 @@ class PreserveText extends AbstractElement
/**
* Get Text style.
*
* @return null|Font|string
* @return null|\PhpOffice\PhpWord\Style\Font|string
*/
public function getFontStyle()
{
@@ -80,7 +79,7 @@ class PreserveText extends AbstractElement
/**
* Get Paragraph style.
*
* @return null|Paragraph|string
* @return null|\PhpOffice\PhpWord\Style\Paragraph|string
*/
public function getParagraphStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -37,14 +36,14 @@ class Row extends AbstractElement
/**
* Row style.
*
* @var ?RowStyle
* @var ?\PhpOffice\PhpWord\Style\Row
*/
private $style;
/**
* Row cells.
*
* @var Cell[]
* @var \PhpOffice\PhpWord\Element\Cell[]
*/
private $cells = [];
@@ -66,7 +65,7 @@ class Row extends AbstractElement
* @param int $width
* @param mixed $style
*
* @return Cell
* @return \PhpOffice\PhpWord\Element\Cell
*/
public function addCell($width = null, $style = null)
{
@@ -80,7 +79,7 @@ class Row extends AbstractElement
/**
* Get all cells.
*
* @return Cell[]
* @return \PhpOffice\PhpWord\Element\Cell[]
*/
public function getCells()
{
@@ -90,7 +89,7 @@ class Row extends AbstractElement
/**
* Get row style.
*
* @return ?RowStyle
* @return ?\PhpOffice\PhpWord\Style\Row
*/
public function getStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -32,7 +31,7 @@ class Section extends AbstractContainer
/**
* Section style.
*
* @var ?SectionStyle
* @var ?\PhpOffice\PhpWord\Style\Section
*/
private $style;
@@ -88,7 +87,7 @@ class Section extends AbstractContainer
/**
* Get section style.
*
* @return ?SectionStyle
* @return ?\PhpOffice\PhpWord\Style\Section
*/
public function getStyle()
{
@@ -197,14 +196,14 @@ class Section extends AbstractContainer
*/
private function addHeaderFooter($type = Header::AUTO, $header = true)
{
$containerClass = substr(static::class, 0, strrpos(static::class, '\\') ?: 0) . '\\' .
$containerClass = substr(static::class, 0, strrpos(static::class, '\\')) . '\\' .
($header ? 'Header' : 'Footer');
$collectionArray = $header ? 'headers' : 'footers';
$collection = &$this->$collectionArray;
if (in_array($type, [Header::AUTO, Header::FIRST, Header::EVEN])) {
$index = count($collection);
/** @var AbstractContainer $container Type hint */
/** @var \PhpOffice\PhpWord\Element\AbstractContainer $container Type hint */
$container = new $containerClass($this->sectionId, ++$index, $type);
$container->setPhpWord($this->phpWord);

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -37,7 +36,7 @@ class Shape extends AbstractElement
/**
* Shape style.
*
* @var ?ShapeStyle
* @var ?\PhpOffice\PhpWord\Style\Shape
*/
private $style;
@@ -81,7 +80,7 @@ class Shape extends AbstractElement
/**
* Get shape style.
*
* @return ?ShapeStyle
* @return ?\PhpOffice\PhpWord\Style\Shape
*/
public function getStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -30,14 +29,14 @@ class TOC extends AbstractElement
/**
* TOC style.
*
* @var TOCStyle
* @var \PhpOffice\PhpWord\Style\TOC
*/
private $tocStyle;
/**
* Font style.
*
* @var Font|string
* @var \PhpOffice\PhpWord\Style\Font|string
*/
private $fontStyle;
@@ -95,7 +94,7 @@ class TOC extends AbstractElement
$titles = $this->phpWord->getTitles()->getItems();
foreach ($titles as $i => $title) {
/** @var Title $title Type hint */
/** @var \PhpOffice\PhpWord\Element\Title $title Type hint */
$depth = $title->getDepth();
if ($this->minDepth > $depth) {
unset($titles[$i]);
@@ -111,7 +110,7 @@ class TOC extends AbstractElement
/**
* Get TOC Style.
*
* @return TOCStyle
* @return \PhpOffice\PhpWord\Style\TOC
*/
public function getStyleTOC()
{
@@ -121,7 +120,7 @@ class TOC extends AbstractElement
/**
* Get Font Style.
*
* @return Font|string
* @return \PhpOffice\PhpWord\Style\Font|string
*/
public function getStyleFont()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -28,14 +27,14 @@ class Table extends AbstractElement
/**
* Table style.
*
* @var ?TableStyle
* @var ?\PhpOffice\PhpWord\Style\Table
*/
private $style;
/**
* Table rows.
*
* @var Row[]
* @var \PhpOffice\PhpWord\Element\Row[]
*/
private $rows = [];
@@ -62,7 +61,7 @@ class Table extends AbstractElement
* @param int $height
* @param mixed $style
*
* @return Row
* @return \PhpOffice\PhpWord\Element\Row
*/
public function addRow($height = null, $style = null)
{
@@ -79,7 +78,7 @@ class Table extends AbstractElement
* @param int $width
* @param mixed $style
*
* @return Cell
* @return \PhpOffice\PhpWord\Element\Cell
*/
public function addCell($width = null, $style = null)
{
@@ -93,7 +92,7 @@ class Table extends AbstractElement
/**
* Get all rows.
*
* @return Row[]
* @return \PhpOffice\PhpWord\Element\Row[]
*/
public function getRows()
{
@@ -103,7 +102,7 @@ class Table extends AbstractElement
/**
* Get table style.
*
* @return null|string|TableStyle
* @return null|\PhpOffice\PhpWord\Style\Table|string
*/
public function getStyle()
{
@@ -141,7 +140,7 @@ class Table extends AbstractElement
$rowCount = count($this->rows);
for ($i = 0; $i < $rowCount; ++$i) {
/** @var Row $row Type hint */
/** @var \PhpOffice\PhpWord\Element\Row $row Type hint */
$row = $this->rows[$i];
$cellCount = count($row->getCells());
if ($columnCount < $cellCount) {

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -37,14 +36,14 @@ class Text extends AbstractElement
/**
* Text style.
*
* @var Font|string
* @var \PhpOffice\PhpWord\Style\Font|string
*/
protected $fontStyle;
/**
* Paragraph style.
*
* @var Paragraph|string
* @var \PhpOffice\PhpWord\Style\Paragraph|string
*/
protected $paragraphStyle;
@@ -65,10 +64,10 @@ class Text extends AbstractElement
/**
* Set Text style.
*
* @param array|Font|string $style
* @param array|Paragraph|string $paragraphStyle
* @param array|\PhpOffice\PhpWord\Style\Font|string $style
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $paragraphStyle
*
* @return Font|string
* @return \PhpOffice\PhpWord\Style\Font|string
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
@@ -91,7 +90,7 @@ class Text extends AbstractElement
/**
* Get Text style.
*
* @return Font|string
* @return \PhpOffice\PhpWord\Style\Font|string
*/
public function getFontStyle()
{
@@ -101,9 +100,9 @@ class Text extends AbstractElement
/**
* Set Paragraph style.
*
* @param array|Paragraph|string $style
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $style
*
* @return Paragraph|string
* @return \PhpOffice\PhpWord\Style\Paragraph|string
*/
public function setParagraphStyle($style = null)
{
@@ -124,7 +123,7 @@ class Text extends AbstractElement
/**
* Get Paragraph style.
*
* @return Paragraph|string
* @return \PhpOffice\PhpWord\Style\Paragraph|string
*/
public function getParagraphStyle()
{
@@ -147,8 +146,10 @@ class Text extends AbstractElement
/**
* Get Text content.
*
* @return ?string
*/
public function getText(): ?string
public function getText()
{
return $this->text;
}

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -35,7 +34,7 @@ class TextBox extends AbstractContainer
/**
* TextBox style.
*
* @var ?TextBoxStyle
* @var ?\PhpOffice\PhpWord\Style\TextBox
*/
private $style;
@@ -52,7 +51,7 @@ class TextBox extends AbstractContainer
/**
* Get textbox style.
*
* @return ?TextBoxStyle
* @return ?\PhpOffice\PhpWord\Style\TextBox
*/
public function getStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -29,14 +28,14 @@ class TextBreak extends AbstractElement
/**
* Paragraph style.
*
* @var null|Paragraph|string
* @var null|\PhpOffice\PhpWord\Style\Paragraph|string
*/
private $paragraphStyle;
/**
* Text style.
*
* @var null|Font|string
* @var null|\PhpOffice\PhpWord\Style\Font|string
*/
private $fontStyle;
@@ -62,7 +61,7 @@ class TextBreak extends AbstractElement
* @param mixed $style
* @param mixed $paragraphStyle
*
* @return Font|string
* @return \PhpOffice\PhpWord\Style\Font|string
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
@@ -83,7 +82,7 @@ class TextBreak extends AbstractElement
/**
* Get Text style.
*
* @return null|Font|string
* @return null|\PhpOffice\PhpWord\Style\Font|string
*/
public function getFontStyle()
{
@@ -93,9 +92,9 @@ class TextBreak extends AbstractElement
/**
* Set Paragraph style.
*
* @param array|Paragraph|string $style
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $style
*
* @return Paragraph|string
* @return \PhpOffice\PhpWord\Style\Paragraph|string
*/
public function setParagraphStyle($style = null)
{
@@ -114,7 +113,7 @@ class TextBreak extends AbstractElement
/**
* Get Paragraph style.
*
* @return null|Paragraph|string
* @return null|\PhpOffice\PhpWord\Style\Paragraph|string
*/
public function getParagraphStyle()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -86,9 +85,6 @@ class TextRun extends AbstractContainer
foreach ($this->getElements() as $element) {
if ($element instanceof Text) {
$outstr .= $element->getText();
} elseif ($element instanceof Ruby) {
$outstr .= $element->getBaseTextRun()->getText() .
' (' . $element->getRubyTextRun()->getText() . ')';
}
}

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -36,7 +35,7 @@ abstract class IOFactory
*/
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
{
if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF', 'EPub3'], true)) {
if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF'], true)) {
throw new Exception("\"{$name}\" is not a valid writer.");
}
@@ -62,9 +61,9 @@ abstract class IOFactory
*
* @param string $type
* @param string $name
* @param PhpWord $phpWord
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*
* @return ReaderInterface|WriterInterface
* @return \PhpOffice\PhpWord\Reader\ReaderInterface|\PhpOffice\PhpWord\Writer\WriterInterface
*/
private static function createObject($type, $name, $phpWord = null)
{
@@ -82,11 +81,11 @@ abstract class IOFactory
* @param string $filename The name of the file
* @param string $readerName
*
* @return PhpWord $phpWord
* @return \PhpOffice\PhpWord\PhpWord $phpWord
*/
public static function load($filename, $readerName = 'Word2007')
{
/** @var ReaderInterface $reader */
/** @var \PhpOffice\PhpWord\Reader\ReaderInterface $reader */
$reader = self::createReader($readerName);
return $reader->load($filename);
@@ -101,7 +100,7 @@ abstract class IOFactory
*/
public static function extractVariables(string $filename, string $readerName = 'Word2007'): array
{
/** @var ReaderInterface $reader */
/** @var \PhpOffice\PhpWord\Reader\ReaderInterface $reader */
$reader = self::createReader($readerName);
$document = $reader->load($filename);
$extractedVariables = [];

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -94,14 +93,14 @@ class Settings
/**
* Spelling and Grammatical Checking State.
*
* @var ProofState
* @var \PhpOffice\PhpWord\ComplexType\ProofState
*/
private $proofState;
/**
* Document Editing Restrictions.
*
* @var Protection
* @var \PhpOffice\PhpWord\Metadata\Protection
*/
private $documentProtection;
@@ -267,7 +266,7 @@ class Settings
/**
* Get the Visibility of Annotation Types.
*
* @return TrackChangesView
* @return \PhpOffice\PhpWord\ComplexType\TrackChangesView
*/
public function getRevisionView()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -48,7 +47,7 @@ class PhpWord
/**
* Collection of sections.
*
* @var Section[]
* @var \PhpOffice\PhpWord\Element\Section[]
*/
private $sections = [];
@@ -152,7 +151,7 @@ class PhpWord
/**
* Get document properties object.
*
* @return Metadata\DocInfo
* @return \PhpOffice\PhpWord\Metadata\DocInfo
*/
public function getDocInfo()
{
@@ -162,7 +161,7 @@ class PhpWord
/**
* Get compatibility.
*
* @return Metadata\Compatibility
* @return \PhpOffice\PhpWord\Metadata\Compatibility
*
* @since 0.12.0
*/
@@ -174,7 +173,7 @@ class PhpWord
/**
* Get compatibility.
*
* @return Metadata\Settings
* @return \PhpOffice\PhpWord\Metadata\Settings
*
* @since 0.14.0
*/
@@ -186,7 +185,7 @@ class PhpWord
/**
* Get all sections.
*
* @return Section[]
* @return \PhpOffice\PhpWord\Element\Section[]
*/
public function getSections()
{
@@ -198,7 +197,7 @@ class PhpWord
*
* @param int $index
*
* @return null|Section
* @return null|\PhpOffice\PhpWord\Element\Section
*/
public function getSection($index)
{
@@ -214,7 +213,7 @@ class PhpWord
*
* @param null|array|string $style
*
* @return Section
* @return \PhpOffice\PhpWord\Element\Section
*/
public function addSection($style = null)
{
@@ -257,40 +256,6 @@ class PhpWord
Settings::setDefaultFontName($fontName);
}
/**
* Get default asian font name.
*/
public function getDefaultAsianFontName(): string
{
return Settings::getDefaultAsianFontName();
}
/**
* Set default asian font name.
*
* @param string $fontName
*/
public function setDefaultAsianFontName($fontName): void
{
Settings::setDefaultAsianFontName($fontName);
}
/**
* Set default font color.
*/
public function setDefaultFontColor(string $fontColor): void
{
Settings::setDefaultFontColor($fontColor);
}
/**
* Get default font color.
*/
public function getDefaultFontColor(): string
{
return Settings::getDefaultFontColor();
}
/**
* Get default font size.
*
@@ -316,7 +281,7 @@ class PhpWord
*
* @param array $styles Paragraph style definition
*
* @return Style\Paragraph
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function setDefaultParagraphStyle($styles)
{
@@ -368,7 +333,7 @@ class PhpWord
*
* @param array $settings
*
* @return Section
* @return \PhpOffice\PhpWord\Element\Section
*
* @codeCoverageIgnore
*/
@@ -382,7 +347,7 @@ class PhpWord
*
* @deprecated 0.12.0
*
* @return Metadata\DocInfo
* @return \PhpOffice\PhpWord\Metadata\DocInfo
*
* @codeCoverageIgnore
*/
@@ -396,7 +361,7 @@ class PhpWord
*
* @deprecated 0.12.0
*
* @param Metadata\DocInfo $documentProperties
* @param \PhpOffice\PhpWord\Metadata\DocInfo $documentProperties
*
* @return self
*

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -34,7 +33,7 @@ class HTML extends AbstractReader implements ReaderInterface
*
* @param string $docFile
*
* @return PhpWord
* @return \PhpOffice\PhpWord\PhpWord
*/
public function load($docFile)
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,5 +1,4 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -33,7 +32,7 @@ class ODText extends AbstractReader implements ReaderInterface
*
* @param string $docFile
*
* @return PhpWord
* @return \PhpOffice\PhpWord\PhpWord
*/
public function load($docFile)
{
@@ -59,7 +58,7 @@ class ODText extends AbstractReader implements ReaderInterface
{
$partClass = "PhpOffice\\PhpWord\\Reader\\ODText\\{$partName}";
if (class_exists($partClass)) {
/** @var ODText\AbstractPart $part Type hint */
/** @var \PhpOffice\PhpWord\Reader\ODText\AbstractPart $part Type hint */
$part = new $partClass($docFile, $xmlFile);
$part->setRels($relationships);
$part->read($phpWord);

Some files were not shown because too many files have changed in this diff Show More