Skip to content

PHP implementation of the Apple News Format and Apple News API.

Notifications You must be signed in to change notification settings

urbania-media/apple-news

Repository files navigation

Apple News PHP

This package offer a wrapper around the Apple News API and Apple News Format in PHP. It includes support for Laravel, Wordpress and an HTML parser.

Packagist Travis (.org) branch Coveralls github

Installation

composer require urbania/apple-news

Laravel

Versions prior to 5.5

  1. Add the Service Provider in the config file config/app.php:
'providers' => [
    // ...
    \Urbania\AppleNews\Laravel\AppleNewsServiceProvider::class,
    // ...
]
  1. Add the Facade in the config file config/app.php:
'facades' => [
    // ...
    'AppleNews' => \Urbania\AppleNews\Laravel\AppleNewsFacade::class,
    // ...
]

All versions

Publish the config file to config/apple-news.php:

php artisan vendor:publish

Usage

Pure PHP

Create a test article:

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

Create a test article: (when creating an article with the facade or the helper, it takes into account the default article values found in config/apple-news.php)

// 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();

About

PHP implementation of the Apple News Format and Apple News API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages