Last active
October 13, 2015 15:48
-
-
Save alex-ross/4219076 to your computer and use it in GitHub Desktop.
Thin assets helper class for php. Made it just for fun but may come useful for realy small projects.
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 | |
/** | |
* @author Alexander Ross <[email protected]> | |
* @license MIT | |
*/ | |
class AssetsHelper | |
{ | |
private $js_array = []; | |
private $css_array = []; | |
// Takes string or array of filenames | |
function add($files) | |
{ | |
if (!is_array($files)) $files = [$files]; | |
foreach ($files as $file) { | |
if (substr($file, -strlen(".js")) == ".js") { | |
array_push($this->js_array, $file); | |
} | |
elseif (substr($file, -strlen(".css")) == ".css") { | |
array_push($this->css_array, $file); | |
} | |
} | |
} | |
function print_js() { | |
$before = "<script src=\""; | |
$after = "\" type=\"text/javascript\"></script>"; | |
return $before.implode($after.$before, $this->js_array).$after; | |
} | |
function print_css() { | |
$before = "<link rel=\"stylesheet\" type=\"text/css\" href=\""; | |
$after = "\" />"; | |
return $before.implode($after.$before, $this->css_array).$after; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment