Skip to content

Instantly share code, notes, and snippets.

@larscwallin
Created November 30, 2011 15:39
Show Gist options
  • Save larscwallin/1409520 to your computer and use it in GitHub Desktop.
Save larscwallin/1409520 to your computer and use it in GitHub Desktop.
SIMPLX Reflect
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" />
<xsl:output method="text" />
<xsl:output indent="yes" />
<xsl:output media-type="text/plain" />
<xsl:param name="directory"/>
<xsl:param name="label-composite">Composites</xsl:param>
<xsl:param name="label-aggregate">Aggregates</xsl:param>
<xsl:param name="xpdo-model"></xsl:param>
<xsl:param name="include-objects">modSnippet modChunk</xsl:param>
<xsl:param name="include-dependencies">1</xsl:param>
<xsl:param name="include-local-only">0</xsl:param>
<xsl:param name="ident">
<xsl:text> </xsl:text>
</xsl:param>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="model">
{"model":{
"modx":{}
<xsl:for-each select="./object">
<xsl:if test="contains($include-objects,@class) or $include-objects='*'">
<xsl:call-template name="xpdo-object" >
<xsl:with-param name="skip-delimiter">0</xsl:with-param>
</xsl:call-template>
<!-- Get all associated Classes -->
<xsl:for-each select="./aggregate">
<xsl:call-template name="xpdo-object" >
<xsl:with-param name="object" select="@class"></xsl:with-param>
<xsl:with-param name="include-dependencies" select="1"></xsl:with-param>
<xsl:with-param name="skip-delimiter">0</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="./composite">
<xsl:call-template name="xpdo-object" >
<xsl:with-param name="object" select="@class"></xsl:with-param>
<xsl:with-param name="include-dependencies" select="1"></xsl:with-param>
<xsl:with-param name="skip-delimiter">0</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
<!-- /Get all associated Classes -->
</xsl:if>
</xsl:for-each>}
}
</xsl:template>
<xsl:template name="xpdo-object" match="object">
<xsl:param name="object" />
<xsl:param name="skip-delimiter" />
<xsl:for-each select=".">
,"<xsl:value-of select="@class" />":{
"class": "<xsl:value-of select="@class" />",
"extends":"<xsl:value-of select="@extends" />",
"fields": [
{
"name": "id",
"type": "int"
}
<xsl:for-each select="//object[@class=current()/@class]/field">
<xsl:apply-templates select="current()" />
</xsl:for-each>
],
"associations": [<xsl:choose>
<xsl:when test="$include-dependencies=1">
<xsl:choose>
<xsl:when test="$include-local-only=1">
<xsl:apply-templates select="./aggregate[@owner!='foreign']" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="./aggregate" />
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="./composite" />
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>]
}
</xsl:for-each>
</xsl:template>
<xsl:template match="field[@phptype='string']">
<xsl:text> ,{</xsl:text>
"name": "<xsl:value-of select="@key" />",
"type": "string",
"defaultValue":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='json']">
<xsl:text> ,{</xsl:text>
"name": "<xsl:value-of select="@key" />",
"type": "string",
"defaultValue":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='integer']">
<xsl:text> ,{</xsl:text>
"name": "<xsl:value-of select="@key" />",
"type": "int",
"defaultValue":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='date']">
<xsl:text> ,{</xsl:text>
"name": "<xsl:value-of select="@key" />",
"type": "date",
"defaultValue":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='boolean']">
<xsl:text> ,{</xsl:text>
"name": "<xsl:value-of select="@key" />",
"type": "boolean",
"defaultValue":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='datetime']">
<xsl:text> ,{</xsl:text>
"name": "<xsl:value-of select="@key" />",
"type": "date",
"defaultValue":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='timestamp']">
<xsl:text> ,{</xsl:text>
"name": "<xsl:value-of select="@key" />",
"type": "string",
"defaultValue":"<xsl:value-of select="@default" />"
}
</xsl:template>
<!--
<xsl:template match="field[@index="fk"]">
,{
//itemCls:"xpdo-object-field, <xsl:value-of select="@phptype" />, xpdo-foreign-object-<xsl:value-of select="../aggregate[@local=current()/@key]/@class" />",
}
</xsl:template>
-->
<xsl:template match="aggregate">
{
<xsl:choose>
<xsl:when test="@owner='local'"> "type": "hasMany",</xsl:when>
<xsl:otherwise> "type": "belongsTo",</xsl:otherwise>
</xsl:choose>
"model": "<xsl:value-of select="./@class" />",
"primaryKey": "<xsl:value-of select="@local" />",
"foreignKey": "<xsl:value-of select="@foreign" />",
"associationKey": "<xsl:value-of select="@local" />"
}
</xsl:template>
<xsl:template match="composite">
{
<xsl:choose>
<xsl:when test="@owner='local'"> "type": "hasMany",</xsl:when>
<xsl:otherwise> "type": "belongsTo",</xsl:otherwise>
</xsl:choose>
"model": "<xsl:value-of select="./@class" />",
"primaryKey": "<xsl:value-of select="@local" />",
"foreignKey": "<xsl:value-of select="@foreign" />",
"associationKey": "<xsl:value-of select="@local" />"
}
</xsl:template>
</xsl:stylesheet>
<!--
<validation>
<rule field="category" name="preventBlank" type="xPDOValidationRule" rule="xPDOMinLengthValidationRule" value="1" message="category_err_ns_name" />
</validation>
<validation>
<rule field="name" name="invalid" type="preg_match" rule="/^(?!\s)[a-zA-Z0-9\x2d-\x2f\x7f-\xff_-\s]+(?!\s)$/" message="tv_err_invalid_name" />
<rule field="name" name="reserved" type="preg_match" rule="/(?!^(id|type|contentType|pagetitle|longtitle|description|alias|link_attributes|published|pub_date|unpub_date|parent|isfolder|introtext|content|richtext|template|menuindex|searchable|cacheable|createdby|createdon|editedby|editedon|deleted|deletedby|deletedon|publishedon|publishedby|menutitle|donthit|haskeywords|hasmetatags|privateweb|privatemgr|content_dispo|hidemenu|class_key|context_key|content_type)$)/" message="tv_err_reserved_name" />
</validation>
<validation>
<rule field="name" name="name" type="xPDOValidationRule" rule="xPDOMinLengthValidationRule" value="1" message="content_type_err_ns_name" />
</validation>
<validation>
<rule field="name" name="invalid" type="preg_match" rule="/^(?!\s)[a-zA-Z0-9\x2d-\x2f\x7f-\xff_-\s]+(?!\s)$/" message="chunk_err_invalid_name" />
</validation
<validation>
<rule field="category" name="preventBlank" type="xPDOValidationRule" rule="xPDOMinLengthValidationRule" value="1" message="category_err_ns_name" />
</validation>
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" />
<xsl:output method="text" />
<xsl:output indent="yes" />
<xsl:output media-type="text/plain" />
<xsl:param name="directory"/>
<xsl:param name="label-composite">Composites</xsl:param>
<xsl:param name="label-aggregate">Aggregates</xsl:param>
<xsl:param name="xpdo-model"></xsl:param>
<xsl:param name="include-objects">*</xsl:param>
<xsl:param name="include-dependencies">1</xsl:param>
<xsl:param name="include-local-only">0</xsl:param>
<xsl:param name="schema-base-url">#</xsl:param>
<xsl:param name="ident">
<xsl:text> </xsl:text>
</xsl:param>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="model">
{
"model":"<xsl:value-of select="./@package" />",
"version":"<xsl:value-of select="./@version" />",
"schema":[
<xsl:for-each select="./object">
<xsl:if test="contains($include-objects,@class) or $include-objects='*'">
<xsl:call-template name="xpdo-object" >
<xsl:with-param name="skip-delimiter">0</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
]}
</xsl:template>
<xsl:template name="xpdo-object" match="object">
<xsl:param name="object" />
<xsl:param name="skip-delimiter" />
<xsl:param name="schema-base-url" />
<xsl:for-each select="."> {
"type":"object",
"description": "<xsl:value-of select="@class" />",
"extends":"<xsl:value-of select="@extends" />",
"properties": {
"id":{
"description": "id",
"type": "integer"
}
<xsl:for-each select="//object[@class=current()/@class]/field">
<xsl:apply-templates select="current()" />
</xsl:for-each>
<xsl:choose>
<xsl:when test="$include-dependencies=1">
<xsl:choose>
<xsl:when test="$include-local-only=1 and count(./aggregate) > 0">
<xsl:apply-templates select="./aggregate[@owner!='foreign']" />
</xsl:when>
<xsl:otherwise>
<xsl:if test="count(./aggregate) > 0">
<xsl:call-template name="aggregate-inline" />
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="count(./composite) > 0">
<xsl:call-template name="composite-inline" />
</xsl:if>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
},
"links": [
<xsl:choose>
<xsl:when test="$include-dependencies=1">
<xsl:choose>
<xsl:when test="$include-local-only=1">
<xsl:apply-templates select="./aggregate[@owner!='foreign']">
<xsl:with-param name="schema-base-url" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="./aggregate">
<xsl:with-param name="schema-base-url" />
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="./composite">
<xsl:with-param name="schema-base-url" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
]
}
</xsl:for-each>
<xsl:if test="position() != last()">,</xsl:if>
</xsl:template>
<xsl:template match="field[@phptype='string']">
<xsl:text> ,"</xsl:text><xsl:value-of select="@key" /><xsl:text>":{</xsl:text>
"type": "string",
"required":<xsl:call-template name="resolveBoolean"><xsl:with-param name="bool" select="@null" /></xsl:call-template>,
"default":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='json']">
<xsl:text> ,"</xsl:text><xsl:value-of select="@key" /><xsl:text>":{</xsl:text>
"type": "object",
"required":<xsl:call-template name="resolveBoolean"><xsl:with-param name="bool" select="@null" /></xsl:call-template>,
"default":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='integer']">
<xsl:text> ,"</xsl:text><xsl:value-of select="@key" /><xsl:text>":{</xsl:text>
"type": "integer",
"required":<xsl:call-template name="resolveBoolean"><xsl:with-param name="bool" select="@null" /></xsl:call-template>,
"default":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='date']">
<xsl:text> ,"</xsl:text><xsl:value-of select="@key" /><xsl:text>":{</xsl:text>
"type": "string",
"format": "date",
"required":<xsl:call-template name="resolveBoolean"><xsl:with-param name="bool" select="@null" /></xsl:call-template>,
"default":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='boolean']">
<xsl:text> ,"</xsl:text><xsl:value-of select="@key" /><xsl:text>":{</xsl:text>
"name": "<xsl:value-of select="@key" />",
"type": "boolean",
"required":<xsl:call-template name="resolveBoolean"><xsl:with-param name="bool" select="@null" /></xsl:call-template>,
"defaultValue":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='datetime']">
<xsl:text> ,"</xsl:text><xsl:value-of select="@key" /><xsl:text>":{</xsl:text>
"type": "string",
"format": "datetime",
"required":<xsl:call-template name="resolveBoolean"><xsl:with-param name="bool" select="@null" /></xsl:call-template>,
"default":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="field[@phptype='timestamp']">
<xsl:text> ,"</xsl:text><xsl:value-of select="@key" /><xsl:text>":{</xsl:text>
"type": "string",
"format": "timestamp",
"required":<xsl:call-template name="resolveBoolean"><xsl:with-param name="bool" select="@null" /></xsl:call-template>,
"default":"<xsl:value-of select="@default" />"
}
</xsl:template>
<xsl:template match="aggregate">
<xsl:param name="schema-base-url" />
{
"rel": "<xsl:value-of select="./@class" />",
"href": "#",
"targetSchema": "<xsl:value-of select="$schema-base-url" />/<xsl:value-of select="./@class" />"
}
</xsl:template>
<xsl:template match="composite">
<xsl:param name="schema-base-url" />
,{
"rel": "<xsl:value-of select="./@class" />",
"href": "#",
"targetSchema": "<xsl:value-of select="$schema-base-url" />/<xsl:value-of select="./@class" />"
}
</xsl:template>
<xsl:template name="aggregate-inline">
<xsl:text> ,"</xsl:text><xsl:value-of select="./aggregate/@class" /><xsl:text>":{</xsl:text>
<xsl:choose>
<xsl:when test="./aggregate/@owner='local' and ./aggregate/@cardinality='many'">
"type": "array",
"items":{
"type":"string"
},
</xsl:when>
<xsl:otherwise>
"type": "string",
</xsl:otherwise>
</xsl:choose>
"required":<xsl:call-template name="resolveBoolean"><xsl:with-param name="bool" select="./aggregate/@null" /></xsl:call-template>,
"rel": "<xsl:value-of select="./aggregate/@class" />"
}
</xsl:template>
<xsl:template name="composite-inline">
<xsl:text> ,"</xsl:text><xsl:value-of select="./composite/@class" /><xsl:text>":{</xsl:text>
<xsl:choose>
<xsl:when test="./composite/@owner='local' and ./composite/@cardinality='many'">
"type": "array",
"items":{
"type":"string"
},
</xsl:when>
<xsl:otherwise>
"type": "string",
</xsl:otherwise>
</xsl:choose>
"required":<xsl:call-template name="resolveBoolean"><xsl:with-param name="bool" select="./composite/@null" /></xsl:call-template>,
"rel": "<xsl:value-of select="./composite/@class" />"
}
</xsl:template>
<xsl:template name="resolveBoolean">
<xsl:param name="bool" />
<xsl:choose>
<xsl:when test="$bool = 'false'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<!--
<validation>
<rule field="category" name="preventBlank" type="xPDOValidationRule" rule="xPDOMinLengthValidationRule" value="1" message="category_err_ns_name" />
</validation>
<validation>
<rule field="name" name="invalid" type="preg_match" rule="/^(?!\s)[a-zA-Z0-9\x2d-\x2f\x7f-\xff_-\s]+(?!\s)$/" message="tv_err_invalid_name" />
<rule field="name" name="reserved" type="preg_match" rule="/(?!^(id|type|contentType|pagetitle|longtitle|description|alias|link_attributes|published|pub_date|unpub_date|parent|isfolder|introtext|content|richtext|template|menuindex|searchable|cacheable|createdby|createdon|editedby|editedon|deleted|deletedby|deletedon|publishedon|publishedby|menutitle|donthit|haskeywords|hasmetatags|privateweb|privatemgr|content_dispo|hidemenu|class_key|context_key|content_type)$)/" message="tv_err_reserved_name" />
</validation>
<validation>
<rule field="name" name="name" type="xPDOValidationRule" rule="xPDOMinLengthValidationRule" value="1" message="content_type_err_ns_name" />
</validation>
<validation>
<rule field="name" name="invalid" type="preg_match" rule="/^(?!\s)[a-zA-Z0-9\x2d-\x2f\x7f-\xff_-\s]+(?!\s)$/" message="chunk_err_invalid_name" />
</validation
<validation>
<rule field="category" name="preventBlank" type="xPDOValidationRule" rule="xPDOMinLengthValidationRule" value="1" message="category_err_ns_name" />
</validation>
-->
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" method="text" indent="yes" />
<xsl:param name="source-directory"/>
<xsl:param name="target-directory"/>
<xsl:param name="modx-namespace"></xsl:param>
<xsl:param name="xpdo-model"></xsl:param>
<xsl:param name="xpdo-objects"></xsl:param>
<xsl:param name="include-dependencies">true</xsl:param>
<xsl:param name="ident">
<xsl:text> </xsl:text>
</xsl:param>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="model">
/**
@schemaElement(value='model')
@package(value='<xsl:value-of select="@package" />')
@baseClass(value='<xsl:value-of select="@baseClass" />')
@platform(value='<xsl:value-of select="@platform" />')
@defaultEngine(value='<xsl:value-of select="@defaultEngine" />')
@version(value='<xsl:value-of select="@version" />')
*/
<xsl:apply-templates select="./object" />
</xsl:template>
<xsl:template match="object">
class <xsl:value-of select="@class" />
<xsl:if test="@extends">
<xsl:text> extends</xsl:text> <xsl:value-of select="@extends" />
</xsl:if>
{
/*
Public properties
*/
<xsl:apply-templates select="./field" />
/*
Public composite associations
*/
<xsl:apply-templates select="./composite" />
/*
Public aggregate associations
*/
<xsl:apply-templates select="./aggregate" />
}
</xsl:template>
<xsl:template match="field">
/**
@<xsl:value-of select="@key" />(
@default='<xsl:value-of select="@default" />',
@phptype='<xsl:value-of select="@phptype" />',
@required='<xsl:value-of select="@required" />',
@precision='<xsl:value-of select="@precision" />',
@null='<xsl:value-of select="@null" />')
*/
$<xsl:value-of select="@key" /> = '<xsl:value-of select="@default" />';
</xsl:template>
<xsl:template match="aggregate">
/**
@alias
@class
@local
@foreign
@owner
@cardinality
*/
public function get<xsl:value-of select="@alias" />s($constraint,$resultPage){
}
public function get<xsl:value-of select="@alias" />($id){
}
</xsl:template>
<xsl:template match="composite">
/**
@alias
@class
@local
@foreign
@owner
@cardinality
*/
public function get<xsl:value-of select="@alias" />s($constraint,$resultPage){
}
public function get<xsl:value-of select="@alias" />($id){
}
</xsl:template>
<xsl:template match="@*">
<!--
<label>
<xsl:attribute name="for"><xsl:value-of select="name()" /></xsl:attribute>
<xsl:value-of select="name()" />
</label>
<input>
<xsl:attribute name="name"><xsl:value-of select="name()" /></xsl:attribute>
<xsl:attribute name="value"></xsl:attribute>
</input>
-->
</xsl:template>
</xsl:stylesheet>
<?php
class Simplx_Reflect{
function getModelAspectCache($name){
global $modx;
$aspect = $modx->cacheManager->get($name);
if(!$aspect){
$aspect = $modx->getObject('modChunk',array('name' => $aspect ));
$aspect = $routingTable->getContent();
$modx->cacheManager->set($name,$aspect);
}
return $aspect;
}
public function renderModelAspect($model='',$aspect='',$params=null){
$objects;
$includeDependencies=1;
$includeLocalOnly=1;
$modelSchema = $this->getXpdoModelSchema($model);
$xslTemplate = $this->getXpdoModelAspectXsl($model,$aspect);
return $this->transform($modelSchema,$xslTemplate,$params);
}
function transform($modelSchema, $xslTemplate, $xslParams) {
global $modx;
if(!$xslTemplate || !$modelSchema){
$modx->log(modX::LOG_LEVEL_ERROR, 'simplx.reflect: Missing required parameters "xslTemplate" and/or "modelSchema".');
return false;
}
$xslTemplate = new SimpleXMLElement($xslTemplate);
$modelSchema = new SimpleXMLElement($modelSchema);
if(!$xslTemplate || !$modelSchema){
$modx->log(modX::LOG_LEVEL_ERROR, 'simplx.reflect: Unable to parse files xslTemplate and/or modelSchema to XML.');
return false;
}
$xslt = new XSLTProcessor();
if(!$xslt){
$modx->log(modX::LOG_LEVEL_ERROR, 'simplx.reflect: Unable to instantiate XSLT parser.');
return false;
}
if(is_array($xslParams)){
$xslt->setParameter('',$xslParams);
}
$xslt->importStylesheet($xslTemplate);
return $xslt->transformToXml($modelSchema);
}
public function getXpdoModelSchema($model){
global $modx;
$schemaPath = '';
$modelSchema = '';
$corePath = $modx->getOption('core_path');
if($model=='modx'){
$modelSchema = file_get_contents($corePath.'model/schema/modx.mysql.schema.xml');
if(!$modelSchema){
$modx->log(modX::LOG_LEVEL_ERROR, 'simplx.reflect: Unable to load XPDO Schema for model "'.$model.'"');
return false;
}else{
}
$modelSchema = substr ($modelSchema, strpos($modelSchema,'<model'));
return $modelSchema;
}
$ns = $modx->getObject('modNamespace',array(
'name' => $model )
);
if(!$ns){
$modx->log(modX::LOG_LEVEL_ERROR, 'simplx.reflect: Unable to load System Namespace "'.$model.'"');
return false;
}
$schemaPath = $ns->get('path');
// Fix a bug where modNamespace->get() does not substitute {core_path} placeholder
$schemaPath = str_replace('{core_path}',$corePath,$schemaPath);
if(!$schemaPath){
$modx->log(modX::LOG_LEVEL_ERROR, 'simplx.reflect: Unable to get "path" property from System Namespace "'.$model.'"');
return false;
}
//$modelSchema = file_get_contents($schemaPath.'model/schema/'.$model.'/'.$model.'.mysql.schema.xml');
$modelSchema = file_get_contents($schemaPath.'model/'.$model.'/'.$model.'.mysql.schema.xml');
if(!$modelSchema){
$modx->log(modX::LOG_LEVEL_ERROR, 'simplx.reflect: Unable to load XPDO Schema for model "'.$model.'"');
return false;
}
$modelSchema = substr ($modelSchema, strpos($modelSchema,'<model'));
return $modelSchema;
}
public function getXpdoModelAspectXsl($model,$aspect){
global $modx;
$xslt = $modx->cacheManager->get(('aspect.'.($model.'.'.$aspect)));
if(!$xslt){
$xslt = $modx->getObject('modChunk',array('name' => ('aspect.'.($model.'.'.$aspect)) ));
if($xslt){
$xslt = $xslt->getContent();
$modx->cacheManager->set(('aspect.'.($model.'.'.$aspect)),$xslt);
}else{
if(!$xslt){$modx->log(modX::LOG_LEVEL_ERROR, 'simplx.reflect: Unable to load XSLT for "'.('aspect.'.($model.'.'.$aspect)).'".');}
return false;
}
}
return $xslt;
}
}
$model = isset($model) ? $model : 'modx' ;
$aspect = isset($aspect) ? $aspect : 'js';
$action = isset($action) ? $action : '';
$params = isset($params) ? $params : array();
$debugmode = isset($debugmode) ? $debugmode : true;
$result = '';
$reflect = new Simplx_Reflect();
if($debugmode){
$modx->setLogLevel(modX::LOG_LEVEL_DEBUG);
}
if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: Starting up...');
switch($action){
case 'getxslt':
if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter is "getxslt". Running getXpdoModelAspectXsl()');
$result = $reflect->getXpdoModelAspectXsl('default',$aspect);
if($result){
if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: Simplx_Reflect->getXpdoModelAspectXsl() returned false.');
}else{
if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: Simplx_Reflect->getXpdoModelAspectXsl() returned "'.$result.'".'); if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter is "getxslt". Running getXpdoModelAspectXsl()');
}
return $result;
break;
case 'getxpdoschema':
if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'The instruction returned "'.json_encode($result).'"');
return $reflect->getXpdoModelSchema($model);
break;
case 'renderaspect':
if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter is "renderaspect". Running getXpdoModelAspectXsl()'); if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter is "getxslt". Running renderModelAspect()'); if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter is "renderaspect". Running getXpdoModelAspectXsl()'); if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter is "getxslt". Running Simplx_Reflect->renderModelAspect()');
$result = $reflect->renderModelAspect($model,$aspect,$params);
if($result){
if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: Simplx_Reflect->renderModelAspect() returned false.');
}else{
if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: Simplx_Reflect->renderModelAspect() returned "'.$result.'".'); if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter is "getxslt". Running getXpdoModelAspectXsl()');
}
return $result;
break;
default:
if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter "'.$action.'" is unknown.'); if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter is "getxslt". Running renderModelAspect()'); if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter is "renderaspect". Running getXpdoModelAspectXsl()'); if($debugmode) $modx->log(modX::LOG_LEVEL_DEBUG, 'simplx.reflect: $action parameter is "getxslt". Running Simplx_Reflect->renderModelAspect()');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment