SitePoint Sponsor |
|
User Tag List
Results 26 to 50 of 110
-
Oct 10, 2005, 11:58 #26
Originally Posted by Dr Livingston
Code:RequestStack: -- HTTPRequest -- Intercepting Filter -- Controller
Code:Response Stack: -- CommandStack -- Login -- LoginFailed -- LoginSuccess -- ModelStack -- UserDataModel -- ViewStack -- Login -- LoginFailed -- LoginSuccess
What do you guys think about this approach?
Edit:Originally Posted by BerislavLopac
-
Oct 10, 2005, 12:40 #27
- Join Date
- May 2004
- Location
- K.S.A
- Posts
- 81
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
One sollution is to use some kind of HEAP table, because you need(imho) fast responsetimes when working with object(application) persistance. But does SQLite support HEAP?
PHP Code:$db = sqlite_open(':memory:')or
die('Can not create memory DB');
We don't need a reason to help people - Zidane [FFIX]
-
Oct 10, 2005, 16:32 #28
- Join Date
- Nov 2004
- Location
- Canberra, Australia
- Posts
- 66
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by BerislavLopac
Originally Posted by BerislavLopac
PHP Code:function getModule($name=NULL)
{
if (isset($this->modules[$name]))
{
return $this->modules[$name];
}
}
PHP Code:function getModule($name=NULL)
{
return $this->modules->get($name);
}
Originally Posted by BerislavLopac
Originally Posted by BerislavLopac
-
Oct 10, 2005, 21:11 #29
Originally Posted by {RainmakeR}
Originally Posted by {RainmakeR}
Originally Posted by {RainmakeR}
Originally Posted by {RainmakeR}
(config.ini)
object_persistance = "/usr/local/framework_objper.sql"
create_mask = 0700
session_persistance = "/usr/local/framework_ssn.sql"
create_mask = 0700
-
Oct 10, 2005, 21:20 #30
Another thing that came up in my mind is if we want some String/Array/HashMap/Integer/Float classes? As php5 has typehinting for everything except the primitive type, this could be both a bad and good idea to make sure you get the correct input. To illustrate to example doing the same thing:
PHP Code:<?php
class String
{
protected $string;
public function __construct($string=null)
{
$this->string = (string)$string;
}
public function get()
{
return $this->string;
}
public function __toString()
{
return $this->string;
}
}
class Tester
{
static public function typeHinting(String $string)
{
echo $string;
}
static public function normal($string)
{
$string = (string)$tring; /* << Has to be done on all parameter w/o type hinting, IMHO */
echo $string;
}
}
$str1 = new String("Woot1<br />\n");
$str2 = "Woot2<br />\n";
Tester::typeHinting($str1);
Tester::normal($str2);
?>
-
Oct 11, 2005, 00:08 #31
- Join Date
- Sep 2004
- Location
- Zagreb, Croatia
- Posts
- 830
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by jayboots
1. It requires the existence of one file for each application -- e.g., for www.example.com/application/module/ we need to have an "application" file. which means that we can't use a single point of entry (Front Controller) for everything. Even then, Apache's multiviews option seems much more appropriate.
2. I don't think it's portable -- even if it is, other servers like IIS probably have a very different way of handling it.
The 404 hack has the following advantages:
a) It abides the HTTP standards, which means that all HTTP servers have some way of setting it up.
b) Allowes for a more flexible entry point strategy; if we really want separate applications, we can set various subfolders with their own 404 handlers.
That being said, the main disadvantage of this approach that all of your pages return a 404 Not Found response header, which can mess up your HTTP logs.
-
Oct 11, 2005, 00:39 #32
- Join Date
- Sep 2004
- Location
- Zagreb, Croatia
- Posts
- 830
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by {RainmakeR}
Code:[group1] var1 = value1 var2 = value2 [group2] var1 = value1 var2 = value2
PHP Code:array('group1' => array('var1' => 'value1', 'var2' => 'value2'),
'group2' => array('var1' => 'value1', 'var2' => 'value2')
);
Originally Posted by {RainmakeR}
-
Oct 11, 2005, 00:40 #33
- Join Date
- Sep 2004
- Location
- Zagreb, Croatia
- Posts
- 830
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by NeverMind
-
Oct 11, 2005, 00:51 #34
- Join Date
- Jan 2004
- Location
- Oslo, Norway
- Posts
- 894
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by BerislavLopac
Dagfinn Reiersøl
PHP in Action / Blog / Twitter
"Making the impossible possible, the possible easy,
and the easy elegant" -- Moshe Feldenkrais
-
Oct 11, 2005, 01:11 #35
- Join Date
- Sep 2004
- Location
- Zagreb, Croatia
- Posts
- 830
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by thr
PHP has a) automatic serialization of everything and b) custom session handlers. So all you have to do is create a custom session handler which will work with databases (ADOdb already has one), and use your standard $_SESSION syntax.
How is this:PHP Code:Session::store('object', $object);
$object = Session::retrieve('object');
PHP Code:$_SESSION['object'] = $object;
$object = $_SESSION['object']
Originally Posted by thr
First, do you know of any good reason to put simple primitive data into objects? Everything works perfectly well without it, and adding new classes would make things more complicated.
The classes should be defined per objects required for the application. For example, it makes sense to create a class Money, since money can have much more properties than a simple number (currency, subdivisions, conversion rates etc), but a generic Number class would be an overkill.
Second, as I have argued on several occasions, type hinting in PHP should be used very carefully and sparingly, if at all. PHP is a dynamic language, which means that its variables are not tied to any particular data type. It also has a great set of automatic conversion rules, meaking possible such feats as putting a string into one variable and then using it in a math calculation. When it comes to objects, this dynamicism frees us from having to follow strict inheritance hierarchies and applying specific interfaces; instead we can put any object into any variable, and it will work providing it has the right properties (that is called "duck typing").
PHP5 has introduced type hinting and interfaces, but if you think twice you will notice that this is a strange couple: one really makes no sense without the other, and everything can work quite nicely without either of them. If you use type hinting, you will soon or later need to use an interface to enable different hierarchies to be passed to the same method; and without type hinting there is absolutely no requirement to use interfaces.
Personally, I often end up using them simply because they are here and make things easier to understand, although not to implement. However, I'd prefer the good old ducktyping and Python's notion of EAFP -- easier to ask forgiveness than permission. Luckily, PHP5 makes this easy by introducting the exceptions:
PHP Code:// --- permission example:
interface MyInterface
{
function foo();
}
class MyClass(MyInterface $bar)
{
function baz()
{
$bar->foo();
}
}
// --- forgiveness example
class MyClass($bar)
{
function baz()
{
try {
$bar->foo();
}
catch (Exception $e) {
// do something else
}
}
}
-
Oct 11, 2005, 01:18 #36
- Join Date
- Sep 2004
- Location
- Zagreb, Croatia
- Posts
- 830
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by dagfinn
Using shared memory would probably make things faster, but I have quite bad experience with stability of this approach.
-
Oct 11, 2005, 01:50 #37
BerislavLopac: Yeah, your probably correct about the primitive>object thingie.. just a quick thought I got last night.
I'm still trying to come up with some basic frame to build on, after reading the SKeleton-threads I'm leaning more towards some type of State-mechanism to keep the different levels of our application separate. And that all states either evalute to true or false, and both true and false either evaluteate into either true or false themself, etc. Untill we have a response of some kind.
-
Oct 11, 2005, 02:24 #38
Another thing I think we should try to look to is how did Rails come up with thier "almost no config files"-setup? I don't want to mimic the rails API at all, but maybee it could give some good pointers ?
-
Oct 11, 2005, 08:11 #39
- Join Date
- Aug 2003
- Location
- Toronto
- Posts
- 300
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by BerislavLopac
-
Oct 11, 2005, 09:21 #40
Was thinking that we'd need some type of logging mechanism, this is what came out in terms of code of the top of my head:
PHP Code:<?php
class Logger
{
protected $log = array();
public function addLog(Log $log,$identifier)
{
$this->log[$identifier] = $log;
}
public function log($identifier,$message)
{
$this->log[$identifier]->log($message);
}
}
interface Log
{
public function log($message);
}
class FileLog implements Log
{
protected $file;
protected $handle = null;
public function __construct($file)
{
$this->file = (string)$file;
}
public function __destruct()
{
if($this->handle !== null){
fclose($this->handle);
}
}
public function log($message)
{
$this->openHandle();
fwrite($this->handle,$message,strlen($message));
}
protected function openHandle()
{
if($this->handle === null){
$this->handle = fopen($this->file,'a');
}
}
}
class ExceptionFileLog extends FileLog
{
public function log($e)
{
$message = $e->getMessage();
$code = $e->getCode();
$file = $e->getFile();
$line = $e->getLine();
$trace = $e->getTraceAsString();
$log = "Exception on line: $line, in file: $file.\r\nCode: $code\r\nBacktrace: $trace\r\n";
parent::log($log);
}
}
$logger = new Logger;
$logger->addLog(new FileLog("access.log"),'access');
$logger->addLog(new FileLog("error.log"),'error');
$logger->addLog(new ExceptionFileLog('exception.log'),'exception');
$logger->log('error','Error on line...XXX');
$logger->log('access','Logger.php, 18:09 2005-10-11, from localhost');
try{
throw new Exception("... Error ...");
}catch(Exception $e){
$logger->log('exception',$e);
}
?>
-
Oct 11, 2005, 10:02 #41
- Join Date
- Sep 2004
- Location
- Zagreb, Croatia
- Posts
- 830
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by jayboots
-
Oct 11, 2005, 10:26 #42
- Join Date
- Sep 2005
- Location
- Canada
- Posts
- 228
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by BerislavLopac
I'm liking this thread. I personally don't see anything wrong with having more than one option but it IS good to have one or more *well supported* options.
-
Oct 11, 2005, 10:39 #43
- Join Date
- Aug 2004
- Location
- California
- Posts
- 1,672
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Database backend choice or URL format are (or should be) irrelevant to a framework/code base. They are matters of personal preference or system requirements. It is not difficult to handle different cases.
One of the biggest drags on these design converstations is each programmers reaches their set of solutions through a series of choices they make, but they then make the mistake of believing that their solution is the "best" way rather than simply one possible result.Christopher
-
Oct 11, 2005, 10:47 #44
- Join Date
- Sep 2003
- Location
- Wixom, Michigan
- Posts
- 591
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by BerislavLopac
Berislav, you are giving us some very valuable insight into precisely this question through your posts, I find myself constantly nodding in agreement when I read you.Garcia
-
Oct 11, 2005, 11:16 #45
- Join Date
- Aug 2003
- Location
- Toronto
- Posts
- 300
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by BerislavLopac
Code:try { $foo = file_get_contents('bar'); } catch (FILE_NOT_EXISTS) { $foo = file_get_contents('barbar'); }
Subverting 404 can be practical but it is simply not a best-practice.
-
Oct 11, 2005, 11:22 #46
- Join Date
- Sep 2004
- Location
- Zagreb, Croatia
- Posts
- 830
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Trent Reimer
-
Oct 11, 2005, 11:30 #47
- Join Date
- Aug 2004
- Location
- California
- Posts
- 1,672
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by ghurtado
I think if there is and "identity crisis", it is about which direction makes "PHP more like PHP".Christopher
-
Oct 11, 2005, 11:35 #48
- Join Date
- Sep 2004
- Location
- Zagreb, Croatia
- Posts
- 830
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by jayboots
That being said, as I said earlier, the problem with 404 hack is that all your regular page calls start returning 404 errors, which will mess up your logs and give you wrong stats.
-
Oct 11, 2005, 11:38 #49
- Join Date
- Sep 2005
- Location
- Canada
- Posts
- 228
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by BerislavLopac
If you get around that hurdle it means you're wasting computing resources on stuff that really is distracting from the job at hand. Often the simple way is the right way.
Last edited by Trent Reimer; Oct 11, 2005 at 11:39. Reason: speling
-
Oct 11, 2005, 11:56 #50
- Join Date
- Aug 2003
- Location
- Toronto
- Posts
- 300
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by BerislavLopac
This is not exceptional logic, it is application logic. If I want to conditionally show b if a is not available, I should test for a (file_exists) and then try to show b if it is not available. Catching a FILE_NOT_EXISTS represents something else: I *expected* that the file *ought* exist, but it did not.
Bookmarks