--- /dev/null
+<?php
+
+class Styles extends Singleton {
+ protected static $instance = false;
+ protected $code = array();
+ protected $files = array();
+
+ public function add($code)
+ {
+ $this->code[] = $code;
+ }
+
+ public function file($path)
+ {
+ $app = Application::get();
+
+ $info = pathinfo($path);
+
+ $minfile = sprintf('%s%s/%s.min.%s', $app->getBaseDir(), $info['dirname'], $info['filename'], $info['extension']);
+ if (file_exists($minfile)) {
+ $origpath = $app->getBaseDir().$path;
+ if (filemtime($minfile) > filemtime($origpath))
+ $path = sprintf('%s/%s.min.%s', $info['dirname'], $info['filename'], $info['extension']);
+ }
+
+ $this->files[$path] = true;
+ }
+
+ public function toString()
+ {
+ $app = Application::get();
+
+ $ret = '';
+ foreach (array_keys($this->files) as $file)
+ $ret .= sprintf('<link href="%s%s" rel="stylesheet" type="text/css">'."\n", $app->getBaseURL(), $file);
+
+ if (count($this->code)) {
+ $ret .= '<style type="text/css">'."\n";
+ $ret .= implode("\n", $this->code);
+ $ret .= "</style>\n";
+ }
+
+ return $ret;
+ }
+
+}