aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2014-07-04 07:39:32 +0200
committerChristian Weiske <cweiske@cweiske.de>2014-07-04 07:39:32 +0200
commit8d4d90d445cc0b0032e0f76ab98cac5a5a29df66 (patch)
tree1bd051f8e9f7fde02f6731fe05c55a0553d830c2 /src
parent43ef6e8dfd4345262f7b974506261e0827bfecae (diff)
downloadphorkie-8d4d90d445cc0b0032e0f76ab98cac5a5a29df66.tar.gz
phorkie-8d4d90d445cc0b0032e0f76ab98cac5a5a29df66.zip
make mime_type_plaindetect work in .phar files
Diffstat (limited to 'src')
-rw-r--r--src/phorkie/Repository/Post.php2
-rw-r--r--src/phorkie/Tool/MIME/Type/PlainDetect.php35
2 files changed, 36 insertions, 1 deletions
diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php
index c9f6a53..fbfea4b 100644
--- a/src/phorkie/Repository/Post.php
+++ b/src/phorkie/Repository/Post.php
@@ -232,7 +232,7 @@ class Repository_Post
{
$tmp = tempnam(sys_get_temp_dir(), 'phorkie-autodetect-');
file_put_contents($tmp, $content);
- $type = \MIME_Type_PlainDetect::autoDetect($tmp);
+ $type = Tool_MIME_Type_PlainDetect::autoDetect($tmp);
unlink($tmp);
return $this->findExtForType($type);
diff --git a/src/phorkie/Tool/MIME/Type/PlainDetect.php b/src/phorkie/Tool/MIME/Type/PlainDetect.php
new file mode 100644
index 0000000..235046e
--- /dev/null
+++ b/src/phorkie/Tool/MIME/Type/PlainDetect.php
@@ -0,0 +1,35 @@
+<?php
+namespace phorkie;
+
+class Tool_MIME_Type_PlainDetect extends \MIME_Type_PlainDetect
+{
+ /**
+ * Try to find the magic file copied by phing's build.xml into
+ * lib/data/.
+ *
+ * @return string path to the magic file
+ */
+ public static function getMagicFile()
+ {
+ $rootdir = __DIR__ . '/../../../../../';
+ if (file_exists($rootdir . '/lib/PEAR.php')) {
+ if (!\Phar::running()) {
+ return $rootdir . '/lib/data/programming.magic';
+ } else {
+ //magic file within a .phar does not work:
+ // https://bugs.php.net/bug.php?id=67556
+ //put it outside
+ $target = '/tmp/phorkie-programming.magic';
+ if (!file_exists($target)) {
+ copy(
+ $rootdir . '/lib/data/programming.magic',
+ $target
+ );
+ }
+ return $target;
+ }
+ }
+ return parent::getMagicFile();
+ }
+}
+?>