Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

push v1.0 forward to life

  • Loading branch information...
commit 5e30776f56170b341ee8d336d39b53b2d2ce40fc 1 parent 1a0648b
@Artazor Artazor authored
View
2  .gitignore
@@ -1,3 +1,5 @@
.idea/
*.oxy.php
+!oxygen.oxy.php
+
View
7 object/object.class.yml
@@ -1,14 +1,17 @@
extends: ~
+
+scope: false # NEVER SET IT FOR Oxygen_Object
+
views:
short_title:
info: "Small title of $this, used in submenu captions"
full_title:
- info: "Full title of $this. Suitable for usage in page title"
+ info: "Full title of $this. Suitable for usage in page title"
page_view:
- info: "Renders full HTML documnet representation suitable for displaying in browser"
+ info: "Renders full HTML documnet representation suitable for displaying in browser"
view:
info: "Generic view of $this, suitable for embedding into other views"
View
12 oxy.php
@@ -7,6 +7,18 @@
class <?=$class->oxyName?> <?if($class->extends):?>extends <?=$class->extends?><?endif?> {
+ # SCOPE:
+ <?if(is_array($class->scope)):?>
+
+ public static $__oxygenScope = array(
+<?foreach($class->scope as $key => $value):?>
+ <?=var_export($key)?> => <?=var_export($value)?>,
+<?endforeach?>
+ );
+ <?else:?>
+ public static $__oxygenScope = <?var_export($class->scope)?>;
+ <?endif?>
+
# BEGIN ASSETS:
<?foreach($class->assets as $asset):?>
<?=$class->views[$asset->name]->access?> function asset_<?=$asset->name?>_<?=$asset->type?>() {<?
View
16 oxygen.class.php
@@ -25,8 +25,9 @@ public function __construct($assertion, $file, $line) {
}
}
+ require "oxygen.oxy.php";
- class Oxygen {
+ class Oxygen extends Oxygen_ {
const OXYGEN_SUFFIX = '_';
@@ -120,7 +121,7 @@ private function compileItem($normalDir, $genPath, $className, $yaml, $path, $bo
}
# === VIEWS ====
- $yamlViews = isset($yaml['views'])
+ $yamlViews = isset($yaml['views'])
? $yaml['views']
: array()
;
@@ -181,10 +182,18 @@ private function compileItem($normalDir, $genPath, $className, $yaml, $path, $bo
}
}
+ # === SCOPE ===
+
+ $scope = isset($yaml['scope'])
+ ? $yaml['scope']
+ : false;
+ ;
+
$class = (object)array(
'both' => $both,
'name' => $className,
'extends' => $ancestor,
+ 'scope' => $scope,
'oxyName' => $className . self::OXYGEN_SUFFIX,
'views' => $views,
'assets' => $assets
@@ -272,11 +281,10 @@ public function __construct($privateCacheRoot, $compileRoot = false, $assetRoot
define('OXYGEN_JS_ROOT', $this->getWritableDir(OXYGEN_ASSET_ROOT, array('js')));
$scope = new Oxygen_Scope();
$scope->Oxygen = array($this,'itself');
- $scope->Object = 'Oxygen_Object';
- $scope->Exception = 'Exception';
$scope->o = $this;
$scope->startedAt = $startedAt;
$this->scope = $scope;
+ $this->scope->__set(self::$__oxygenScope);
}
public function compile() {
View
8 oxygen.class.yml
@@ -1,12 +1,18 @@
extends: ~
+scope:
+ Object: Oxygen_Object
+ Exception: Exception
+ Scope: Oxygen_Scope
+ Controller: Oxygen_Controller
+
views:
oxy:
access: public
args: { class: Object }
info: Renders template
- exception:
+ exception:
access: public
args: { ex: Exception }
info: Renders given exception
View
121 oxygen.oxy.php
@@ -0,0 +1,121 @@
+<?
+ # WARNING !!!
+
+ # This file is generated automatically by Oxygen,
+ # so any changes within it will be overwritten
+
+ class Oxygen_ {
+
+ # SCOPE:
+
+ public static $__oxygenScope = array(
+ 'Object' => 'Oxygen_Object',
+ 'Exception' => 'Exception',
+ 'Scope' => 'Oxygen_Scope',
+ 'Controller' => 'Oxygen_Controller',
+ );
+
+ # BEGIN ASSETS:
+ public function asset_exception_css() {}
+ public function asset_exception_less() {}
+ public function asset_exception_js() {}
+ public function asset_exception_trace_css() {}
+ public function asset_exception_trace_less() {}
+ public function asset_exception_trace_js() {}
+ public function asset_inspected_css() {}
+ public function asset_inspected_less() {}
+ public function asset_inspected_js() {}
+ public function asset_oxy_css() {}
+ public function asset_oxy_less() {}
+ public function asset_oxy_js() {}
+ # END ASSETS.
+
+ # BEGIN VIEWS:
+
+ /** GET: Renders given exception
+ @param Exception ex
+ */
+ public function get_exception($ex) {
+ ob_start(); try { $this->put_exception($ex); }
+ catch (Exception $_) {}
+ if(isset($_)) {ob_end_clean(); throw $_;}
+ return ob_get_clean();
+ }
+
+ /** PUT: Renders given exception
+ @param Exception ex
+ */
+ public function put_exception($ex) {
+ $result = include 'C:\webdev\www\toic2.lv\oxygen\exception.php';
+ $this->asset_exception_css();
+ $this->asset_exception_js();
+ $this->asset_exception_less();
+ return $result;
+ }
+
+ /** GET: Renders given exception trace
+ @param array trace
+ */
+ public function get_exception_trace($trace) {
+ ob_start(); try { $this->put_exception_trace($trace); }
+ catch (Exception $_) {}
+ if(isset($_)) {ob_end_clean(); throw $_;}
+ return ob_get_clean();
+ }
+
+ /** PUT: Renders given exception trace
+ @param array trace
+ */
+ public function put_exception_trace($trace) {
+ $result = include 'C:\webdev\www\toic2.lv\oxygen\exception_trace.php';
+ $this->asset_exception_trace_css();
+ $this->asset_exception_trace_js();
+ $this->asset_exception_trace_less();
+ return $result;
+ }
+
+ /** GET: inspected view
+ */
+ public function get_inspected() {
+ ob_start(); try { $this->put_inspected(); }
+ catch (Exception $_) {}
+ if(isset($_)) {ob_end_clean(); throw $_;}
+ return ob_get_clean();
+ }
+
+ /** PUT: inspected view
+ */
+ public function put_inspected() {
+ $result = include 'C:\webdev\www\toic2.lv\oxygen\inspected.php';
+ $this->asset_inspected_css();
+ $this->asset_inspected_js();
+ $this->asset_inspected_less();
+ return $result;
+ }
+
+ /** GET: Renders template
+ @param Object class
+ */
+ public function get_oxy($class) {
+ ob_start(); try { $this->put_oxy($class); }
+ catch (Exception $_) {}
+ if(isset($_)) {ob_end_clean(); throw $_;}
+ return ob_get_clean();
+ }
+
+ /** PUT: Renders template
+ @param Object class
+ */
+ public function put_oxy($class) {
+ $result = include 'C:\webdev\www\toic2.lv\oxygen\oxy.php';
+ $this->asset_oxy_css();
+ $this->asset_oxy_js();
+ $this->asset_oxy_less();
+ return $result;
+ }
+
+ # END VIEWS.
+ }
+
+
+?>
View
37 reflector/reflector.class.php
@@ -5,6 +5,9 @@ class Oxygen_Reflector {
public $factory = null;
private $setScope = 'setScopeNone';
private $setScopeName = 'scope';
+ private $reflected = null;
+ private $parent = null;
+ private $overrides = false;
private static $defaults = array(
'factory' => false,
@@ -15,6 +18,36 @@ class Oxygen_Reflector {
public function __construct($name) {
$this->name = $name;
$ref = $this->reflected = new ReflectionClass($name);
+
+ # === Handling scope overrides ===
+ $newScope = false;
+ // current scope
+ try {
+ $__currentScope = $ref->getProperty('__oxygenScope')->getValue();
+ } catch (ReflectionException $e) {
+ $__currentScope = false;
+ }
+ // parent scope
+ try {
+ $par = $ref->getParentClass();
+ if($par) $par = $par->getParentClass();
+ if ($par) {
+ $__parentScope = $par->getProperty('__oxygenScope')->getValue();
+ } else {
+ $__parentScope = false;
+ }
+ } catch (ReflectionException $e) {
+ $__parentScope = false;
+ }
+
+ if ($__parentScope || $__currentScope) {
+ if(!is_array($__parentScope)) $__parentScope = array();
+ if(!is_array($__currentScope)) $__currentScope = array();
+ $this->overrides = array_merge($__parentScope, $__currentScope);
+ } else {
+ $this->overrides = false;
+ }
+
try {
$info = $ref->getMethod('__oxygen_info');
if (!$info->isStatic()) $info = false;
@@ -72,6 +105,10 @@ private function setScopeThrow($obj, $scope) {
public function newInstance($args, $scope) {
$result = call_user_func_array($this->factory, $args);
+ if($this->overrides !== false) {
+ $scope = $scope->Scope();
+ $scope->__set($this->overrides);
+ }
$this->{$this->setScope}($result, $scope);
if(isset($this->info['complete'])) {
$result->{$this->info['complte']}($scope);
View
12 scope/scope.class.php
@@ -17,8 +17,16 @@ public function __get($name) {
}
}
- public function __set($name, $value) {
- if (isset($this->entries[$name])) {
+ public function __set($name, $value = true) {
+ if(is_array($name)) {
+ foreach($name as $key => $value) {
+ if(is_integer($key)){
+ $this->__set($value, true);
+ } else {
+ $this->__set($key, $value);
+ }
+ }
+ } else if (isset($this->entries[$name])) {
throw $this->Exception("Duplicate entry $name");
} else {
$this->entries[$name] = $value;
Please sign in to comment.
Something went wrong with that request. Please try again.