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 commit 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 CommitFactory 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
|
52 |
|
public function canHandle(PathInformationInterface $path, $mode) |
58
|
|
|
{ |
59
|
52 |
|
return $path->hasArgument('commit'); |
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
|
2 |
|
public function createFileBuffer(PathInformationInterface $path, $mode) |
70
|
|
|
{ |
71
|
2 |
|
$repo = $path->getRepository(); |
72
|
2 |
|
$buffer = $repo->showCommit($path->getArgument('ref')); |
73
|
2 |
|
return new StringBuffer($buffer, array(), 'r'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|