| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Sepia\PoParser\SourceHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  *    Copyright (c) 2012 Raúl Ferràs [email protected] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  *    All rights reserved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  *    Redistribution and use in source and binary forms, with or without | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  *    modification, are permitted provided that the following conditions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  *    are met: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  *    1. Redistributions of source code must retain the above copyright | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  *       notice, this list of conditions and the following disclaimer. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  *    2. Redistributions in binary form must reproduce the above copyright | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  *       notice, this list of conditions and the following disclaimer in the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  *       documentation and/or other materials provided with the distribution. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  *    3. Neither the name of copyright holders nor the names of its | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  *       contributors may be used to endorse or promote products derived | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  *       from this software without specific prior written permission. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  *    ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  *    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  *    PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  *    BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  *    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  *    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  *    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  *    POSSIBILITY OF SUCH DAMAGE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * https://github.com/raulferras/PHP-po-parser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | class StringSource implements SourceHandler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** @var string[] */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     protected $strings; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** @var int */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     protected $line; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** @var int */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     protected $total; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     public function __construct($string) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->line = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->strings = explode("\n",$string); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->total = count($this->strings); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     public function getNextLine() | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         if (isset($this->strings[$this->line])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |             $result = $this->strings[$this->line]; | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             $this->line++; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |             $result = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         return $result; | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public function ended() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         return ($this->line>=$this->total); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     public function close() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->line = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     public function save($ignore) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |  |