Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Miller committed Feb 24, 2020
1 parent 40f488c commit 8cfcb2f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 43 deletions.
37 changes: 0 additions & 37 deletions mixeer/Helpers.php

This file was deleted.

2 changes: 1 addition & 1 deletion mixeer/addon.setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
39 changes: 34 additions & 5 deletions mixeer/pi.mixeer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
exit('No direct script access allowed');
}

use Benjivm\Mixeer\Helpers;

class Mixeer
{
public $return_data = '';
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
}

0 comments on commit 8cfcb2f

Please sign in to comment.