Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helpers with a specific namespace can be loaded now. Fixes #1726 #1741

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 47 additions & 29 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,44 +600,62 @@ function helper($filenames)
$filename .= '_helper';
}

$paths = $loader->search('Helpers/' . $filename);
// If the file is namespaced, we'll just grab that
// file and not search for any others
if (strpos($filename, '\\') !== false)
{
$path = $loader->locateFile($filename, 'Helpers');

if (empty($path))
{
throw \CodeIgniter\Files\Exceptions\FileNotFoundException::forFileNotFound($filename);
}

$includes[] = $path;
}

if (! empty($paths))
// No namespaces, so search in all available locations
else
{
foreach ($paths as $path)
$paths = $loader->search('Helpers/' . $filename);

if (! empty($paths))
{
if (strpos($path, APPPATH) === 0)
{
// @codeCoverageIgnoreStart
$appHelper = $path;
// @codeCoverageIgnoreEnd
}
elseif (strpos($path, SYSTEMPATH) === 0)
foreach ($paths as $path)
{
$systemHelper = $path;
}
else
{
$localIncludes[] = $path;
if (strpos($path, APPPATH) === 0)
{
// @codeCoverageIgnoreStart
$appHelper = $path;
// @codeCoverageIgnoreEnd
}
elseif (strpos($path, SYSTEMPATH) === 0)
{
$systemHelper = $path;
}
else
{
$localIncludes[] = $path;
}
}
}
}

// App-level helpers should override all others
if (! empty($appHelper))
{
// @codeCoverageIgnoreStart
$includes[] = $appHelper;
// @codeCoverageIgnoreEnd
}
// App-level helpers should override all others
if (! empty($appHelper))
{
// @codeCoverageIgnoreStart
$includes[] = $appHelper;
// @codeCoverageIgnoreEnd
}

// All namespaced files get added in next
$includes = array_merge($includes, $localIncludes);
// All namespaced files get added in next
$includes = array_merge($includes, $localIncludes);

// And the system default one should be added in last.
if (! empty($systemHelper))
{
$includes[] = $systemHelper;
// And the system default one should be added in last.
if (! empty($systemHelper))
{
$includes[] = $systemHelper;
}
}
}

Expand Down