Last active
September 6, 2017 07:52
-
-
Save lastguest/d55e8e182940632fc8be to your computer and use it in GitHub Desktop.
[Include a gist file with local caching] #PHP #gist
This file contains hidden or 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 | |
/** | |
* Include a gist file with local caching | |
* | |
* | |
* @example : | |
* // Include lastguest/profiler gist | |
* // https://gist.github.com/lastguest/4344954 | |
* | |
* include_gist('lastguest','4344954'); | |
* | |
* | |
* @author [email protected] | |
* @param string $user The user gist repository (GitHub username) | |
* @param string $name The ID of the gist to load | |
* @param string $tmpdir (optional) If passed this will be the cache directory | |
* | |
*/ | |
function include_gist($user,$name,$tmpdir=null){ | |
$tmp = $tmpdir ?: sys_get_temp_dir().'/.gists'; | |
if (false == is_dir($tmp)) mkdir($tmp); | |
if (false == is_file($file = "$tmp/$user-$name.php")){ | |
file_put_contents($file,file_get_contents("https://gist.githubusercontent.com/$user/$name/raw")); | |
} | |
return include($file); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment