featureName = $featureName;
$this->type = $type;
$this->content = $content;
}
public function getType() {
return $this->type;
}
public function getContent() {
if (! $this->loaded && $this->type == 'FILE') {
if (Config::get('compress_javascript')) {
$featureCache = Config::get('feature_cache');
$featureCache = new $featureCache();
if (! ($content = $featureCache->get(md5($this->content)))) {
$content = JsMin::minify(JsLibrary::loadData($this->content, $this->type));
$featureCache->set(md5($this->content), $content);
$this->content = $content;
} else {
$this->content = $content;
}
} else {
$this->content = JsLibrary::loadData($this->content, $this->type);
}
$this->loaded = true;
}
return $this->content;
}
public function getFeatureName() {
return $this->featureName;
}
public function toString() {
if ($this->type == 'URL') {
return "";
} else {
return "\n\n";
}
}
static function create($type, $content, $name) {
return new JsLibrary($type, $content, $name);
}
static private function loadData($name, $type) {
// we don't really do 'resources', so limiting this to files only
if ($type == 'FILE') {
return JsLibrary::loadFile($name);
}
return null;
}
static private function loadFile($fileName) {
// this hack prevents loadFile from trying to load .jar resources
if (empty($fileName) || (strpos($fileName, 'res://') !== false)) {
return '';
}
if (Config::get('debug')) {
if (! File::exists($fileName)) {
throw new Exception("JsLibrary file missing: $fileName");
}
if (! is_file($fileName)) {
throw new Exception("JsLibrary file is not a file: $fileName");
}
if (! File::readable($fileName)) {
throw new Exception("JsLibrary file not readable: $fileName");
}
}
if (! ($content = @file_get_contents($fileName))) {
throw new Exception("JsLibrary error reading file: $fileName");
}
return $content;
}
}