/**
  * @inheritDoc ITask::runStep()
  *
  * @param int $step
  *
  * @return bool
  */
 public function runStep($step)
 {
     if (is_array($this->_paths)) {
         $path = $this->_paths[$step];
     } else {
         $path = $this->_paths;
     }
     Tinify\setKey(craft()->imager->getSetting('tinyPngApiKey'));
     Tinify\fromFile($path)->toFile($path);
     return true;
 }
示例#2
0
 /**
  * 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.");
     }
 }
示例#3
0
 public function apply()
 {
     if ($this->configured) {
         return true;
     }
     $key = $this->getKey();
     if (empty($key)) {
         return false;
     }
     Tinify\setKey($key);
     $name = $this->magentoInfo->getName();
     $version = $this->magentoInfo->getVersion();
     $edition = $this->magentoInfo->getEdition();
     Tinify\setAppIdentifier("{$name}/{$version} ({$edition})");
     return $this->configured = true;
 }
示例#4
0
 /**
  * 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);
     }
 }
 public function testUpdateSetsUnexpectedFailureData()
 {
     Tinify\setKey("my_key");
     $this->config->method("apply")->willReturn(true);
     AspectMock\Test::double("Tinify\\Client", ["request" => function () {
         throw new \Exception("unexpected error");
     }]);
     $this->cache->expects($this->once())->method("save")->with(serialize(["status" => 2, "last_error" => "unexpected error"]), "tinify_status");
     $this->status->update();
 }