| Conditions | 5 |
| Paths | 6 |
| Total Lines | 17 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 26 | public static function copyToClipboard(string $string): bool |
||
| 27 | { |
||
| 28 | if (PHP_OS_FAMILY === "Windows") { |
||
| 29 | // works on windows 7 + |
||
| 30 | $clip = popen("clip", "wb"); |
||
| 31 | } elseif (PHP_OS_FAMILY === "Linux") { |
||
| 32 | return false; |
||
| 33 | // tested, works on ArchLinux |
||
| 34 | // $clip = popen('xclip -selection clipboard', 'wb'); |
||
| 35 | } elseif (PHP_OS_FAMILY === "Darwin") { |
||
| 36 | // untested! |
||
| 37 | $clip = popen('pbcopy', 'wb'); |
||
| 38 | } else { |
||
| 39 | throw new \Exception("running on unsupported OS: " . PHP_OS_FAMILY . " - only Windows, Linux, and MacOS supported."); |
||
| 40 | } |
||
| 41 | $written = fwrite($clip, $string); |
||
| 42 | return (pclose($clip) === 0 && strlen($string) === $written); |
||
| 43 | } |
||
| 54 |