| Conditions | 3 |
| Paths | 2 |
| Total Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | public function compile(string $view): string |
||
| 18 | { |
||
| 19 | foreach ($this->bladeX->getRegisteredComponents() as $componentName => $classOrView) { |
||
| 20 | $pattern = '/<\s*'.$componentName.'[^>]*>((.|\n)*?)<\s*\/\s*'.$componentName.'>/m'; |
||
| 21 | |||
| 22 | $view = preg_replace_callback($pattern, function ($result) use ($classOrView) { |
||
| 23 | [$component, $contents] = $result; |
||
| 24 | |||
| 25 | $xml = new SimpleXMLElement($component); |
||
| 26 | |||
| 27 | $data = '['; |
||
| 28 | |||
| 29 | foreach ($xml->attributes() as $attribute => $value) { |
||
| 30 | $value = str_replace("'","\\'", $value); |
||
| 31 | $data .= "'{$attribute}' => '{$value}',"; |
||
| 32 | } |
||
| 33 | |||
| 34 | $data .= ']'; |
||
| 35 | |||
| 36 | $pattern = '/<\s*slot[^>]*name=[\'"](.*)[\'"][^>]*>((.|\n)*?)<\s*\/\s*slot>/m'; |
||
| 37 | |||
| 38 | $contents = preg_replace_callback($pattern, function ($result) { |
||
| 39 | [$slot, $name, $contents] = $result; |
||
| 40 | |||
| 41 | return "@slot('{$name}'){$contents}@endslot"; |
||
| 42 | }, $contents); |
||
| 43 | |||
| 44 | return "@component('{$classOrView}', {$data})".$contents."@endcomponent"; |
||
| 45 | }, $view); |
||
| 46 | } |
||
| 47 | |||
| 48 | return $view; |
||
| 49 | } |
||
| 50 | } |