Mercurial > hg > cmmr2012-drupal-site
comparison vendor/psy/psysh/src/Command/EditCommand.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
93 ); | 93 ); |
94 | 94 |
95 $shouldRemoveFile = false; | 95 $shouldRemoveFile = false; |
96 | 96 |
97 if ($filePath === null) { | 97 if ($filePath === null) { |
98 $filePath = tempnam($this->runtimeDir, 'psysh-edit-command'); | 98 $filePath = \tempnam($this->runtimeDir, 'psysh-edit-command'); |
99 $shouldRemoveFile = true; | 99 $shouldRemoveFile = true; |
100 } | 100 } |
101 | 101 |
102 $editedContent = $this->editFile($filePath, $shouldRemoveFile); | 102 $editedContent = $this->editFile($filePath, $shouldRemoveFile); |
103 | 103 |
136 */ | 136 */ |
137 private function extractFilePath($fileArgument) | 137 private function extractFilePath($fileArgument) |
138 { | 138 { |
139 // If the file argument was a variable, get it from the context | 139 // If the file argument was a variable, get it from the context |
140 if ($fileArgument !== null && | 140 if ($fileArgument !== null && |
141 strlen($fileArgument) > 0 && | 141 \strlen($fileArgument) > 0 && |
142 $fileArgument[0] === '$') { | 142 $fileArgument[0] === '$') { |
143 $fileArgument = $this->context->get(preg_replace('/^\$/', '', $fileArgument)); | 143 $fileArgument = $this->context->get(\preg_replace('/^\$/', '', $fileArgument)); |
144 } | 144 } |
145 | 145 |
146 return $fileArgument; | 146 return $fileArgument; |
147 } | 147 } |
148 | 148 |
154 * | 154 * |
155 * @throws \UnexpectedValueException if file_get_contents on $filePath returns false instead of a string | 155 * @throws \UnexpectedValueException if file_get_contents on $filePath returns false instead of a string |
156 */ | 156 */ |
157 private function editFile($filePath, $shouldRemoveFile) | 157 private function editFile($filePath, $shouldRemoveFile) |
158 { | 158 { |
159 $escapedFilePath = escapeshellarg($filePath); | 159 $escapedFilePath = \escapeshellarg($filePath); |
160 | 160 |
161 $pipes = []; | 161 $pipes = []; |
162 $proc = proc_open((getenv('EDITOR') ?: 'nano') . " {$escapedFilePath}", [STDIN, STDOUT, STDERR], $pipes); | 162 $proc = \proc_open((\getenv('EDITOR') ?: 'nano') . " {$escapedFilePath}", [STDIN, STDOUT, STDERR], $pipes); |
163 proc_close($proc); | 163 \proc_close($proc); |
164 | 164 |
165 $editedContent = @file_get_contents($filePath); | 165 $editedContent = @\file_get_contents($filePath); |
166 | 166 |
167 if ($shouldRemoveFile) { | 167 if ($shouldRemoveFile) { |
168 @unlink($filePath); | 168 @\unlink($filePath); |
169 } | 169 } |
170 | 170 |
171 if ($editedContent === false) { | 171 if ($editedContent === false) { |
172 throw new \UnexpectedValueException("Reading {$filePath} returned false"); | 172 throw new \UnexpectedValueException("Reading {$filePath} returned false"); |
173 } | 173 } |