public static function register(\Texy $texy, ImagePipe $imagePipe) { $texy->addHandler("image", function (\TexyHandlerInvocation $invocation, \TexyImage $image, $link) use($imagePipe) { $arguments = Helpers::prepareMacroArguments($image->URL); try { $image->URL = $imagePipe->setNamespace($arguments["namespace"])->request($arguments["name"], $arguments["size"], $arguments["flags"], TRUE); } catch (FileNotFoundException $e) { $image->URL = $arguments["name"]; if (!empty($arguments["size"])) { list($image->width, $image->height) = explode("x", $arguments["size"]); } } return $invocation->proceed($image, $link); }); }
/** * @param Nette\Latte\MacroNode $node * @param Nette\Latte\PhpWriter $writer * @return string * @throws Nette\Latte\CompileException */ public function macroAttrImg(MacroNode $node, PhpWriter $writer) { $this->isUsed = TRUE; $arguments = Helpers::prepareMacroArguments($node->args); if ($arguments["name"] === NULL) { throw new Nette\Latte\CompileException("Please provide filename."); } $namespace = $arguments["namespace"]; unset($arguments["namespace"]); $arguments = array_map(function ($value) use($writer) { return $value ? $writer->formatWord($value) : 'NULL'; }, $arguments); $command = '$_imagePipe'; $command .= $namespace !== NULL ? '->setNamespace(' . $writer->formatWord(trim($namespace)) . ')' : ''; $command .= '->request(' . implode(", ", $arguments) . ')'; return $writer->write('?> src="<?php echo %escape(' . $writer->formatWord($command) . ')?>" <?php'); }
/** * @param \Texy|\Texy\Texy $texy * @param ImagePipe $imagePipe */ public static function register($texy, ImagePipe $imagePipe) { if (!$texy instanceof \Texy && !$texy instanceof \Texy\Texy) { throw new \InvalidArgumentException('The $texy parameter is not instance of Texy or Texy\\Texy'); } $texy->addHandler("image", function ($invocation, $image, $link) use($imagePipe) { if (!$invocation instanceof \TexyHandlerInvocation && !$invocation instanceof \Texy\HandlerInvocation) { throw new \InvalidArgumentException('The $invocation parameter is not instance of TexyHandlerInvocation or Texy\\HandlerInvocation'); } if (!$image instanceof \TexyImage && !$image instanceof \Texy\Image) { throw new \InvalidArgumentException('The $image parameter is not instance of TexyImage or Texy\\Image'); } $arguments = Helpers::prepareMacroArguments($image->URL); try { $image->URL = $imagePipe->setNamespace($arguments["namespace"])->request($arguments["name"], $arguments["size"], $arguments["flags"], TRUE); } catch (FileNotFoundException $e) { $image->URL = $arguments["name"]; if (!empty($arguments["size"])) { list($image->width, $image->height) = explode("x", $arguments["size"]); } } return $invocation->proceed($image, $link); }); }