public function testAsImage() { $value = 'http://sample.com/img.jpg'; $this->assertSame("<img src=\"{$value}\" alt=\"\">", $this->formatter->asImage($value)); // null display $this->assertSame($this->formatter->nullDisplay, $this->formatter->asImage(null)); }
public function asImage($value, $options = []) { if ($value === null) { return $this->nullDisplay; } if (empty($value)) { if (isset($options['default'])) { $value = \Yii::$app->params['domain']['data'] . $options['default']; unset($options['default']); } else { $value = \Yii::$app->params['domain']['data'] . \Yii::$app->params['image']['default']['common']; } } if (!preg_match('/\\b(([\\w-]+:\\/\\/?|www[.])[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|\\/)))/i', $value)) { $value = \Yii::$app->params['domain']['data'] . $value; } return parent::asImage($value, $options); }