robertfausk /
behat-screenshot-image-driver-url
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Bex\Behat\ScreenshotExtension\Driver; |
||
| 4 | |||
| 5 | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
||
| 6 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
| 7 | |||
| 8 | class Url extends Local implements ImageDriverInterface |
||
| 9 | { |
||
| 10 | const CONFIG_PARAM_SCREENSHOT_URL = 'screenshot_url'; |
||
| 11 | |||
| 12 | private $screenshotUrl; |
||
| 13 | private $screenshotDirectory; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @param ArrayNodeDefinition $builder |
||
| 17 | * |
||
| 18 | * @return void |
||
| 19 | */ |
||
| 20 | public function configure(ArrayNodeDefinition $builder) |
||
| 21 | { |
||
| 22 | parent::configure($builder); |
||
| 23 | |||
| 24 | $builder |
||
| 25 | ->children() |
||
| 26 | ->scalarNode(self::CONFIG_PARAM_SCREENSHOT_URL) |
||
| 27 | ->end() |
||
| 28 | ->end(); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param ContainerBuilder $container |
||
| 33 | * @param array $config |
||
| 34 | * |
||
| 35 | * @return void |
||
| 36 | */ |
||
| 37 | public function load(ContainerBuilder $container, array $config) |
||
| 38 | { |
||
| 39 | parent::load($container, $config); |
||
| 40 | |||
| 41 | $this->screenshotUrl = $config[self::CONFIG_PARAM_SCREENSHOT_URL]; |
||
| 42 | $this->screenshotDirectory = $config[self::CONFIG_PARAM_SCREENSHOT_DIRECTORY]; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param string $binaryImage |
||
| 47 | * @param string $filename |
||
| 48 | * |
||
| 49 | * @return string URL to the image |
||
| 50 | */ |
||
| 51 | public function upload($binaryImage, $filename) |
||
| 52 | { |
||
| 53 | $urlToImage = parent::upload($binaryImage, $filename); |
||
| 54 | $externUrlToImage = str_replace($this->screenshotDirectory, $this->screenshotUrl, $urlToImage); |
||
| 55 | |||
| 56 | return sprintf("%s or %s", $urlToImage, $externUrlToImage); |
||
| 57 | } |
||
| 58 | } |
||
| 59 |