| 1 |
<?php |
| 2 |
namespace Depicter\Front; |
| 3 |
|
| 4 |
|
| 5 |
use Depicter\Html\Html; |
| 6 |
|
| 7 |
class Symbols |
| 8 |
{ |
| 9 |
|
| 10 |
private $symbols = []; |
| 11 |
|
| 12 |
private $clipPathIDs = []; |
| 13 |
|
| 14 |
/** |
| 15 |
* Add symbol id to symbols list |
| 16 |
* |
| 17 |
* @param string $symbolID |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
public function add( $symbolID ) { |
| 21 |
if ( !in_array( $symbolID, $this->symbols ) ) { |
| 22 |
$this->symbols[] = $symbolID; |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Add symbol id to symbols list |
| 28 |
* |
| 29 |
* @param string $symbolID |
| 30 |
* @return void |
| 31 |
*/ |
| 32 |
public function addClipPath( $clipPathID ) { |
| 33 |
if ( !in_array( $clipPathID, $this->clipPathIDs ) ) { |
| 34 |
$this->clipPathIDs[] = $clipPathID; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Render registered svg symbols |
| 40 |
* |
| 41 |
* @return string|\TypeRocket\Html\Html |
| 42 |
*/ |
| 43 |
public function render() { |
| 44 |
$symbolsContent = ''; |
| 45 |
|
| 46 |
$clipPathContent = ''; |
| 47 |
if ( !empty( $this->symbols ) ) { |
| 48 |
foreach ( $this->symbols as $key => $symbolID ) { |
| 49 |
if ( file_exists( DEPICTER_PLUGIN_PATH .'/resources/scripts/svg-symbols/' . $symbolID . '.svg' ) ) { |
| 50 |
$symbolsContent .= \Depicter::storage()->filesystem()->read( DEPICTER_PLUGIN_PATH .'/resources/scripts/svg-symbols/' . $symbolID . '.svg' ); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
$symbolsContent = Html::el('svg', [ 'xmlns' => "http://www.w3.org/2000/svg" ], $symbolsContent ); |
| 55 |
} |
| 56 |
|
| 57 |
if ( !empty( $this->clipPathIDs ) ) { |
| 58 |
foreach ( $this->clipPathIDs as $key => $clipPathID ) { |
| 59 |
if ( file_exists( DEPICTER_PLUGIN_PATH .'/resources/scripts/svg-symbols/clipPaths/' . $clipPathID . '.svg' ) ) { |
| 60 |
$clipPathContent .= \Depicter::storage()->filesystem()->read( DEPICTER_PLUGIN_PATH .'/resources/scripts/svg-symbols/clipPaths/' . $clipPathID . '.svg' ). "\n"; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
$clipPathContent = "\n" .Html::el('defs', [], "\n" . $clipPathContent ); |
| 65 |
$clipPathContent = Html::el('svg', [ |
| 66 |
//'xmlns' => "http://www.w3.org/2000/svg", |
| 67 |
'width' => '0', |
| 68 |
'height' => '0', |
| 69 |
'class' => 'depicter-svg-clip-paths' |
| 70 |
], $clipPathContent . "\n" ); |
| 71 |
} |
| 72 |
|
| 73 |
return $symbolsContent . "\n". $clipPathContent; |
| 74 |
} |
| 75 |
} |
| 76 |
|