Skip to content

Instantly share code, notes, and snippets.

@alex-ross
Last active October 13, 2015 15:48
Show Gist options
  • Save alex-ross/4219076 to your computer and use it in GitHub Desktop.
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.
<?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