开发者

Managing project agnostic code libraries without creating dependencies

I'm curious to know how fellow developers manage project agnostic code/libraries?

For example, given these two functions:

function array_exclude_keys(Array $array, Array $keys){
    foreach($keys as $key){
        unset($array[$key]);
    }
    return $array;
}

function array_order_to_assoc(Array $array){
    do{
        $return[current($array)] = next($array);
    }while(next($array));
    return !empty($return) ? $return : null;
}

These have a pretty general application. In a project I'm currently working on, array_exclude functionality is needed in at lea开发者_开发百科st two places, and array_order_to_assoc in at least one. I can even think of other projects which would benefit semantically from these.

Now, instead of writing them into methods for the necessary classes (non-DRY), I could simply amend them to a library, and include that library in the project. However, now the classes requiring these functions are completely dependent. Without such dependency, my classes in this project are quite literally "copy, paste, include, and instantiate", which is how I'd like to keep them.

I'm curious to know how others manage such situations.


If I'm understanding your question correctly, it sounds like you should be looking into php's spl_autoload functionality.

Here is a tutorial: http://www.phpro.org/tutorials/SPL-Autoload.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜