Page 2 of 4

Re: New PHP Framework

Posted: Sat Sep 13, 2008 8:01 pm
by powerofq
not a framework
That's just the data storage model.

Client / Ajax < - > PHP business tier < - > EAV DB

Re: New PHP Framework

Posted: Sat Sep 13, 2008 8:59 pm
by Christopher
powerofq wrote:Client / Ajax < - > PHP business tier < - > EAV DB
Again, lots of applications use Ajax and implement dependencies to have a clear business tier/layer. Most modern MVC frameworks encourage/enforce 3-Tier. Business Tier being the old 3-Tier name -- it is usually called the Model or Domain Layer these days.

Re: New PHP Framework

Posted: Sat Sep 13, 2008 10:15 pm
by josh
arborint wrote: I have seen a similar DB design in other CMSs,
is this similar to data driven programming? do you know of an OS CMSs that store logic in the data layer that I could check out, or am I totally confused here lol

Re: New PHP Framework

Posted: Sun Sep 14, 2008 5:00 am
by powerofq
With the semantic network concepts out of the way, here's some actual code. For this example, we'll take and display custom cake orders for a particular client (code is simplified ie: inline js, for clarity)

The page has a form

Code: Select all

<form id=”ordercustomcakeform” action='commander.php'>
<input type=”hidden” name=”order” value=”ordercustomcake”>
<input type=”text” name=”message” />
</form>
<a href=”#” onclick=command(“ordercustomcakeform”);>ORDER</a>
 
When the ORDER event is fired, the command() JS function serializes the form, and sends to commander.php via AJAX

COMMANDER.PHP (simplified);

Code: Select all

<?
$order = $_POST['order'];
 
function e($order){
  $code = singlevalue($order, 'order');
  Eval($code);
}
 
e($order);
?>
Pull the order name from the form.
The e() functions pulls the VALUE of the SUBJECT (in this case 'ordercustomcake') using the 'order' PREDICATE, and executes it (everything that has an 'order' predicate has PHP code for it's value)
singlevalue() is the most common function for working with the DB.. its passed a subject and a predicate, and returns the value. These index nicely, and are very fast.

The VALUE of 'ordercustomcake' order looks like this;

Code: Select all

e('papers');
e('uniquesubject');
e('insertatom');
e('respond');
 
$uid = papers();
$message = $_POST['message'];
 
$orderid = uniquesubject();
 
insertatom($uid, 'hascakeorder', $orderid)
insertatom($orderid, 'message', $message);
 
respond('Order has been saved');
This 'ordercustomcake' order does a few things;
  • - checks the client is logged in, and pulls their userid (exits otherwise);
    - pulls the custom message from the form
    - it creates a unique SUBJECT to represent this order
    - associates the message with the order
    - associates the order with the client
    - sends a mesage back as a response to the Ajax request, confirming the order has been created
The first four lines lazy load supporting orders.
The insertatom() function creates a single declaration in the DB, takes subject, predicate and value args

So, we've recorded our cake order.. the db looks something like this (bob is the customer, and A39G2B... is an abbreviated 32 bit hash)

Code: Select all

 
bob            hascakeorder       A39G2B... 
A39G2B...      message            "Happy Birthday Neo"
VIEWING THE CAKE ORDERS
Now lets say Bob wants to see all of his custom cake orders in a nice table with sortable columns;

Code: Select all

<form id=”viewcakeordersform” action='commander.php'>
<input type=”hidden” name=”order” value=”viewcakeorders”>
</form>
<a href=”#” onclick=command(“viewcakeordersform”);>VIEW ORDER</a>
<div id="cakeorderresults"></div>
*Note the empty div to receive the HTML

The order is passed to the commander as before.

The viewcakeorders order looks like this

Code: Select all

e('papers');
e('vofsandp');
e('sorttable');
 
$uid = papers();
 
$allorders = vofsandp($uid, 'hascakeorder');
 
$headings = array('OrderID', 'Message');
$data = array();
 
foreach($allorders as $order){
  $msg = singlevalue($order, 'msg');
  array_push($data, $order);
  array_push($data, $msg);
}
 
$output = sorttable($headings, $data);
echo "$('cakeorderresults').innerHTML = '$output';";
Again, identify user with papers(), and load two other supporting orders..
vofsandp(); takes the Subject and Predicate, returns an array of Values( in this case, the orderid's of all 'hascakeorders' for 'bob')

sorttable() - takes an array of data, coupled with a headings array, and builds a nicely styled CSS table with sortable columns..

The result is then delivered back to the page as the Ajax response, and is popped into the id='cakeorderresults' div tag.. all pretty like.

So that's pretty much it. I have 100s of orders that can be mixed and matched for the purpose at hand. Building RSS feeds, locking elments on the page to prevent dragging, color mgmt, payment gateways, project management, mashups, image editing, advanced database manipulation, AI.. the list is endless. See the demo at http://rockst-r.com/sandbox for more examples.

Oh, and lowercase rather than camelCase is the way I roll.

Re: New PHP Framework

Posted: Sun Sep 14, 2008 7:34 am
by josh
How well does this profile on large data sets, is this scalable? So your whole data layer resides in this one table? ( or duplicate tables of the same structure )? How do you decide to partition the data? Do you group together similar predicates, like hascakeorder and hasmuffinorder, are the predicates indexed anywhere so the framework knows those two predicates have similar semantic meaning?

Re: New PHP Framework

Posted: Sun Sep 14, 2008 1:53 pm
by Christopher
That is essentially a Front Controller like thingy with the overhead of the database access to load the code -- and it uses eval(). Also looking at the code, and since you alluded to Lazy Loading somewhere, I assume that there are globals that hold all the magic between function calls...

Re: New PHP Framework

Posted: Sun Sep 14, 2008 8:03 pm
by powerofq
arborint wrote:I assume that there are globals that hold all the magic between function calls...
I do use one global, 'page' which holds the name of the page the ajax request came from, but not necessary.
arborint wrote:overhead of the database access to load the code
Code, like everything else, is data.. what makes php data special? But storing the code in a table has other benefits that more than offset any 'overhead'. An order has a unique SUBJECT name like everything else.. Take the singlevalue(); order/function as an example.. we can store metadata with it ie:

Code: Select all

 
Subject   /  Predicate   /   Value
 
singlevalue  /   lastaccessedby   /  bob
singlevalue  /  lastmodifieddate   / 080703
singlevalue  /  revision1   /  "... "

Re: New PHP Framework

Posted: Sun Sep 14, 2008 8:18 pm
by allspiritseve
powerofq wrote:Code, like everything else, is data.. what makes php data special?
The ability to combine data with behavior.
powerofq wrote:Storing the code in a table has other benefits that more than offset any 'overhead'. An order has a unique SUBJECT name like everything else.. Take the singlevalue(); order/function as an example.. we can store metadata with it ie:

Code: Select all

 
Subject   /  Predicate   /   Value
 
singlevalue  /   lastaccessedby   /  bob
singlevalue  /  lastmodifieddate   / 080703
singlevalue  /  revision1   /  "... "
This is starting to sound a lot like ezPublish's content model, which I like very much. It's a slightly more normalized version of your system, where "objects" (your subjects) have their own table, and the "object_properties" table (your values) has a foreign key association with the objects table. This is then organized by classes, so that every object has a foreign key association with a specific class, and then "class properties" for each class (your predicates). See here for a better explanation.

The biggest advantage I see to a system like this, is the fact that you have a global (ie not table-specific) id for every content object in your system, so you could create associations between objects of many different class types, rather than the ones that you explicitly make an association table for. The biggest detriment I see to a system like this is you are storing much more data in a more complex way over standard database practices.

I haven't yet figured out how this content model would fit in with a strong domain model, but that is something I'll be working on in the future.

Re: New PHP Framework

Posted: Sun Sep 14, 2008 8:25 pm
by Christopher
powerofq wrote:Code, like everything else, is data.. what makes php data special?
You can certainly say sentences like that, but saying so does not mean they are not nonsense. There is a clear distinction between 'code' and 'data' in that code can be executed. But the discussion here does not really get to that discussion. It is really about where the code is stored.
powerofq wrote:But storing the code in a table has other benefits that more than offset any 'overhead'. An order has a unique SUBJECT name like everything else.. Take the singlevalue(); order/function as an example.. we can store metadata with it ie:
There is really no difference between the information you attribute to a specific request and what is available with Front/Action Controllers.

As allspiritsteve said, this system sounds like some other interesting system I have seen. I would add the way Google used 'tags' for doing multiple things as another example. I am not saying that your system is not reasonable, not well designed, nor possibly of interest. But you presented it as conceptually unique, incomprehensible to the average programmer, and used a bunch of mumbo-jumbo like 'metadata,' 'entity' and 'semantic network model' to describe it...

Re: New PHP Framework

Posted: Sun Sep 14, 2008 8:48 pm
by allspiritseve
arborint wrote:
powerofq wrote:incomprehensible to the average programmer, and used a bunch of mumbo-jumbo like 'metadata,' 'entity' and 'semantic network model' to describe it...
I think the latter may have contributed a bit to the former...

Re: New PHP Framework

Posted: Sun Sep 14, 2008 9:06 pm
by powerofq
jshpro2 wrote:How well does this profile on large data sets, is this scalable? So your whole data layer resides in this one table? ( or duplicate tables of the same structure )?
I've benchmarked in the past, and it scales better than average. Imagine the index on a 3 column table where your query is pulling all cake orders "select value from atoms where subject='bob' and predicate='hascakeorder' ". The same structure in a hash table was blazing. The model works nicely with memcached as well, and has room for further optimizations.

Everything is in a single table, but given consistent structure of the model, allows access to 100s of DBs with no need to know how the Db is structured (we already know).

Along this line, each subject is it's own namespace as well.
And predicates really should be defined, ie: if we all agree to use the "dateofbirth" predicate, queries would be universal.
jshpro2 wrote: How do you decide to partition the data? Do you group together similar predicates, like hascakeorder and hasmuffinorder, are the predicates indexed anywhere so the framework knows those two predicates have similar semantic meaning?
Absolutely. It's a fairly extensive topic, but it's actually the reason I developed this framework.

If what I've shown so far was the extent of the benefits of using the Semantic Network Database (SNDMS), then hey.. that's great, but where it really begins to take off is with Semantic networking..
"What is common to all semantic networks is a declarative graphic representation that can be used either to represent knowledge or to support automated systems for reasoning about knowledge."
http://www.jfsowa.com/pubs/semnet.htm
Semantic Networking has more purpose in some areas than others. I don't know there's much use for it in baked goods, for example.. but you could do something like this. "Display all bakery orders shipped on Thursday that weighed less than 1 pound."

Re: New PHP Framework

Posted: Sun Sep 14, 2008 9:59 pm
by powerofq
From Wikipedia on the 'mumbo-jumbo' known as metadata;
http://en.wikipedia.org/wiki/Metadata#V ... efinitions
"Metadata helps to bridge the semantic gap. By telling a computer how data items are related and how these relations can be evaluated automatically, it becomes possible to process even more complex filter and search operations. For example, if a search engine understands that "Van Gogh" was a "Dutch painter", it can answer a search query on "Dutch painters" with a link to a web page about Vincent Van Gogh, although the exact words "Dutch painters" never occur on that page. This approach, called knowledge representation, is of special interest to the semantic web and artificial intelligence."

Re: New PHP Framework

Posted: Sun Sep 14, 2008 11:12 pm
by Christopher
I think terms like metadata and semantic network as they relate to representing information (you'd say "knowledge representation" ;)) are completely understandable by any programmer if you do not use mumbo-jumbo to make yourself sound cool. When you start getting into AI and ways to implement these concepts (you'd say "heuristics" ;)) it certainly gets more complex. But I think you are really taking about pretty standard kinds of information and relationships here.

On top of that you are quoting 25 year old papers that, though significant, have been surpassed by discussions of the semantic web (which many programmers understand) and beyond that more probabilistic ways to represent information such as what search engines do. Even that can be discussed by many programmers here, with possibly interesting insights, if we reduce the mumbo-jumbo and hyperbole ...

Re: New PHP Framework

Posted: Mon Sep 15, 2008 12:14 am
by alex.barylski
Not sure if I understand correctly but...are you storing PHP code in the database and later eval'ing it?

I can't say I like that approach:

1. SQL injections are probably the most common attack especially in PHP. Even if file permissions on a PHP script are 777 an outside attacker would still likely have a challenge updating the files. SQL injection would be trivial for anyone who understood how they are executed.

2. My IDE doesn't understand DB tables it understands native files.

Saying code and data are the same thing...I strongly disagree. For the CPU sure code and data are ambiguous (for lack of a better word) but for the high level developer focused on good design, simplicity, conventions, etc...there is a HUGE difference between code and data, much like there is between OOP or procedural programming.

How do you find the PHP source you are looking for if all source modules/functions/whatever are stored in a trivial lookup table? I'm not sure I fully understand how or why you are storing code this way...

Subject predicate and value fields to store an entire source tree sounds like a lot of work maintaining. File systems are structured (usually) in such a way to expedite finding a source file. How do you use a linear list to find that same code? It's analogous to storing all files in a single directory which does lead to misnomers when labeling code which does little for simplifying source code.I think I need to hear more.

Re: New PHP Framework

Posted: Mon Sep 15, 2008 1:18 am
by matthijs
The terminology used here isn't very clear to me. However, is putting everything in one table not the concept of the OTLT or EAV? I recently did a bit of reading about it.

I soon found out there are some problems/considerations to deal with:
http://www.dbazine.com/ofinterest/oi-articles/celko22
http://tonyandrews.blogspot.com/2004/10 ... takes.html
http://decipherinfosys.wordpress.com/20 ... kup-table/
http://weblogs.sqlteam.com/davidm/articles/12117.aspx

I'm by far an expert on database design, so you should read those links for a good explanation