Skip to content

Commit

Permalink
code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michelmelo committed Apr 9, 2020
1 parent b9144d8 commit 590b4b3
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 91 deletions.
60 changes: 30 additions & 30 deletions config/mm-instagram-api.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<?php

return [
/**
* @var boolean
*/
'debug' => false,
/**
* @var boolean
*/
'debug' => false,

/**
* @var boolean
*/
'truncated_debug' => false,
/**
* @var boolean
*/
'truncated_debug' => false,

/**
* Settings adapter
* @var array|null
*/
'storage_config' => [
'storage' => 'file',
'basefolder' => storage_path() . '/instagram-api',
],
/**
* Settings adapter
* @var array|null
*/
'storage_config' => [
'storage' => 'file',
'basefolder' => storage_path() . '/instagram-api',
],

/**
* Enable or disable using proxies in the API
* @var boolean
*/
'use_proxy' => false,
/**
* List of the proxies.
* e.g. https://free-proxy-list.net/
*
* @var array
*/
'proxies' => [
//'103.14.8.239:8080',
],
/**
* Enable or disable using proxies in the API
* @var boolean
*/
'use_proxy' => false,
/**
* List of the proxies.
* e.g. https://free-proxy-list.net/
*
* @var array
*/
'proxies' => [
//'103.14.8.239:8080',
],
];
16 changes: 9 additions & 7 deletions src/Facades/InstagramApi.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
namespace MichelMelo\InstagramApi\Facades;

class InstagramApi extends \Illuminate\Support\Facades\Facade {
/**
* {@inheritDoc}
*/
protected static function getFacadeAccessor() {
return 'instagram.singleton';
}
class InstagramApi extends \Illuminate\Support\Facades\Facade
{
/**
* {@inheritDoc}
*/
protected static function getFacadeAccessor()
{
return 'instagram.singleton';
}
}
113 changes: 59 additions & 54 deletions src/LaravelInstagramApiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,72 @@
use InstagramAPI\Instagram;
use MichelMelo\InstagramApi\Facades\InstagramApi as InstagramApiFacade;

class LaravelInstagramApiProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
class LaravelInstagramApiProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Register the service provider.
* @todo Take over the world
* @return void
*/
public function register() {
$configPath = __DIR__ . '/../config/mm-instagram-api.php';
$this->mergeConfigFrom($configPath, 'mm-instagram-api');
$this->publishes([$configPath => $this->getConfigPath()], 'config');
/**
* Register the service provider.
* @todo Take over the world
* @return void
*/
public function register()
{
$configPath = __DIR__ . '/../config/mm-instagram-api.php';
$this->mergeConfigFrom($configPath, 'mm-instagram-api');
$this->publishes([$configPath => $this->getConfigPath()], 'config');

$this->registerInstagramApi();
}
$this->registerInstagramApi();
}

/**
* Creating singleton and registering alias
*/
private function registerInstagramApi() {
$this->app->singleton('instagram.singleton', function ($app) {
$instance = new Instagram(
$app['config']->get('instagram-api.debug', false),
$app['config']->get('instagram-api.truncated_debug', false),
$app['config']->get('instagram-api.storageConfi', [])
);
/**
* Creating singleton and registering alias
*/
private function registerInstagramApi()
{
$this->app->singleton('instagram.singleton', function ($app) {
$instance = new Instagram(
$app['config']->get('instagram-api.debug', false),
$app['config']->get('instagram-api.truncated_debug', false),
$app['config']->get('instagram-api.storageConfi', [])
);

$useProxy = $app['config']->get('instagram-api.use_proxy', false);
$proxies = $app['config']->get('instagram-api.proxies', false);
$useProxy = $app['config']->get('instagram-api.use_proxy', false);
$proxies = $app['config']->get('instagram-api.proxies', false);

if ($useProxy && $proxies) {
$proxy = $proxies[array_rand($proxies, 1)];
$instance->setProxy($proxy);
}
if ($useProxy && $proxies) {
$proxy = $proxies[array_rand($proxies, 1)];
$instance->setProxy($proxy);
}

return $instance;
});
return $instance;
});

$this->app->alias('instagram.singleton', InstagramApiFacade::class);
}
$this->app->alias('instagram.singleton', InstagramApiFacade::class);
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides() {
return ['instagram.singleton'];
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['instagram.singleton'];
}

/**
* Get the config path
*
* @return string
*/
protected function getConfigPath() {
return config_path('mm-instagram-api.php');
}
/**
* Get the config path
*
* @return string
*/
protected function getConfigPath()
{
return config_path('mm-instagram-api.php');
}
}

0 comments on commit 590b4b3

Please sign in to comment.