make mime_type_plaindetect work in .phar files
[phorkie.git] / src / phorkie / Tool / MIME / Type / PlainDetect.php
1 <?php
2 namespace phorkie;
3
4 class Tool_MIME_Type_PlainDetect extends \MIME_Type_PlainDetect
5 {
6     /**
7      * Try to find the magic file copied by phing's build.xml into
8      * lib/data/.
9      *
10      * @return string path to the magic file
11      */
12     public static function getMagicFile()
13     {
14         $rootdir = __DIR__ . '/../../../../../';
15         if (file_exists($rootdir . '/lib/PEAR.php')) {
16             if (!\Phar::running()) {
17                 return $rootdir . '/lib/data/programming.magic';
18             } else {
19                 //magic file within a .phar does not work:
20                 // https://bugs.php.net/bug.php?id=67556
21                 //put it outside
22                 $target = '/tmp/phorkie-programming.magic';
23                 if (!file_exists($target)) {
24                     copy(
25                         $rootdir . '/lib/data/programming.magic',
26                         $target
27                     );
28                 }
29                 return $target;
30             }
31         }
32         return parent::getMagicFile();
33     }
34 }
35 ?>