Created
May 11, 2011 06:49
-
-
Save robotamer/966019 to your computer and use it in GitHub Desktop.
Add a directory to the php include path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Description Add a directory to the php include path | |
* | |
* @package TaMeR | |
* @category File | |
* @type Function | |
* @author Dennis T Kaplan | |
* @copyright (C) 2009-2011 Dennis T Kaplan | |
* @license GPL {@link http://www.gnu.org/licenses/gpl.html} | |
* @todo | |
* | |
* @param dir: The directory to add to the path | |
* @param at_end: If true, place this directory at the end of | |
* the include path. Otherwise, place it at the beginning. | |
*/ | |
function addInclude($dir, $at_end = false) | |
{ | |
$exist = file_exists($dir); | |
if ( ! $exist || ($exist && filetype($dir) != 'dir')) | |
{ | |
trigger_error("Include path '{$dir}' does not exist", E_USER_WARNING); | |
echo '<pre>'; print_r(debug_backtrace()); | |
exit; | |
} | |
$dir = rtrim($dir, "/"); | |
$paths = ltrim(get_include_path(), ".".PATH_SEPARATOR); | |
$paths = explode(PATH_SEPARATOR, $paths); | |
$ds = '.'.PATH_SEPARATOR; | |
if (strlen($paths[0]) && array_search($dir, $paths) === false) { | |
$at_end ? array_push($paths, $dir) : array_unshift($paths, $dir); | |
$paths = implode(PATH_SEPARATOR, $paths); | |
set_include_path($ds.$paths); | |
} else { | |
set_include_path($ds.$dir); | |
} | |
} | |
/* #Test it | |
echo get_include_path(); | |
echo '<br />'; | |
addInclude('/var/www/library/'); | |
echo get_include_path(); | |
echo '<br />'; | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment