diff --git a/class/class.class.php b/class/class.class.php index 8118301..a8c1769 100644 --- a/class/class.class.php +++ b/class/class.class.php @@ -3,6 +3,7 @@ define('OXYGEN_METACLASS_MODIFIED', filemtime(__FILE__)); class Oxygen_Class { + private $ref = null; private $name = ''; private $less = null; @@ -24,35 +25,53 @@ public function __toString() { } public function __getPublicInstanceMethod($name) { - $m = $this->ref->getMethod($name); + $m = $this->ref->getMethod($name); if ($m->isStatic()) throw new ReflectionException("$name is static"); if (!$m->isPublic()) throw new ReflectionException("$name is not public"); return $m; } - public function compile($source, $destination, $css, $name, $type, $time) { - $include = dirname(__FILE__) . DIRECTORY_SEPARATOR . $type . '.php'; + public function compile($asset) { + + $type = $asset['type']; + $name = $asset['name']; + $ext = $asset['ext']; + + $include = dirname(__FILE__) + . DIRECTORY_SEPARATOR + . $type + . '.php' + ; + $destination = OXYGEN_ASSET_ROOT + . DIRECTORY_SEPARATOR + . $type + . $this->__oxygen_path + . DIRECTORY_SEPARATOR + . $name + . $ext + ; + $source = OXYGEN_ROOT + . DIRECTORY_SEPARATOR + . $asset['path'] + . DIRECTORY_SEPARATOR + . $name + . $ext + ; try { $d = filemtime($destination); $s = filemtime($source); $i = filemtime($include); + $t = $this->__lastMetaModified; $m = OXYGEN_METACLASS_MODIFIED; - if ($d >= max($s, $i, $time, $m)) return $d; + if ($d >= max($s, $i, $t, $m)) return array($d, $destination); } catch (Oxygen_FileNotFoundException $e) { Oxygen::getWritableDir(dirname($destination)); } - $parent = $this->__getParentClass(); - if ($parent !== null) { - try { - $parent = 'css-'. $parent->{'__defines_'.$type.'_'.$name} . '-' . $name; - } catch (ReflectionException $e) { - $parent = $css; - } - } else { - $parent = $css; - } + $css = 'css-' . $this . '-' . $name; try { - unset($d); + unset($m); + unset($t); + unset($d); unset($s); unset($i); ob_start(); @@ -63,7 +82,7 @@ public function compile($source, $destination, $css, $name, $type, $time) { $result = '/* ' . $e->getMessage() . ' */'; } file_put_contents($destination, $result); - return time(); + return array(time(), $destination); } } diff --git a/oxy.php b/oxy.php index 30f32bc..e32c68c 100644 --- a/oxy.php +++ b/oxy.php @@ -7,6 +7,9 @@ class oxyName?> extends):?>extends extends?> { + public static $__oxygen_path = 'path?>'; + public static $__lastMetaModified = ; + private static $static = null; public static $name = 'name?>'; public static function __getClass() { @@ -21,7 +24,7 @@ public static function __getParentClass() { return extends?>::__getClass(); return null; - + } # SCOPE: @@ -42,20 +45,20 @@ public static function __getParentClass() { assets as $asset):?> - access?> function asset_name?>_type?>($path, $css, $class, $last) {override):?>} + access?> function method?>($class) {file === false):?>} if(!isset($this->__assets)) { $this->__assets = &$this->scope->assets; } - $name = $css . '-name?>'; + $name = $class . '-name?>'; if (!isset($this->__assets['type?>'][$name])) { $this->__assets['type?>'][$name] = array( - 'source' => OXYGEN_ROOT . 'relPath)?>', - 'destination' => OXYGEN_ASSET_ROOT . '/type?>' . $path . '/baseName?>', - 'class' => $class, - 'name' => 'name?>', - 'last' => $last + 'type' => 'type?>', + 'ext' => 'ext?>', + 'name' => 'name?>', + 'path' => self::$__oxygen_path, + 'class' => $class ); } } @@ -93,21 +96,12 @@ public static function __getParentClass() { access?> function put_() { try { Oxygen::push($this,''); - $result = include OXYGEN_ROOT . 'relPath?>'; + $result = include OXYGEN_ROOT . 'path?>/.php'; Oxygen::closeAll(); -assets)):?> $class = $this->__getClass(); - $last = $this->__lastMetaModified(); - $css = 'css-' . $class; assets as $asset):?> - $this->asset_name?>_type?>( - 'path?>', - $css, - $class, - $last - ); - - + $this->method?>($class); + } catch (Exception $e) { Oxygen::pop(); throw $e; @@ -119,9 +113,6 @@ public static function __getParentClass() { # END VIEWS. - public function __lastMetaModified() { - return ; - } } both):?>class name?> extends oxyName?> { diff --git a/oxygen.class.php b/oxygen.class.php index abe55dc..8e6392d 100644 --- a/oxygen.class.php +++ b/oxygen.class.php @@ -127,21 +127,21 @@ public static function requireFile($relative) { return require_once self::pathFor($relative); } - public function compileAsset($type, $source, $filename) { + public function compileAsset($type, $source, $fileName) { switch ($type) { case 'css': case 'less': require_once self::pathFor('oxygen/lib/lessphp/lessc.inc.php'); $less = new lessc(); try { - file_put_contents($filename, $less->parse($source)); + file_put_contents($fileName, $less->parse($source)); } catch (Exception $e) { - file_put_contents($filename, '/* ' . $e->getMessage() . ' */'); + file_put_contents($fileName, '/* ' . $e->getMessage() . ' */'); } break; case 'js': default: - file_put_contents($filename, $source); + file_put_contents($fileName, $source); break; } @@ -150,21 +150,14 @@ public function compileAsset($type, $source, $filename) { public function compileAssets() { $result = array(); foreach ($this->scope->assets as $type => $assets) { - $names = array(); + $fileNames = array(); $last = 1; - foreach($assets as $css => $asset) { - $time = $asset['class']->compile( - $asset['source'], - $asset['destination'], - $css, - $asset['name'], - $type, - $asset['last'] - ); + foreach($assets as $asset) { + list($time, $fileName) = $asset['class']->compile($asset); $last = max($last, $time); - $names[] = $asset['destination']; + $fileNames[] = $fileName; } - $bundle = md5(implode(':',$names)); + $bundle = md5(implode(':',$fileNames)); $bundle_path = OXYGEN_ASSET_ROOT . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $bundle @@ -172,10 +165,11 @@ public function compileAssets() { $m = self::modificationTime($bundle_path); if ($last > $m) { ob_start(); - foreach($names as $source) { - $s = substr($source,strlen(OXYGEN_ASSET_ROOT)+1); + foreach($fileNames as $fileName) { + $s = substr($fileName, strlen(OXYGEN_ASSET_ROOT)+1); echo '/* ' . $s . " */\n"; - readfile($source); + readfile($fileName); + echo "\n"; } $this->compileAsset($type, ob_get_clean(), $bundle_path); } @@ -266,6 +260,7 @@ private function compileItem($normalDir, $genPath, $className, $yaml, $path, $bo $pattern = '/(?:' . implode('|', array_map('preg_quote', array_keys($all))) . ')$/'; foreach ($files as $file) { $name = basename($file); + $file = '/' . $path . '/' . $file; if (preg_match($pattern, $name, $m)) { $ext = $m[0]; $name = substr($name, 0, -strlen($ext)); @@ -291,6 +286,7 @@ private function compileItem($normalDir, $genPath, $className, $yaml, $path, $bo ? $yaml['views'] : array() ; + $views = array(); foreach ($all['.php'] as $name => $file) { $defaultAccess = 'private'; @@ -309,9 +305,6 @@ private function compileItem($normalDir, $genPath, $className, $yaml, $path, $bo $yamlView = array(); } $views[$name] = (object)array( - 'relPath' => str_replace(DIRECTORY_SEPARATOR,'/',$path . DIRECTORY_SEPARATOR . basename($file)), - 'absPath' => str_replace(DIRECTORY_SEPARATOR,'/',$file), - 'path' => str_replace(DIRECTORY_SEPARATOR,'/',$path), 'access' => isset($yamlView['access']) ? $yamlView['access'] : $defaultAccess, 'args' => isset($yamlView['args']) ? $yamlView['args'] : array(), 'info' => isset($yamlView['info']) ? $yamlView['info'] : ($name . ' view'), @@ -330,39 +323,34 @@ private function compileItem($normalDir, $genPath, $className, $yaml, $path, $bo foreach ($views as $name => &$view) { foreach ($assetExt as $type => $ext) { $method = 'asset_' . $name . '_' . $type; - if (isset($all[$ext][$name])) { - $file = $all[$ext][$name]; - $assets[] = $view->assets[$method] = (object)array( - 'override' => true, - 'name' => $name, - 'relPath' => str_replace(DIRECTORY_SEPARATOR,'/',$path . DIRECTORY_SEPARATOR . basename($file)), - 'absPath' => $file, - 'baseName' => basename($file), - 'type' => $type, - 'genPath' => OXYGEN_ASSET_ROOT . DIRECTORY_SEPARATOR - . $type . $path . DIRECTORY_SEPARATOR - . basename($file), - 'access' => $view->access - ); + $file = isset($all[$ext][$name]) + ? $all[$ext][$name] + : false + ; + $asset = (object)array( + 'name' => $name, + 'file' => $file, + 'ext' => $ext, + 'type' => $type, + 'method' => $method, + 'access' => $view->access + ); + if ($file !== false) { + // asset is defined in current class + // display it both in defs and usages + $assets[] = $view->assets[$method] = $asset; } else if ($ancestor_access[$name] === 'private') { + // asset is not inherited and file is not present; if ($view->access !== 'private') { - $assets[] = $view->assets[$method] = (object)array( - 'override' => false, - 'name' => $name, - 'type' => $type, - 'method' => $method, - 'access' => $view->access - ); + //asset should be introduced since view is inheritable + //we should create an empty entries in defs + //and also generate usage; + $assets[] = $view->assets[$method] = $asset; } } else { - $view->assets[$method] = (object)array( - 'override' => false, - 'name' => $name, - 'type' => $type, - 'method' => $method, - 'baseName' => $name . $ext, - 'access' => $view->access - ); + //asset is simply inherited, so we'll + //generate only it's usage + $view->assets[$method] = $asset; } } } @@ -381,18 +369,12 @@ private function compileItem($normalDir, $genPath, $className, $yaml, $path, $bo 'scope' => $scope, 'oxyName' => $className . self::OXYGEN_SUFFIX, 'views' => $views, - 'assets' => $assets + 'assets' => $assets, + 'path' => $path ); try { - $generated = $this->get_oxy($class); - $f = fopen($genPath,'w+'); - if (flock($f,LOCK_EX)) { - ftruncate($f, 0); - fwrite($f, $generated); - flock($f, LOCK_UN); - } - fclose($f); + file_put_contents($genPath, $this->get_oxy($class)); } catch (Exception $e) { print $e; } @@ -428,7 +410,7 @@ public function loadClass($class) { $compilePath, $base ? substr($class,0,-strlen(self::OXYGEN_SUFFIX)) : $class, $yaml, - $path, + str_replace(DIRECTORY_SEPARATOR, '/', $path), !$base ); } diff --git a/oxygen.oxy.php b/oxygen.oxy.php index 5092a3c..533b7c9 100644 --- a/oxygen.oxy.php +++ b/oxygen.oxy.php @@ -6,6 +6,9 @@ class Oxygen_ { + public static $__oxygen_path = '/oxygen'; + public static $__lastMetaModified = 1339287938; + private static $static = null; public static $name = 'Oxygen'; public static function __getClass() { @@ -17,7 +20,6 @@ public static function __getClass() { public static function __getParentClass() { return null; - } # SCOPE: @@ -34,9 +36,9 @@ public static function __getParentClass() { public static $__defines_less_inspected = 'Oxygen'; public static $__defines_js_inspected = 'Oxygen'; - public function asset_inspected_css($path, $css, $class, $last) {} - public function asset_inspected_less($path, $css, $class, $last) {} - public function asset_inspected_js($path, $css, $class, $last) {} + public function asset_inspected_css($class) {} + public function asset_inspected_less($class) {} + public function asset_inspected_js($class) {} # END ASSETS. # BEGIN VIEWS: @@ -59,7 +61,7 @@ private function put_exception($ex) { Oxygen::push($this,'exception'); $result = include OXYGEN_ROOT . '/oxygen/exception.php'; Oxygen::closeAll(); - + $class = $this->__getClass(); } catch (Exception $e) { Oxygen::pop(); throw $e; @@ -86,7 +88,7 @@ private function put_exception_trace($trace) { Oxygen::push($this,'exception_trace'); $result = include OXYGEN_ROOT . '/oxygen/exception_trace.php'; Oxygen::closeAll(); - + $class = $this->__getClass(); } catch (Exception $e) { Oxygen::pop(); throw $e; @@ -114,28 +116,9 @@ public function put_inspected($value) { $result = include OXYGEN_ROOT . '/oxygen/inspected.php'; Oxygen::closeAll(); $class = $this->__getClass(); - $last = $this->__lastMetaModified(); - $css = 'css-' . $class; - $this->asset_inspected_css( - '/oxygen', - $css, - $class, - $last - ); - $this->asset_inspected_less( - '/oxygen', - $css, - $class, - $last - ); - $this->asset_inspected_js( - '/oxygen', - $css, - $class, - $last - ); - - + $this->asset_inspected_css($class); + $this->asset_inspected_less($class); + $this->asset_inspected_js($class); } catch (Exception $e) { Oxygen::pop(); throw $e; @@ -162,7 +145,7 @@ private function put_oxy($class) { Oxygen::push($this,'oxy'); $result = include OXYGEN_ROOT . '/oxygen/oxy.php'; Oxygen::closeAll(); - + $class = $this->__getClass(); } catch (Exception $e) { Oxygen::pop(); throw $e; @@ -173,9 +156,6 @@ private function put_oxy($class) { # END VIEWS. - public function __lastMetaModified() { - return 1339276099; - } }