7 function findLicense($dir, $file = null) {
9 return realpath("$dir/$file");
13 foreach (["{,UN}LICEN{S,C}{E,ING}", "COPY{,ING,RIGHT}"] as $name) {
14 $names[] = $this->mergeLicensePattern($name, strtolower($name));
17 foreach (["t{,e}xt", "rst", "asc{,i,ii}", "m{,ark}d{,own}", "htm{,l}"] as $ext) {
18 $exts[] = $this->mergeLicensePattern(strtoupper($ext), $ext);
21 $pattern = "{". implode(",", $names) ."}{,.{". implode(",", $exts) ."}}";
23 if (($glob = glob("$dir/$pattern", GLOB_BRACE
))) {
24 return current($glob);
28 private function mergeLicensePattern($upper, $lower) {
30 $length = strlen($upper);
31 for ($i = 0; $i < $length; ++
$i) {
32 if ($lower{$i} === $upper{$i}) {
33 $pattern .= $upper{$i};
35 $pattern .= "[" . $upper{$i} . $lower{$i} . "]";
41 public function readLicense($file) {
42 $text = file_get_contents($file);
43 switch (strtolower(pathinfo($file, PATHINFO_EXTENSION
))) {
46 $text = strip_tags($text);