Update for Laravel 5

This commit is contained in:
Ben Speakman 2015-02-07 13:43:01 +00:00
parent f9d9c4ac86
commit 6883ff9d98
4 changed files with 30 additions and 6 deletions

18
README.md Normal file → Executable file
View file

@ -1,5 +1,5 @@
# laravel-wp-api
Laravel package for the [Wordpress JSON REST API](https://github.com/WP-API/WP-API)
Laravel 5 package for the [Wordpress JSON REST API](https://github.com/WP-API/WP-API)
## Install
@ -11,9 +11,9 @@ Simply add the following line to your `composer.json` and run install/update:
Publish the package config files to configure the location of your Wordpress install:
php artisan config:publish cyberduck/laravel-wp-api
php artisan vendor:publish
You will also need to add the service provider and the facade alias to your `app/config/app.php`:
You will also need to add the service provider and optionally the facade alias to your `app/config/app.php`:
```php
'providers' => array(
@ -36,6 +36,12 @@ WpApi::posts($page);
```
#### Pages
```php
WpApi::pages($page);
```
#### Post
```php
WpApi::post($slug);
@ -48,6 +54,12 @@ WpApi::categories();
```
#### Tags
```php
WpApi::tags();
```
#### Category posts
```php
WpApi::category_posts($slug, $page);

2
composer.json Normal file → Executable file
View file

@ -11,7 +11,7 @@
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "4.2.*|~5.0",
"illuminate/support": "~5.0",
"guzzlehttp/guzzle": "~4.0"
},
"autoload": {

View file

@ -19,7 +19,9 @@ class LaravelWpApiServiceProvider extends ServiceProvider {
*/
public function boot()
{
$this->package('cyberduck/laravel-wp-api');
$this->publishes([
__DIR__.'/../../config/config.php' => config_path('/packages/cyberduck/laravel-wp-api/laravel-wp-api.php'),
]);
}
/**
@ -31,7 +33,7 @@ class LaravelWpApiServiceProvider extends ServiceProvider {
{
$this->app->bindShared('wp-api', function ($app) {
$endpoint = $this->app['config']->get('laravel-wp-api::endpoint');
$endpoint = $this->app['config']->get('laravel-wp-api.endpoint');
$client = new Client();
return new WpApi($endpoint, $client);

10
src/Cyberduck/LaravelWpApi/WpApi.php Normal file → Executable file
View file

@ -18,6 +18,11 @@ class WpApi
return $this->_get('posts', ['page' => $page]);
}
public function pages($page = null)
{
return $this->_get('posts', ['type' => 'page', 'page' => $page]);
}
public function post($slug)
{
return $this->_get('posts', ['filter' => ['name' => $slug]]);
@ -28,6 +33,11 @@ class WpApi
return $this->_get('taxonomies/category/terms');
}
public function tags()
{
return $this->_get('taxonomies/post_tag/terms');
}
public function category_posts($slug, $page = null)
{
return $this->_get('posts', ['page' => $page, 'filter' => ['category_name' => $slug]]);