Passed
Push — master ( ce725d...c4b0c0 )
by Aimeos
06:00
created

Standard::baseurl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2014
6
 * @copyright Aimeos (aimeos.org), 2015-2021
7
 * @package MW
8
 * @subpackage View
9
 */
10
11
12
namespace Aimeos\MW\View\Helper\Content;
13
14
15
/**
16
 * View helper class for generating media URLs
17
 *
18
 * @package MW
19
 * @subpackage View
20
 */
21
class Standard
22
	extends \Aimeos\MW\View\Helper\Base
23
	implements \Aimeos\MW\View\Helper\Content\Iface
24
{
25
	private $baseurls = [];
26
	private $enc;
27
28
29
	/**
30
	 * Initializes the content view helper.
31
	 *
32
	 * @param \Aimeos\MW\View\Iface $view View instance with registered view helpers
33
	 */
34
	public function __construct( \Aimeos\MW\View\Iface $view )
35
	{
36
		parent::__construct( $view );
37
		$this->enc = $view->encoder();
0 ignored issues
show
Bug introduced by
The method encoder() does not exist on Aimeos\MW\View\Iface. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
		/** @scrutinizer ignore-call */ 
38
  $this->enc = $view->encoder();
Loading history...
38
	}
39
40
41
	/**
42
	 * Returns the complete encoded content URL.
43
	 *
44
	 * @param string|null $url Absolute, relative or data: URL
45
	 * @param string $fsname File system name the file is stored at
46
	 * @return string Complete encoded content URL
47
	 */
48
	public function transform( ?string $url, $fsname = 'fs-media' ) : string
49
	{
50
		if( $url && !\Aimeos\MW\Str::starts( $url, ['http', 'data:', '/'] ) ) {
51
			$url = $this->baseurl( $fsname ) . '/' . $url;
52
		}
53
54
		return $this->enc->attr( $url );
55
	}
56
57
58
	/**
59
	 * Returns the base URL for the given file system.
60
	 *
61
	 * @param string $fsname File system name
62
	 * @return string Base URL of the file system
63
	 */
64
	protected function baseurl( string $fsname ) : string
65
	{
66
		if( !isset( $this->baseurls[$fsname] ) ) {
67
			$this->baseurls[$fsname] = rtrim( $this->getView()->config( 'resource/' . $fsname . '/baseurl' ), '/' );
0 ignored issues
show
Bug introduced by
The method config() does not exist on Aimeos\MW\View\Iface. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
			$this->baseurls[$fsname] = rtrim( $this->getView()->/** @scrutinizer ignore-call */ config( 'resource/' . $fsname . '/baseurl' ), '/' );
Loading history...
68
		}
69
70
		return $this->baseurls[$fsname];
71
	}
72
}
73