3 Replies - 1237 Views - Last Post: 01 June 2008 - 10:51 PM Rate Topic: -----

#1 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1134
  • View blog
  • Posts: 7,094
  • Joined: 07-September 06

creating a php framework

Post icon  Posted 29 May 2008 - 06:45 PM

Frist off it has been a long time, I know but I have started up a new project (now that I am out of school for summer) and have already hit a brick wall. It's nie to be back.

Okay, so here is what I am attempting to do. I would like to create a php framework to make things such as blogs and forums easier to set up and customize after creation. While there may already be something like tis out there I haven't been able to find it and, as you mayremember about me (wierd as I am) I prefer to write my own code so that I can edit it later with less hassle.

Basically what I am attempting to succeed in for a final project is to have some code in standard (X)HTML like so:
<html>
<head>
<import[[standard_skin.css,js_files.js]] />
</head>
<body>
<table>
<tr>
<td style="width: 150px"><!-- Left pane-->
  <user>
  <avatar[[float:left]] />
  <username />
  Posts: <posts />
  etc.
</td>
<td>
content here
</td>
</tr>
</table>
</body>
</html>


and have php able to successfully parse the additional (at this point made up) (X)HTML tags; so the <username> tag would post the user's username and so on.

The problem I am having at this point in time, and yes it is very early into the whole project; no this isn't for school or anything other than my personal quest for knowledge.

So, it is about time I show some work (all I am asking at this point is for some help getting this to work properly).

Here are my files, with the exact contents:

index.php:
<?php
require'class.php';
require'tmp.php';

$compile_fw = &new framework;
echo $compile_fw->init($t_str);
?>


class.php:
<?php
class time{
  function tostamp($time){
	return strtotime(Stime);
  }
}

class framework{
  function init($str){

	$from = "|\<(.*?)\[\[(.*?)\((.*?)\)\]\]\/>|i";
	$to = '$tmp = &new $1; $tmp->$2($3);';
	$content = preg_replace($from, $to, $str);

	return $content . '<br>OP: ' . eval($content);
  }
}
?>


tmp.php:
<?php
$t_str = <<<EOS

<time[[tostamp('now')]]/>

EOS;
?>


NOTE - in this case tmp is standing for template, not temporary.

Okay, as you can see I have the class and tmp files required by the index file, then go throught and have it "compile" the tmp file and return an output, which looks like so:

$tmp = &new time; $tmp->tostamp('now'); 
OP: 


Where the OP: is should be giving a timestamp but at this point is not outputting anything (and is getting quite annoying).

As I haven't had much use for eval() in the past it is possible (and very probable) that I am mis-using it and thus my problems are occurring, however I believe that there is something else adding to the issues I am having.

Ideally the eval() statement would be unnecessary but at this time I see no way around using it.

Hopefully someone can point me in the right direction.

Thanks in advance,
BetaWar

PS - if you are itnerested in seeing the current version in all its broken glory here is the address:
http://www.reigningg...phpfw/index.php

Is This A Good Question/Topic? 0
  • +

Replies To: creating a php framework

#2 joeyadms  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: creating a php framework

Posted 29 May 2008 - 10:41 PM

When I was waiting for the Zend Framework a while back, I created my own framework from some knowledge of Cake. What you are wanting to do as far as the custom tags, is make a template parser, There is a tutorial on google, I forget which site, maybe devshed, on creating one.

Oh and your returning the strtotime() , so try this
echo $tmp->tostamp('now'); 



If you want to look over what I did a while back, I still have the source and API online. It is horrific though.

http://bin.joeyadams...garooFramework/
Was This Post Helpful? 0
  • +
  • -

#3 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1134
  • View blog
  • Posts: 7,094
  • Joined: 07-September 06

Re: creating a php framework

Posted 30 May 2008 - 08:41 AM

Thanks for the reply.

At this point I think I may have been a little confusing with my prior post. I have it so that everything the functions are outputting is being echoed

echo $compile_fw->init($t_str);


The second to last line of index.php does that.

Through class.php's framework class it goes off and takes $t_str and changes it into php, giving this:

$tmp = &new time; $tmp->tostamp('now');


This is a totally dynamic procedure and as such there is no way to know what class/function will be called beofre itis run, as $t_str gives all the information on class, function and params (and later on will contain multiple class calls and (X)HTML as well).

So telling it to echo $tmp->tostamp('now'); is hat I am wantint it to do there is the problem of getting php to evaluate it as code and not simply text in a string.

At this point I haven't looked over your source, but I am about to.

Again, thanks fotr the reply,
BetaWar
Was This Post Helpful? 0
  • +
  • -

#4 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1134
  • View blog
  • Posts: 7,094
  • Joined: 07-September 06

Re: creating a php framework

Posted 01 June 2008 - 10:51 PM

Sorry ahead of time, this post will act mostly as a bump.

However I was thinking, and instead of making this as complicated as it is turning out to be (as I haven't been able to come up with anything that gets it to work correctly yet, and nobody else has given me a reply since... 2 days ago [almost 3]). Maybe we could go about trying to make a sinple suped up BB addition to things, and have them just using predefined variables to set anything that needs to be dynamic instead of rendering the variables on the spot?

So the application would go through and set things like the class pointers etc and the replaces could just change out the variables for the tags?

Does that sound like it could work out better than this to others?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1