urbania/apple-news

dev-master 2019-03-25 22:45 UTC

This package is auto-updated.

Last update: 2024-09-09 13:44:53 UTC


README

此软件包为PHP提供了围绕Apple News API和Apple News Format的包装。它包括对Laravel、Wordpress和HTML解析器的支持。

Packagist Travis (.org) branch Coveralls github

安装

composer require urbania/apple-news

Laravel

5.5版本之前

  1. 在配置文件 config/app.php 中添加服务提供者
'providers' => [
    // ...
    \Urbania\AppleNews\Laravel\AppleNewsServiceProvider::class,
    // ...
]
  1. 在配置文件 config/app.php 中添加外观
'facades' => [
    // ...
    'AppleNews' => \Urbania\AppleNews\Laravel\AppleNewsFacade::class,
    // ...
]

所有版本

发布配置文件到 config/apple-news.php

php artisan vendor:publish

使用

纯PHP

创建测试文章

require __DIR__ . '/vendor/autoload.php';

use Urbania\AppleNews\Article;

$article = new Article([
    'identifier' => 'test-article',
    'language' => 'en-US',
    'version' => '1.7',
    'layout' => [
        'columns' => 12,
        'width' => 1024
    ],
    'title' => 'An article',
    'components' => [
        [
            'role' => 'title',
            'text' => 'This is a title'
        ],
        [
            'role' => 'body',
            'text' => 'This is a body'
        ]
    ]
]);

echo $article->toJson();

Laravel

创建测试文章:(当使用外观或助手创建文章时,它会考虑在 config/apple-news.php 中找到的默认 article 值)

// Using the facade
use AppleNews;

$article = AppleNews::article([
    'identifier' => 'test-article',
    'title' => 'An article',
    'components' => [
        [
            'role' => 'title',
            'text' => 'This is a title'
        ],
        [
            'role' => 'body',
            'text' => 'This is a body'
        ]
    ]
]);

// Using the helper
$article = article([
    // ... same as above
]);

echo $article->toJson();