mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 03:57:32 -05:00 
			
		
		
		
	Refactor logic for replacing variables
This commit is contained in:
		
							parent
							
								
									92b2295db1
								
							
						
					
					
						commit
						66d23cd816
					
				@ -2,8 +2,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Tests\Feature\PdfMaker;
 | 
					namespace Tests\Feature\PdfMaker;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use DOMDocument;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class PdfMaker
 | 
					class PdfMaker
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    use PdfMakerUtilities;
 | 
					    use PdfMakerUtilities;
 | 
				
			||||||
@ -42,9 +40,7 @@ class PdfMaker
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach ($this->data['variables'] as $entry) {
 | 
					        $this->updateVariables($this->data['variables']);
 | 
				
			||||||
            $this->updateVariable($entry['id'], $entry['variable'], $entry['value']);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -95,7 +95,7 @@ class PdfMakerTest extends TestCase
 | 
				
			|||||||
                ],
 | 
					                ],
 | 
				
			||||||
            ],
 | 
					            ],
 | 
				
			||||||
            'variables' => [
 | 
					            'variables' => [
 | 
				
			||||||
                ['id' => 'header', 'variable' => '$title', 'value' => 'Invoice Ninja'],
 | 
					                '$title' => 'Invoice Ninja',
 | 
				
			||||||
            ],
 | 
					            ],
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -49,6 +49,15 @@ trait PdfMakerUtilities
 | 
				
			|||||||
        return $element;
 | 
					        return $element;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function updateVariables(array $variables)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $html = strtr($this->getCompiledHTML(), $variables);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->document->loadHTML($html);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->document->saveHTML();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function updateVariable(string $element, string $variable, string $value)
 | 
					    public function updateVariable(string $element, string $variable, string $value)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $element = $this->document->getElementById($element);
 | 
					        $element = $this->document->getElementById($element);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user