forked from msonowal/laravel-tinify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bhavin Rudani
committed
Apr 21, 2021
1 parent
7a914c8
commit 18c476c
Showing
5 changed files
with
84 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,3 +72,6 @@ fabric.properties | |
|
||
# *.iml | ||
# modules.xml | ||
|
||
# PHP CS Fixer | ||
.php_cs.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |