Skip to content

Commit 18c476c

Browse files
author
Bhavin Rudani
committed
added laravel 8 compatibility
1 parent 7a914c8 commit 18c476c

File tree

5 files changed

+84
-62
lines changed

5 files changed

+84
-62
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ fabric.properties
7272

7373
# *.iml
7474
# modules.xml
75+
76+
# PHP CS Fixer
77+
.php_cs.cache

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=5.5.0",
15-
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.x",
16-
"tinify/tinify":"~1.1"
14+
"php": ">=7.4",
15+
"illuminate/support": "^6.0 || ^7.0 || ^8.0",
16+
"tinify/tinify":"~1.5"
1717
},
1818
"autoload": {
1919
"psr-4": {

src/Facades/Tinify.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
<?php
1+
<?php
2+
23
namespace msonowal\LaravelTinify\Facades;
4+
35
use Illuminate\Support\Facades\Facade;
4-
class Tinify extends Facade {
5-
protected static function getFacadeAccessor(){
6-
return 'tinify';
7-
}
8-
}
6+
7+
class Tinify extends Facade
8+
{
9+
protected static function getFacadeAccessor()
10+
{
11+
return 'tinify';
12+
}
13+
}

src/LaravelTinifyServiceProvider.php

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,57 @@
1-
<?php
1+
<?php
22

33
namespace msonowal\LaravelTinify;
44

55
use Illuminate\Support\ServiceProvider;
66
use Tinify\Tinify;
77

8-
class LaravelTinifyServiceProvider extends ServiceProvider {
9-
10-
/**
11-
* Indicates if loading of the provider is deferred.
12-
*
13-
* @var bool
14-
*/
15-
protected $defer = false;
16-
17-
/**
18-
* Register custom form macros on package start
19-
* @return void
20-
*/
21-
public function boot()
8+
class LaravelTinifyServiceProvider extends ServiceProvider
9+
{
10+
11+
/**
12+
* Indicates if loading of the provider is deferred.
13+
*
14+
* @var bool
15+
*/
16+
protected $defer = false;
17+
18+
/**
19+
* Register custom form macros on package start
20+
* @return void
21+
*/
22+
public function boot()
2223
{
2324
$this->publishConfiguration();
2425
}
2526

26-
/**
27-
* Register the service provider.
28-
*
29-
* @return void
30-
*/
31-
public function register()
32-
{
33-
34-
$config = __DIR__ . '/../config/tinify.php';
27+
/**
28+
* Register the service provider.
29+
*
30+
* @return void
31+
*/
32+
public function register()
33+
{
34+
$config = __DIR__ . '/../config/tinify.php';
3535
$this->mergeConfigFrom($config, 'tinify');
36-
$this->app->bind('tinify', 'msonowal\LaravelTinify\Services\TinifyService');
37-
38-
}
39-
40-
/**
41-
* Get the services provided by the provider.
42-
*
43-
* @return array
44-
*/
45-
public function provides()
46-
{
47-
return array();
48-
}
49-
public function publishConfiguration()
36+
$this->app->bind('tinify', 'msonowal\LaravelTinify\Services\TinifyService');
37+
}
38+
39+
/**
40+
* Get the services provided by the provider.
41+
*
42+
* @return array
43+
*/
44+
public function provides()
5045
{
51-
$path = realpath(__DIR__.'/../config/tinify.php');
52-
$this->publishes([$path => config_path('tinify.php')], 'config');
46+
return [];
5347
}
5448

55-
}
49+
public function publishConfiguration()
50+
{
51+
$this->publishes([
52+
__DIR__.'/../config/tinify.php' => config_path('tinify.php'),
53+
], 'config');
54+
// $path = realpath(__DIR__.'/../config/tinify.php');
55+
// $this->publishes([$path => config_path('tinify.php')], 'config');
56+
}
57+
}

src/Services/TinifyService.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,68 @@
11
<?php
22

33
namespace msonowal\LaravelTinify\Services;
4+
45
use Tinify\Source;
56
use Tinify\Tinify;
6-
class TinifyService {
7+
8+
class TinifyService
9+
{
710
/**
811
* Get api key from env, fail if any are missing.
912
* Instantiate API client and set api key.
1013
*
1114
* @throws Exception
1215
*/
13-
public function __construct() {
16+
public function __construct()
17+
{
1418
$this->apikey = config('tinify.api_key');
15-
if(!$this->apikey) {
19+
if (!$this->apikey) {
1620
throw new \InvalidArgumentException('Please set TINIFY_APIKEY in environment variables or in config.');
1721
}
1822
$this->client = new Tinify();
1923
$this->client->setKey($this->apikey);
2024
}
21-
public function setKey($key) {
25+
public function setKey($key)
26+
{
2227
return $this->client->setKey($key);
2328
}
2429

25-
public function setAppIdentifier($appIdentifier) {
30+
public function setAppIdentifier($appIdentifier)
31+
{
2632
return $this->client->setAppIdentifier($appIdentifier);
2733
}
2834

29-
public function getCompressionCount() {
35+
public function getCompressionCount()
36+
{
3037
return $this->client->getCompressionCount();
3138
}
3239

33-
public function compressionCount() {
40+
public function compressionCount()
41+
{
3442
return $this->client->getCompressionCount();
3543
}
3644

37-
public function fromFile($path) {
45+
public function fromFile($path)
46+
{
3847
return Source::fromFile($path);
3948
}
4049

41-
public function fromBuffer($string) {
50+
public function fromBuffer($string)
51+
{
4252
return Source::fromBuffer($string);
4353
}
4454

45-
public function fromUrl($string) {
55+
public function fromUrl($string)
56+
{
4657
return Source::fromUrl($string);
4758
}
4859

49-
public function validate() {
60+
public function validate()
61+
{
5062
try {
5163
$this->client->getClient()->request("post", "/shrink");
5264
} catch (ClientException $e) {
5365
return true;
5466
}
5567
}
56-
}
68+
}

0 commit comments

Comments
 (0)