Archive

Archive for the ‘Uncategorized’ Category

PHP 5.2, late static binding, get_called_class() and $self = new self()

July 29th, 2009 visual77 8 comments

Early on in Septuro’s development, well prior to the name being adopted, I had a tough challenge dealing with the dataTemplates. Chris Webb, one of the Septuro founders, was helping me with this particular issue. In the abstract dataTemplate, we wanted to set up a factory method make() that just pumped out an instance of the class that was called. The issue that we ran into involved late static binding.

class abstract_dataTemplate {
    static function make() {
        return new self();
    }
}
class stringTemplate extends abstract_dataTemplate {

}
stringTemplate::make();

In this example, we called stringTemplate::make(), but since make() is defined within abstract_dataTemplate, the function will always return an instance of abstract_dataTemplate. We found out that in PHP 5.3, late static binding will be better supported and come with a function get_called_class() that will return the name of the called class, rather than the current class. Unfortunately, we run PHP 5.2 on our servers and are unable to use this function. I considered using debug_backtrace(), file() and preg_match() to mimic the functionality, but this won’t work if there is more than 1 instance per line of a late static bind call.

I looked at php.net to see if anyone else found a good solution, but everyone seemed to be stopped at the same point I was. Then I realized I could use static class properties to keep a count of how many times a match has already been found on the current line. This would let me support multiple calls per line without issue – with each call returning the exact class that called it. So I took a function listed in the php.net comments and modified it up to make use of this static class.

if(!function_exists('get_called_class')) {
    class class_tools {
        static $i = 0;
        static $fl = null;

        static function get_called_class() {
            $bt = debug_backtrace();

            if(self::$fl == $bt[2]['file'].$bt[2]['line']) {
                self::$i++;
            } else {
                self::$i = 0;
                self::$fl = $bt[2]['file'].$bt[2]['line'];
            }

            $lines = file($bt[2]['file']);

            preg_match_all('
                /([a-zA-Z0-9\_]+)::'.$bt[2]['function'].'/',
                $lines[$bt[2]['line']-1],
                $matches
            );

            return $matches[1][self::$i];
        }
    }

    function get_called_class() {
        return class_tools::get_called_class();
    }
}

We now have perfect support of get_called_class() in PHP 5.2, and we can use the factory method make() inside the abstract dataTemplate, rather than in all of the derived templates.

Categories: Uncategorized Tags:

Less sucky theme!

June 25th, 2009 visual77 No comments

So, anyone who saw this site prior to today would notice something – that theme is awful. Well, screw you, I was in a hurry. I chose the old Wordpress default theme over the new one for one reason – the new one didn’t list the author name. Now, I know what you’re thinking, we created Septuro – we know code, I could’ve edited it. Yeah, I could’ve edited the new default theme to show authors, but I was just trying to get this set up on a stable host, since SourceForge’s hosting is pretty crappy. Well, today I updated to the iNove theme, which looks clean enough and shows the author names of each post.

One of these days, I’ll get the theme looking even better, but for now, this theme is acceptable and does what we need it to do. At some point, we’ll have this site running on Septuro, but until that time, this Wordpress blog is good enough for what we are using this site for – to just post on where the project is at.

Speaking of that, the project is still moving smoothly, and we’ve got our development machines working with DOMi and Septuro in such a way that we keep fixing DOMi bugs while doing Septuro work – so we’re now advancing both projects smoothly. The same thing will happen once we get Yeakum started, as it is just an extension of Septuro into a full blown CMS, but I can’t talk about that project too much… yet. Once it gets rolling, you’ll be hearing about it.

Categories: Uncategorized Tags:

I’m trying to figure out how open source copyright is applied

June 5th, 2009 visual77 No comments

I am an extremely rabid fan of open source software, and Phil and I plan to release Septuro as an open source project. However, one hurdle that we are now encountering is not fully knowing how to do the open source copyright to make it complete and enforceable. This is the first open source project that either of us have worked to this extent. We did DOMi last year, but it was a standalone file that doesn’t have anywhere near the complexity that Septuro has.

We originally planned to use the Creative Commons 3.0 BY-SA license, but after a bit of research, I find out that their license is not ideal for software, and is more intended for works of art. I looked a little bit further, and now we are looking at using the GNU GPL license, and figuring out what we need to do to make it apply to Septuro. I have gone ahead and added a notice to each of the core source code files (a lot of the extended objects are pretty minimal and unimportant, so I don’t see the need to put the notice on everything).

If anyone out there could give us some pointers, I would be very appreciative. We want this software to be freely available to everyone. Part of that will be to make sure nobody else can come along and clamp it down, should we not set up our rights properly. This weekend, I’ll be doing some research into open source copyright law, and I’ll hopefully have this sorted out soon, so we can protect Septuro the way we want it to be protected – by protecting it’s free nature and make sure nobody can lock it down.

Categories: Uncategorized Tags: