1 | <?php |
||
51 | class Adapter implements AdapterInterface, StreamFactory, ChecksumCalculator |
||
52 | { |
||
53 | /** |
||
54 | * The repository |
||
55 | * |
||
56 | * @var RepositoryInterface |
||
57 | */ |
||
58 | protected $repository; |
||
59 | |||
60 | /** |
||
61 | * Creates a new VCS adapter to be used with a Gaufrette filesystem |
||
62 | * |
||
63 | * @param RepositoryInterface $repository |
||
64 | */ |
||
65 | 28 | public function __construct(RepositoryInterface $repository) |
|
69 | |||
70 | /** |
||
71 | * Returns the repository |
||
72 | * |
||
73 | * @return RepositoryInterface |
||
74 | */ |
||
75 | 14 | public function getRepository() |
|
79 | |||
80 | /** |
||
81 | * {@inheritDoc} |
||
82 | */ |
||
83 | 2 | public function read($key) |
|
87 | |||
88 | /** |
||
89 | * {@inheritDoc} |
||
90 | */ |
||
91 | 2 | public function write($key, $content) |
|
92 | { |
||
93 | 2 | $this->repository->writeFile($key, $content); |
|
94 | 2 | return true; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * {@inheritDoc} |
||
99 | */ |
||
100 | 10 | public function rename($sourceKey, $targetKey) |
|
101 | { |
||
102 | 10 | $this->repository->renameFile($sourceKey, $targetKey); |
|
103 | 10 | return true; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * {@inheritDoc} |
||
108 | */ |
||
109 | 2 | public function exists($key) |
|
113 | |||
114 | /** |
||
115 | * {@inheritDoc} |
||
116 | */ |
||
117 | 2 | public function keys() |
|
118 | { |
||
119 | try { |
||
120 | 2 | $iterator = new \RecursiveIteratorIterator( |
|
121 | 2 | new \RecursiveDirectoryIterator($this->repository->getRepositoryPath(), |
|
122 | \FilesystemIterator::SKIP_DOTS |
||
123 | 2 | | \FilesystemIterator::UNIX_PATHS |
|
124 | ) |
||
125 | ); |
||
126 | } catch (\Exception $e) { |
||
127 | $iterator = new \EmptyIterator; |
||
128 | } |
||
129 | |||
130 | 2 | $keys = array(); |
|
131 | 2 | foreach ($iterator as $file) { |
|
132 | 2 | $path = $this->repository->resolveLocalPath($file); |
|
133 | 2 | if (preg_match('~\.(?:svn|git)~i', $path)) { |
|
134 | 2 | continue; |
|
135 | } |
||
136 | 2 | $keys[] = $key = $path; |
|
137 | 2 | if ('.' !== dirname($key)) { |
|
138 | 2 | $keys[] = dirname($key); |
|
139 | } |
||
140 | } |
||
141 | 2 | $keys = array_unique($keys); |
|
142 | 2 | sort($keys); |
|
143 | |||
144 | 2 | return $keys; |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * {@inheritDoc} |
||
149 | */ |
||
150 | 2 | public function mtime($key) |
|
154 | |||
155 | /** |
||
156 | * {@inheritDoc} |
||
157 | */ |
||
158 | 2 | public function delete($key) |
|
159 | { |
||
160 | 2 | $this->repository->removeFile($key); |
|
161 | 2 | return true; |
|
162 | } |
||
163 | |||
164 | /** |
||
165 | * {@inheritDoc} |
||
166 | */ |
||
167 | 2 | public function isDirectory($key) |
|
171 | |||
172 | /** |
||
173 | * {@inheritDoc} |
||
174 | */ |
||
175 | 2 | public function createStream($key) |
|
179 | |||
180 | /** |
||
181 | * {@inheritDoc} |
||
182 | */ |
||
183 | 2 | public function checksum($key) |
|
187 | } |
||
188 |