Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       100.00%  | 
       14 / 14  | 
               | 
       100.00%  | 
       1 / 1  | 
       CRAP |         | 
       100.00%  | 
       1 / 1  | 
      
| Container |         | 
       100.00%  | 
       14 / 14  | 
               | 
       100.00%  | 
       1 / 1  | 
       5 |         | 
       100.00%  | 
       1 / 1  | 
      
| write |         | 
       100.00%  | 
       14 / 14  | 
               | 
       100.00%  | 
       1 / 1  | 
       5 | |||
| 1 | <?php | 
| 2 | |
| 3 | /** | 
| 4 | * This file is part of PHPWord - A pure PHP library for reading and writing | 
| 5 | * word processing documents. | 
| 6 | * | 
| 7 | * PHPWord is free software distributed under the terms of the GNU Lesser | 
| 8 | * General Public License version 3 as published by the Free Software Foundation. | 
| 9 | * | 
| 10 | * For the full copyright and license information, please read the LICENSE | 
| 11 | * file that was distributed with this source code. For the full list of | 
| 12 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. | 
| 13 | * | 
| 14 | * @see https://github.com/PHPOffice/PHPWord | 
| 15 | * | 
| 16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 | 
| 17 | */ | 
| 18 | |
| 19 | namespace PhpOffice\PhpWord\Writer\RTF\Element; | 
| 20 | |
| 21 | use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement; | 
| 22 | |
| 23 | /** | 
| 24 | * Container element RTF writer. | 
| 25 | * | 
| 26 | * @since 0.11.0 | 
| 27 | */ | 
| 28 | class Container extends AbstractElement | 
| 29 | { | 
| 30 | /** | 
| 31 | * Namespace; Can't use __NAMESPACE__ in inherited class (RTF). | 
| 32 | * | 
| 33 | * @var string | 
| 34 | */ | 
| 35 | protected $namespace = 'PhpOffice\\PhpWord\\Writer\\RTF\\Element'; | 
| 36 | |
| 37 | /** | 
| 38 | * Write container. | 
| 39 | * | 
| 40 | * @return string | 
| 41 | */ | 
| 42 | public function write() | 
| 43 | { | 
| 44 | $container = $this->element; | 
| 45 | if (!$container instanceof ContainerElement) { | 
| 46 | return ''; | 
| 47 | } | 
| 48 | $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); | 
| 49 | $withoutP = in_array($containerClass, ['TextRun', 'Footnote', 'Endnote']) ? true : false; | 
| 50 | $content = ''; | 
| 51 | |
| 52 | $elements = $container->getElements(); | 
| 53 | foreach ($elements as $element) { | 
| 54 | $elementClass = get_class($element); | 
| 55 | $writerClass = str_replace('PhpOffice\\PhpWord\\Element', $this->namespace, $elementClass); | 
| 56 | if (class_exists($writerClass)) { | 
| 57 | /** @var AbstractElement $writer Type hint */ | 
| 58 | $writer = new $writerClass($this->parentWriter, $element, $withoutP); | 
| 59 | $content .= $writer->write(); | 
| 60 | } | 
| 61 | } | 
| 62 | |
| 63 | return $content; | 
| 64 | } | 
| 65 | } |