/** * Initializes the component by validating [[apiKey]]. * * @throws InvalidConfigException if [[apiKey]] is not set. * @throws UnauthorizedHttpException if [[apiKey]] could not be validated. */ public function init() { if (!$this->apiKey) { throw new InvalidConfigException("The property 'apiKey' must be in set in " . get_class($this) . "."); } try { Tinify\setKey($this->apiKey); Tinify\validate(); } catch (\Tinify\Exception $e) { throw new UnauthorizedHttpException("The specified apiKey '{$this->apiKey}' could not be validated."); } }
public function update() { $this->setStatus(self::UNKNOWN); if ($this->config->apply()) { try { Tinify\validate(); $this->setStatus(self::SUCCESS); $this->setLastError(null); } catch (\Exception $err) { $this->setStatus(self::FAILURE); $this->setLastError($err->getMessage()); } $this->setCompressionCount(Tinify\getCompressionCount()); } $this->save(); }
/** * Runs TinyPNG optimization * * @param $file * @param $transform */ public function runTinyPng($file) { try { \Tinify\setKey($this->getSetting('tinyPngApiKey')); \Tinify\validate(); \Tinify\fromFile($file)->toFile($file); } catch (\Tinify\Exception $e) { ImagerPlugin::log("Could not validate connection to TinyPNG, image was not optimized.", LogLevel::Error); } }