定制 lukaswhite/podcast-feed-validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lukaswhite/podcast-feed-validator

最新稳定版本:1.1

Composer 安装命令:

composer require lukaswhite/podcast-feed-validator

包简介

A PHP library for validating podcast feeds

README 文档

README

A PHP library for validating podcast feeds.

Checks the validity of the feed; for example whether it's XML, RSS, whether it has the appropriate namespace.

It warns if certain fields are missing; for example, the fields that iTunes requires.

It also recommends fields that iTunes recommend, but which are not required.

Note that I deliberately haven't added a method to fetch a remote feed, so as not to add additional dependencies; I'd recommend using Guzzle.

Installation

composer require lukaswhite/podcast-feed-validator

Usage

use Lukaswhite\PodcastFeedValidator\Validator;

$validator = new Validator();

$validator->load('/path/to/feed.rss');
// or
$validator->setContent(/** raw content */);

$result = $validator->run();
        
if ($result->fails()) {
    // ...do something
}

The Result

The return value is an object that encapsulates the errors, warnings and recommendations.

Each of these are just strings, and are defined as constants in the relevant classes.

Note that typically, if an error has occurred then validation has failed before it starts generating warnings or recommendations. For example if the provided feed isn't XML, then it cannot check for the existence of certain fields.

if ($result->hasErrors()) {
    foreach ($result->getErrors() as $error) {
    
    }
}

if ($result->hasWarnings()) {
    foreach ($result->getWarnings() as $error) {
    
    }
}

if ($result->hasRecommendations()) {
    foreach ($result->getRecommendations() as $error) {
    
    }
}

The result object also includes individual results for the episodes.

Example

Suppose you provide the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:rawvoice="http://www.rawvoice.com/rawvoiceRssModule/"
xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"
>
<channel>
	<title>Minimal Example</title>
	<link>https://example.com</link>
	<description>Just an example.</description>
	<item>
		<title>Episode One</title>
	</item>
</channel>
</rss>

This will return FALSE:

$result->hasErrors();

The following will all return TRUE:

$result->hasWarnings();
$result->hasWarning(Warning::NO_LANGUAGE);
$result->hasWarning(Warning::NO_ARTWORK);
$result->hasWarning(Warning::NO_CATEGORIES);
$result->hasWarning(Warning::NO_EXPLICIT);

It will also make recommendations, so the following will also return TRUE:

$result->hasRecommendations();
$result->hasRecommendation(Recommendation::ADD_AUTHOR);
$result->hasRecommendation(Recommendation::ADD_OWNER);

For the episode:

$result = $validator->run()->episodes()[0];
$result->hasWarning(Warning::NO_MEDIA);
$result->hasRecommendation(Recommendation::ADD_LINK);
$result->hasRecommendation(Recommendation::ADD_GUID);
$result->hasRecommendation(Recommendation::ADD_PUB_DATE);
$result->hasRecommendation(Recommendation::ADD_DESCRIPTION);
$result->hasRecommendation(Recommendation::ADD_EXPLICIT);
$result->hasRecommendation(Recommendation::ADD_ARTWORK);
$result->hasRecommendation(Recommendation::ADD_DURATION);

See the tests for more information.

统计信息

  • 总下载量: 459
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固