Permalink
Browse files

+ implemented modeler environment

  • Loading branch information...
jgswift committed Mar 22, 2011
1 parent e89ed09 commit ae99fbcd6d38ed3af9a1853527149004b26952d9
@@ -50,7 +50,7 @@ function setText( $text )
$this->_text = $text;
}
- function assemble()
+ protected function assemble()
{
$this->_text = parent::assemble();
@@ -68,6 +68,7 @@ function getDefaultStream()
function resolve( $connection = null )
{
+ //TODO: CHECK IF PLATFORM SUPPORTS TRANSACTIONS, THROW EXCEPTION IF NOT
if( $connection instanceof \DBAL\Database )
{
$this->setDatabase( $connection );
@@ -19,17 +19,18 @@ protected function reflect( $class = null )
return false;
}
- protected function resolve( $className, &$ref )
+ protected function resolve( $className, &$component )
{
- if( array_key_exists( 'Namespace', $ref->Parameters ))
- $className = $ref->Parameters['Namespace'].'\\'.ucfirst($className);
+ if( array_key_exists( 'Namespace', $component->Parameters ))
+ $className = $component->Parameters['Namespace'].'\\'.ucfirst($className);
return $className;
}
function call( $name, array $arguments, &$ref )
{
- $classPath = $this->resolve( $name, $ref );
+ $component = $ref->getComponent();
+ $classPath = $this->resolve( $name, $component );
if( ( $class = $this->reflect( $classPath )) !== false )
{
@@ -53,7 +54,7 @@ function call( $name, array $arguments, &$ref )
$arguments[ $k ] = $ref;
$object = $class->newInstanceArgs( $arguments );
-
+ $object->setComponent( $component );
if( $object instanceof I\Nameable )
$object->setName( $class->getShortName() );
View
@@ -13,20 +13,29 @@ function getBuilder()
function getDefaultBuilder()
{
- $params = $this->Parameters;
- $params['Component'] = $this;
- return new \Kinesis\Task\Builder( $params );
+ if( array_key_exists('BuilderClass', $this->Parameters ))
+ $builderClass = $this->Parameters['BuilderClass'];
+ else
+ $builderClass = 'Kinesis\Task\Builder';
+
+ $builder = new $builderClass( array() );
+
+ return $builder;
}
function setBuilder( \Kinesis\Task\Builder $builder )
{
+ if( !array_key_exists('Namespace', $this->Parameters ))
+ $this->Parameters['Namespace'] = get_class( $builder );
+
+ $builder->setComponent( $this );
$this->builder = $builder;
}
function build()
{
if( is_null( $this->builder ))
- $this->builder = $this->getDefaultBuilder();
+ $this->setBuilder( $this->getDefaultBuilder() );
return $this->builder;
}
View
@@ -3,8 +3,15 @@
abstract class Task extends Component
{
+ /**
+ * Implemented differently for various tasks
+ */
abstract protected function execute();
+ /**
+ * Catch or ensure invoke arguments
+ * @return mixed Task execution result
+ */
function __invoke()
{
if( func_num_args() > 0 )
@@ -14,5 +21,4 @@ function __invoke()
return $this->execute( $args );
}
-
}
@@ -3,6 +3,18 @@
class Builder extends Factory
{
+ protected $component;
+
+ function getComponent()
+ {
+ return $this->component;
+ }
+
+ function setComponent( \Kinesis\Component $component )
+ {
+ $this->component = $component;
+ }
+
function execute()
{
$dispatcher = new \Kinesis\Dispatcher();
@@ -9,11 +9,7 @@
protected $component;
function getComponent()
- {
- if( is_null( $this->component ) &&
- $this->isRoot() )
- $this->component = $this->Parent->Parameters['Component'];
-
+ {
return $this->component;
}
@@ -88,7 +88,7 @@ function __invoke( $statement = null, array $args = array() )
if( get_class( $statement ) == 'Closure' )
$result = $statement( $this->Reference, $this->_method, $args );
- else
+ //else
//TODO: THROW EXCEPTION: STATEMENT NOT VALID
if( !empty( $args ) &&
View
@@ -78,6 +78,8 @@ private static function object( $ref )
$type = new Type\Object\Builder();
elseif( stripos( $name, 'controller') !== false )
$type = new Type\Object\Control();
+ elseif( is_subclass_of($name, '\Kinesis\Task\Builder'))
+ $type = new Type\Object\Builder();
elseif( is_subclass_of($name, 'Kinesis\Task' ) )
$type = new Type\Object\Task();
elseif( is_subclass_of($name, 'Kinesis\ArrayList' ) )
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
@@ -1,28 +1,51 @@
<?php
-$driver = new \DBAL\Driver\MySQL();
-$database = new \DBAL\Database( $driver );
-
+use DBAL as DB;
+// MODEL BUILDER TEST
+// Model builder modifies tables and column definitions in the database
+/* EXAMPLE XML ENTITY
+
+<entity name="Clothing" type="Product">
+ <attribute name="Color" type="string">None</attribute>
+</entity>
+
+*/
+// ESTABLISH DATABASE
+$driver = new DB\Driver\MySQL();
+$database = new DB\Database( $driver );
$core->setDatabase( $database );
-$source = new \DBAL\Data\Source();
+// DATA COMPONENTS
+$source = new DB\Data\Source();
+$adapter = new DB\Data\Adapter();
-$adapter = new \DBAL\Data\Adapter();
+// RETRIEVE XML ENTITY DATA
+$adapter->View = new DB\XML\View\Entity();
+$xmlEntities = $adapter->Fill( $source );
+// RETRIEVE SQL ENTITY DATA
+$adapter->View = new DB\SQL\View\Entity();
+$sqlEntities = $adapter->Fill( $source );
+// CREATE MODELER
+$query = new DB\SQL\Query();
+$query->setBuilder( new DBAL\SQL\Modeler( array() ) );
-$adapter->View = new \DBAL\XML\View\Entity();
-$adapter->Fill( $source );
+// SPECIFY THE ENTITIES TO COMPARE
+$query->build()
+ ->update( $sqlEntities )
+ ->set( $xmlEntities );
-$adapter->View = new \DBAL\SQL\View\Entity();
-$adapter->Fill( $source );
+// CREATES/ALTERS/DROP SQL TABLES OR COLUMNS
+// COMPARE XML TO CURRENT SCHEMA AND GENERATE DIFFERENCE
+// GENERATE TRANSACTION TO UPDATE SCHEMA BASED ON DIFFERENCES
+$query();
-$adapter->Update( $source );
//foreach( $source as $entity )
//{
// unset( $ent );
// $ent = $database->Models[ucfirst($entity->Name)];
//
-// if( $ent instanceof \DBAL\Data\Entity )
+// if( $ent instanceof DB\Data\Entity )
// {
// var_dump( $ent->Name );
// var_dump( $ent->equals( $entity ));

0 comments on commit ae99fbc

Please sign in to comment.