Skip to content

Commit

Permalink
push v1.0 forward to life
Browse files Browse the repository at this point in the history
  • Loading branch information
Artazor committed May 27, 2012
1 parent 1a0648b commit 5e30776
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,5 @@
.idea/
*.oxy.php
!oxygen.oxy.php


7 changes: 5 additions & 2 deletions 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"
Expand Down
12 changes: 12 additions & 0 deletions oxy.php
Expand Up @@ -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?>() {<?
Expand Down
16 changes: 12 additions & 4 deletions oxygen.class.php
Expand Up @@ -25,8 +25,9 @@ public function __construct($assertion, $file, $line) {
}
}

require "oxygen.oxy.php";

class Oxygen {
class Oxygen extends Oxygen_ {

const OXYGEN_SUFFIX = '_';

Expand Down Expand Up @@ -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()
;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 7 additions & 1 deletion 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
Expand Down
121 changes: 121 additions & 0 deletions 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.
}


?>
37 changes: 37 additions & 0 deletions reflector/reflector.class.php
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions scope/scope.class.php
Expand Up @@ -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;
Expand Down

0 comments on commit 5e30776

Please sign in to comment.