Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Adding support for Laravel 5 while still keeping the backwards compat…
Browse files Browse the repository at this point in the history
…ibility with Laravel 4.

Fixes #10
  • Loading branch information
jelovac committed Feb 13, 2015
1 parent 53ee3a6 commit fa170bb
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bitly4laravel
=============
[![Build Status](https://travis-ci.org/jelovac/bitly4laravel.png?branch=master)](https://travis-ci.org/jelovac/bitly4laravel) [![Latest Stable Version](https://poser.pugx.org/jelovac/bitly4laravel/v/stable.png)](https://packagist.org/packages/jelovac/bitly4laravel) [![Total Downloads](https://poser.pugx.org/jelovac/bitly4laravel/downloads.png)](https://packagist.org/packages/jelovac/bitly4laravel) [![Latest Unstable Version](https://poser.pugx.org/jelovac/bitly4laravel/v/unstable.png)](https://packagist.org/packages/jelovac/bitly4laravel) [![License](https://poser.pugx.org/jelovac/bitly4laravel/license.png)](https://packagist.org/packages/jelovac/bitly4laravel)

Provides basic bitly API to use with Laravel.
Provides a Laravel package to communicate with Bit.ly API.

In order to use this API you need to get [OAuth Generic Access Token](https://bitly.com/a/oauth_apps) from Bitly website.

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "jelovac/bitly4laravel",
"description": "Provides basic bitly API to use with Laravel",
"description": "Provides a Laravel package to communicate with Bit.ly API",
"authors": [
{
"name": "Vladimir Jelovac",
"email": "vladimir.jelovac@jeftinodosajta.com"
"email": "jelovac@users.noreply.github.com"
}
],
"license": "BSD-2-Clause",
Expand Down
43 changes: 37 additions & 6 deletions src/Jelovac/Bitly4laravel/Bitly4laravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,33 @@ class Bitly4laravelServiceProvider extends ServiceProvider {
*/
protected $defer = false;

/**
* Actual provider
*
* @var \Illuminate\Support\ServiceProvider
*/
protected $provider;

/**
* Create a new service provider instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function __construct($app)
{
parent::__construct($app);
$this->provider = $this->getProvider();
}

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('jelovac/bitly4laravel');
return $this->provider->boot();
}

/**
Expand All @@ -28,10 +47,22 @@ public function boot()
*/
public function register()
{
$this->app['bitly4laravel'] = $this->app->share(function($app) {
$config = $app['config']->get('bitly4laravel::config');
return new Bitly4laravel($config);
});
return $this->provider->register();
}

/**
* Return ServiceProvider according to Laravel version
*
* @return \Intervention\Image\Provider\ProviderInterface
*/
private function getProvider()
{
$app = $this->app;
$version = intval($app::VERSION);
$provider = sprintf(
'\Jelovac\Bitly4laravel\ServiceProviders\Laravel%dServiceProvider', $version
);
return new $provider($app);
}

/**
Expand All @@ -44,4 +75,4 @@ public function provides()
return array('bitly4laravel');
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php namespace Jelovac\Bitly4laravel\ServiceProviders;

use Illuminate\Support\ServiceProvider;

class Laravel4ServiceProvider extends ServiceProvider {

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('jelovac/bitly4laravel');
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['bitly4laravel'] = $this->app->share(function($app) {
$config = $app['config']->get('bitly4laravel::config');
return new Bitly4laravel($config);
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php namespace Jelovac\Bitly4laravel\ServiceProviders;

use Illuminate\Support\ServiceProvider;

class Laravel5ServiceProvider extends ServiceProvider {

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$configPath = __DIR__ . '/../../config/bitly4laravel.php';
$paths = array(
$configPath => $this->config_path("bitly4laravel.php"),
);
$this->publishes($paths, 'config');
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$configPath = __DIR__ . '/../../config/bitly4laravel.php';
$this->mergeConfigFrom($configPath, 'bitly4laravel');
$this->app['bitly4laravel'] = $this->app->share(function($app) {
return new Bitly4laravel($app['config']);
});
}

}

0 comments on commit fa170bb

Please sign in to comment.