| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  *  ____  _     _                       _ _ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * |  _ \| |__ | |_ ___ _ __ ___   __ _(_) | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | |_) | '_ \| __/ _ \ '_ ` _ \ / _` | | | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * |  __/| | | | ||  __/ | | | | | (_| | | | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * |_|   |_| |_|\__\___|_| |_| |_|\__,_|_|_| | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * This file is part of Kristuff\Phtemail. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * (c) Kristuff <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @version    0.2.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @copyright  2017-2020 Kristuff | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | namespace Kristuff\Phtemail\Core; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | /**  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * Class HtmlContainerElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * Abstract base class for Html email elements that can have child(s) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | abstract class HtmlContainerElement extends HtmlElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /**  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * Allow to set padding and remove top/bottom padding | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     use \Kristuff\Phtemail\Core\ContainerPaddingTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /**  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * Allow to set v/h align | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     use \Kristuff\Phtemail\Core\ContainerAlignTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /**  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * The content of the email | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @access private | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @var array   $childElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     protected $childElements = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /**  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * Add an element to the HtmlElement collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @access public  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @param HtmlElement   $element    An html element | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public function add(HtmlElement $element) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $element->setParent($this); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->childElements[] = $element; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /**  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * Get the html element collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @access public  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function elements() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         return $this->childElements; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /**  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * Gets the HTML  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param string        $indent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @return string       The html string content | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |     public function getHtml(string $indent) | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |         // html result. start with an empty string or a html comment | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |         $html  = $this->getBuilder()->getHtmlComment('BLOCK', $indent); | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |       | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |         // render child elements collection | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |         foreach ($this->elements() as $element){ | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |             $html .= PHP_EOL . $element->getHtml($indent); | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |          | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |         // ending comment | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |         $html  .= $this->getBuilder()->getHtmlComment('END BLOCK', $indent); | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |         // return the build html  | 
            
                                                        
            
                                    
            
            
                | 94 |  |  |         return $html; | 
            
                                                        
            
                                    
            
            
                | 95 |  |  |     }     | 
            
                                                        
            
                                    
            
            
                | 96 |  |  | } |