From: Antonio Ospite <ao2@ao2.it>
Date: Sat, 10 Dec 2016 18:34:57 +0000 (+0100)
Subject: tweeper: allow running tweeper from vendor/bin also when it's not a symlink
X-Git-Tag: v1.0.0~5
X-Git-Url: https://git.ao2.it/tweeper.git/commitdiff_plain/acf3e387ca460a9c5d5ecaaf14079553cce63971?hp=901618842d5be25fa21cee16a1e123568ca117dc

tweeper: allow running tweeper from vendor/bin also when it's not a symlink
---

diff --git a/tweeper b/tweeper
index 6256e20..d4b04e3 100755
--- a/tweeper
+++ b/tweeper
@@ -6,4 +6,17 @@
  * CLI file to run tweeper.
  */
 
-require dirname(__FILE__) . '/tweeper.php';
+if (preg_match('/' . preg_quote('/vendor/bin', '/') . '$/', __DIR__)) {
+  /*
+   * This covers the case of tweeper running from a "vendor/bin" directory in
+   * a composer setup, but with the tweeper executable _not_ being a symlink.
+   *
+   * This can happen when the filesystem does not support symlinks.
+   */
+  $package_name = 'ao2/tweeper';
+  require __DIR__ . '/../' . $package_name . '/tweeper.php';
+}
+else {
+  /* For the other cases look at the autoload.php required by tweeper.php */
+  require __DIR__ . '/tweeper.php';
+}