@@ -24,6 +24,7 @@ class Tree
24
24
protected $ hash ;
25
25
protected $ isInitialized = false ;
26
26
protected $ entries ;
27
+ protected $ entriesByType ;
27
28
28
29
public function __construct (Repository $ repository , $ hash )
29
30
{
@@ -47,31 +48,68 @@ protected function initialize()
47
48
$ parser ->parse ($ output );
48
49
49
50
$ this ->entries = [];
51
+ $ this ->entriesByType = [
52
+ 'blob ' => [],
53
+ 'tree ' => [],
54
+ 'commit ' => [],
55
+ ];
50
56
51
57
foreach ($ parser ->entries as $ entry ) {
52
58
list ($ mode , $ type , $ hash , $ name ) = $ entry ;
53
59
if ($ type == 'blob ' ) {
54
- $ this -> entries [ $ name ] = [$ mode , $ this ->repository ->getBlob ($ hash )];
60
+ $ treeEntry = [$ mode , $ this ->repository ->getBlob ($ hash )];
55
61
} elseif ($ type == 'tree ' ) {
56
- $ this -> entries [ $ name ] = [$ mode , $ this ->repository ->getTree ($ hash )];
62
+ $ treeEntry = [$ mode , $ this ->repository ->getTree ($ hash )];
57
63
} else {
58
- $ this -> entries [ $ name ] = [$ mode , new CommitReference ($ hash )];
64
+ $ treeEntry = [$ mode , new CommitReference ($ hash )];
59
65
}
66
+ $ this ->entries [$ name ] = $ treeEntry ;
67
+ $ this ->entriesByType [$ type ][$ name ] = $ treeEntry ;
60
68
}
61
69
62
70
$ this ->isInitialized = true ;
63
71
}
64
72
65
73
/**
66
- * @return array An associative array name => $object
74
+ * @return array<string, array{string, CommitReference|Tree|Blob}> An associative array name => $object
67
75
*/
68
- public function getEntries ()
76
+ public function getEntries (): array
69
77
{
70
78
$ this ->initialize ();
71
79
72
80
return $ this ->entries ;
73
81
}
74
82
83
+ /**
84
+ * @return array<string, array{string, CommitReference}> An associative array of name => [mode, commit reference]
85
+ */
86
+ public function getCommitReferenceEntries (): array
87
+ {
88
+ $ this ->initialize ();
89
+
90
+ return $ this ->entriesByType ['commit ' ];
91
+ }
92
+
93
+ /**
94
+ * @return array<string, array{string, Tree}> An associative array of name => [mode, tree]
95
+ */
96
+ public function getTreeEntries (): array
97
+ {
98
+ $ this ->initialize ();
99
+
100
+ return $ this ->entriesByType ['tree ' ];
101
+ }
102
+
103
+ /**
104
+ * @return array<string, array{string, Blob}> An associative array of name => [mode, blob]
105
+ */
106
+ public function getBlobEntries (): array
107
+ {
108
+ $ this ->initialize ();
109
+
110
+ return $ this ->entriesByType ['blob ' ];
111
+ }
112
+
75
113
public function getEntry ($ name )
76
114
{
77
115
$ this ->initialize ();
0 commit comments