diff --git a/mixeer/Helpers.php b/mixeer/Helpers.php deleted file mode 100644 index b141b9e..0000000 --- a/mixeer/Helpers.php +++ /dev/null @@ -1,37 +0,0 @@ -config->item('base_path') . ($path ? '/' . ltrim($path, '/') : $path); - } -} diff --git a/mixeer/addon.setup.php b/mixeer/addon.setup.php index 04ae21a..b2cbf92 100644 --- a/mixeer/addon.setup.php +++ b/mixeer/addon.setup.php @@ -17,6 +17,6 @@ 'docs_url' => 'https://github.com/benjivm/mixeer', 'name' => 'MixEEr', 'description' => 'Processes mix manifest files in ExpressionEngine for asset management.', - 'version' => '1.0.2', + 'version' => '1.0.3', 'namespace' => 'Benjivm\Mixeer', ]; diff --git a/mixeer/pi.mixeer.php b/mixeer/pi.mixeer.php index 3ed7257..05650dc 100644 --- a/mixeer/pi.mixeer.php +++ b/mixeer/pi.mixeer.php @@ -4,8 +4,6 @@ exit('No direct script access allowed'); } -use Benjivm\Mixeer\Helpers; - class Mixeer { public $return_data = ''; @@ -35,15 +33,15 @@ public function mix($path, $manifestDir = '') { static $manifests = []; - if (! Helpers::startsWith($path, '/')) { + if (! $this->startsWith($path, '/')) { $path = "/{$path}"; } - if ($manifestDir && ! Helpers::startsWith($manifestDir, '/')) { + if ($manifestDir && ! $this->startsWith($manifestDir, '/')) { $manifestDir = "/{$manifestDir}"; } - $manifestPath = Helpers::publicPath($manifestDir . '/mix-manifest.json'); + $manifestPath = $this->publicPath($manifestDir . '/mix-manifest.json'); if (! isset($manifests[$manifestPath])) { if (! file_exists($manifestPath)) { @@ -63,4 +61,35 @@ public function mix($path, $manifestDir = '') return $manifestDir . $manifest[$path]; } + + /** + * Determine if a given string starts with a given character. + * + * @param $haystack + * @param $needles + * + * @return bool + */ + private static function startsWith($haystack, $needles) + { + foreach ((array) $needles as $needle) { + if ($needle != '' && substr($haystack, 0, strlen($needle)) === (string) $needle) { + return true; + } + } + + return false; + } + + /** + * Generate the public path to the given file. + * + * @param string $path + * + * @return string + */ + private static function publicPath($path = '') + { + return ee()->config->item('base_path') . ($path ? '/' . ltrim($path, '/') : $path); + } }