| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Copyright (C) 2017 by TEQneers GmbH & Co. KG | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * in the Software without restriction, including without limitation the rights | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * furnished to do so, subject to the following conditions: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * The above copyright notice and this permission notice shall be included in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * all copies or substantial portions of the Software. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * THE SOFTWARE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * Git Stream Wrapper for PHP | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * @category   TQ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * @package    TQ_VCS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * @subpackage VCS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * @copyright  Copyright (C) 2018 by TEQneers GmbH & Co. KG | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | namespace TQ\Vcs\StreamWrapper\FileBuffer\Factory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | use TQ\Vcs\Buffer\FileBufferInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use TQ\Vcs\StreamWrapper\FileBuffer\FactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | use TQ\Vcs\Buffer\StringBuffer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | use TQ\Vcs\StreamWrapper\PathInformationInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  * Factory to create a default buffer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  * @author     Stefan Gehrig <gehrigteqneers.de> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  * @category   TQ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  * @package    TQ_VCS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  * @subpackage VCS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  * @copyright  Copyright (C) 2018 by TEQneers GmbH & Co. KG | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | class DefaultFactory implements FactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * Returns true if this factory can handle the requested path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @param   PathInformationInterface     $path   The path information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @param   string                       $mode   The mode used to open the file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @return  boolean                              True if this factory can handle the path | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 4 |  |     public function canHandle(PathInformationInterface $path, $mode) | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 | 4 |  |         return true; | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * Returns the file stream to handle the requested path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @param   PathInformationInterface     $path   The path information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @param   string                       $mode   The mode used to open the path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @return  FileBufferInterface                  The file buffer to handle the path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 4 |  |     public function createFileBuffer(PathInformationInterface $path, $mode) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 4 |  |         $repo       = $path->getRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 4 |  |         $buffer     = $repo->showFile($path->getLocalPath(), $path->getRef()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 4 |  |         $objectInfo = $repo->getObjectInfo($path->getLocalPath(), $path->getRef()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 4 |  |         return new StringBuffer($buffer, $objectInfo, 'r'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |  |