Skip to content

Commit

Permalink
added laravel 8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavin Rudani committed Apr 21, 2021
1 parent 7a914c8 commit 18c476c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 62 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ fabric.properties

# *.iml
# modules.xml

# PHP CS Fixer
.php_cs.cache
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
}
],
"require": {
"php": ">=5.5.0",
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.x",
"tinify/tinify":"~1.1"
"php": ">=7.4",
"illuminate/support": "^6.0 || ^7.0 || ^8.0",
"tinify/tinify":"~1.5"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 11 additions & 6 deletions src/Facades/Tinify.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?php
<?php

namespace msonowal\LaravelTinify\Facades;

use Illuminate\Support\Facades\Facade;
class Tinify extends Facade {
protected static function getFacadeAccessor(){
return 'tinify';
}
}

class Tinify extends Facade
{
protected static function getFacadeAccessor()
{
return 'tinify';
}
}
84 changes: 43 additions & 41 deletions src/LaravelTinifyServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
<?php
<?php

namespace msonowal\LaravelTinify;

use Illuminate\Support\ServiceProvider;
use Tinify\Tinify;

class LaravelTinifyServiceProvider extends ServiceProvider {

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

/**
* Register custom form macros on package start
* @return void
*/
public function boot()
class LaravelTinifyServiceProvider extends ServiceProvider
{

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

/**
* Register custom form macros on package start
* @return void
*/
public function boot()
{
$this->publishConfiguration();
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{

$config = __DIR__ . '/../config/tinify.php';
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$config = __DIR__ . '/../config/tinify.php';
$this->mergeConfigFrom($config, 'tinify');
$this->app->bind('tinify', 'msonowal\LaravelTinify\Services\TinifyService');

}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array();
}
public function publishConfiguration()
$this->app->bind('tinify', 'msonowal\LaravelTinify\Services\TinifyService');
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
$path = realpath(__DIR__.'/../config/tinify.php');
$this->publishes([$path => config_path('tinify.php')], 'config');
return [];
}

}
public function publishConfiguration()
{
$this->publishes([
__DIR__.'/../config/tinify.php' => config_path('tinify.php'),
], 'config');
// $path = realpath(__DIR__.'/../config/tinify.php');
// $this->publishes([$path => config_path('tinify.php')], 'config');
}
}
36 changes: 24 additions & 12 deletions src/Services/TinifyService.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,68 @@
<?php

namespace msonowal\LaravelTinify\Services;

use Tinify\Source;
use Tinify\Tinify;
class TinifyService {

class TinifyService
{
/**
* Get api key from env, fail if any are missing.
* Instantiate API client and set api key.
*
* @throws Exception
*/
public function __construct() {
public function __construct()
{
$this->apikey = config('tinify.api_key');
if(!$this->apikey) {
if (!$this->apikey) {
throw new \InvalidArgumentException('Please set TINIFY_APIKEY in environment variables or in config.');
}
$this->client = new Tinify();
$this->client->setKey($this->apikey);
}
public function setKey($key) {
public function setKey($key)
{
return $this->client->setKey($key);
}

public function setAppIdentifier($appIdentifier) {
public function setAppIdentifier($appIdentifier)
{
return $this->client->setAppIdentifier($appIdentifier);
}

public function getCompressionCount() {
public function getCompressionCount()
{
return $this->client->getCompressionCount();
}

public function compressionCount() {
public function compressionCount()
{
return $this->client->getCompressionCount();
}

public function fromFile($path) {
public function fromFile($path)
{
return Source::fromFile($path);
}

public function fromBuffer($string) {
public function fromBuffer($string)
{
return Source::fromBuffer($string);
}

public function fromUrl($string) {
public function fromUrl($string)
{
return Source::fromUrl($string);
}

public function validate() {
public function validate()
{
try {
$this->client->getClient()->request("post", "/shrink");
} catch (ClientException $e) {
return true;
}
}
}
}

0 comments on commit 18c476c

Please sign in to comment.