Notice: Undefined index: HTTP_ACCEPT in /var/local/cache/midgard/midgard/31-100-217-0.php(66) : eval()'d code on line 11

Blog: category "duct"

PHP5 xmlObject

Posted on 2008-08-05 18:37:23 EEST to .

UPDATE [08/06/2008]: Version update. Did some fixing and made it work better with larger structures.

Here's another simple little helper I developed for Duct framework.
I use this one to convert my arrays to XML. As Duct automatically scaffolds objects from XML/YAML to database
and uses the same methods to render the database objects to html forms for editing I needed some quick way to
transform this data to and from XML. Class end examples are here

Usage example:

<?php
$resource = new xmlObjectItem();
$resource->items = array(
'id' => 100,
'name' => "Jerry Jalava",
'person_id' => 1
);
$resource->attributes = array(
'person_id' => array(
'is_assoc' => true,
'foreign_model' => 'person',
'foreign_key' => 'id'
)
);

$resource_set = new xmlObjectSet();
$resource_set->wrapper_id = 'resource';
$resource_set->items[] = $resource;

$projects = array();
for ($i=1; $i <= 1; $i++)
{
$object = new xmlObjectItem();
$object->items = array(
'id' => $i,
'name' => "Project {$i}",
'manager_id' => $i+1,
'resources' => $resource_set
);

$projects[] = $object;
}

$project_set = new xmlObjectSet();
$project_set->wrapper_id = 'project';
$project_set->items = $projects;

$clients = array();
for ($i=1; $i <= 1; $i++)
{
$client = new xmlObjectItem();
$client->items = array(
'id' => $i,
'name' => "Client {$i}",
'contact_id' => $i+1,
'team-leader' => null,
'projects' => $project_set
);
$client->attributes = array(
'contact_id' => array(
'is_assoc' => true,
'foreign_model' => 'person',
'foreign_key' => 'id'
)
);

$clients[] = $client;
}
$client_set = new xmlObjectSet();
$client_set->wrapper_id = 'client';
$client_set->items = $clients;

echo "complex set:\n";
var_dump($client_set);

echo "\n--------toXml---------\n";

$xmlSet_clients = xmlObjects::toXml($client_set, 'clients');
echo "complex:\n";
echo $xmlSet_clients;

echo "\n--------fromXml---------\n";

$client_set = xmlObjects::fromXml($xmlSet_clients);
echo "client_set root: {$client_set->root}\n";
var_dump($client_set);

echo "\n--------back toXml---------\n";

$xmlSet_clients2 = xmlObjects::toXml($client_set);
echo "complex:\n";
echo $xmlSet_clients2;

if ($xmlSet_clients == $xmlSet_clients2) {
echo "\n\nVALID SET CONVERSION\n\n";
}

?>

PHP5 events class

Posted on 2008-08-04 12:42:01 EEST to .

While I was building Duct Frameworks server side with PHP5 I realized I needed some kind of event support for it.
So I created similar approach that ActionScript uses. You can download the class with example from here.

Hopefully this comes in handy for someone else also. 

Here is simple example also:

 

<?php

class mother extends events_observable
{
public function __construct()
{
parent::__construct();

$this->addEventListener(events_event::ONCONSTRUCT, events::delegate($this, 'on_object_constructed'));
}

public function on_object_constructed($target, $args)
{
echo "{$target->name} has born.";
}
}

class child extends events_observable
{
public $name;

public function __construct($name)
{
parent::__construct();

$this->name = $name;

$this->dispatchEvent(new events_event(events_event::ONCONSTRUCT, $this));
}
}

$mother = new mother();
$child = new child('Jack');

?>

Duct Framework

Posted on 2008-07-17 18:15:30 EEST to .

Duct is something I have planned doing for a while and started coding last week.

What is Duct? (or what it will be)

Duct is a Flash framework with different generators and tools.
with single click it can generate dynamic Flash Sites, Banners, Polls, Surveys, etc. (through engines)
It has it's own server implementation also which allows dynamic content, mail and other features
for Flash. Server side is written with PHP but I have planned a Python version of it also.

Currently Duct UI is built to Flash IDE but I have plans to add Commandline, Online and Standalone support also.

I'm going to publish this as a Open Source project as soon as it gets a bit more mature.
Also more about the whole project will be published later.

Here are some screenshots of the Banner Engine. (And scaffolded banner project.)

scaffoldedBanner.png
(All these files have been generated after pressing the "Create" -button)