Thursday, July 26, 2012

Something usefull - at last


Couple of weeks ago I had serious doubts about continuing my CMS, after seeing this video.

I thought why should I make CMS when so many other already done it much better than I ever could.
But then I realized that thinking that way is like thinking "Why should I go for a run, when there is always someone who runs faster". Building CMS is not a composition, at least - not for me.

I'we bumped into some interesting articles recently, like What's the least You can expect from a modern CMS. That is a quite good list of things to do in my CMS. Not all at once, but little by little.

As I told earlier I renamed by CMS to Cimbic. There has been progress with the system, new GitHub repository, redone namespacing (for the 3rd time), now I will follow PSR–2 conding conventions. Although I don't totally agree with all of the rules, following that style guide will produce clean, easy-to read code.

The Cimbic will not use any database to store the content. At this point I'we managed to get Cimbic to provide static .htm files with free hierarchy. The content is wrapped in html generated from Dwoo templates. If the requested content doesn't exist, Cimbic will show custom 404-page. First time since I started the project and this blog I actually have something someone could use as base for their web-page.

Cimbic hierarchy in a nutshell:

  somesite.net –launches–> Cimbic –extends–> JSFramework

Aim is that the site (somesite.net) has as little business logic as possible, only php-script at the moment is Public/index.php - used only for launching Cimbic-instance.

Now that I got the displaying of content to work, the next steps (after I get the tests to work again…) is to implement editing of the content, session management and so on. I'm going to try using Create.js for editing content. Their demo is SO cool! Definitly something I want my CMS to have - simply elegant.

I'll put the CMS live to my homepage in progress. And as always, I will share everything on GitHub, possibly be the most important social network in existence.

Keep on coding!

Tuesday, July 10, 2012

New parameter besides POST and GET

"Comment Your code. Do the tests first. This forces You to think WTF it is that You're doing."

This is how I commented my friend when he said that he had wrote code that he doesn't know that the f*k it does, but it works. You don't do anything with code if You don't know what it does. Would You agree?

The bug I had earlier in my framework about mixing traditional and this custom way of GET-parameters fails - has been fixed. But if I give parameters in URI like this:

/YourController/itsMethod/someParam:value/fuu:bar/

and interpret it as request for controller "YourController"s method "itsMethod" and parameters "someParam" = "value" and "fuu" = "bar", then the parameters are not GET-parameters. Those would be given like: "?someParam=value&fuu=bar".

But what are they? I think I need to give them some sort of name.

Naming stuff is hard. I want to give describing name that actually means something but doesn't have risk to be confuced with something else. Name "URI" would confuce to beleave that it's the whole "Uniform resource identifier". The usage of these parameters would be to refer to certain ID:s, for example like:

/User/view/id:145/ or /Page/show/pid:37/

But naming the parameter just "ID" would not tell the whole story. And concider the code $_ID['id']… Don't like it. But how about "UNIQ", short from "unique". $_UNIQ['id'] is much more like it. Let's think the URI again for second, code $_URI['id'] could be read like "part 'id' from 'URI'" - but that is exactly what it is. No matter if one would use it as something else than identifier, the concept would still be correct. URI "/User/list/start:15/limit:50/" would have parts "start" and "limit".

It is desided then: In my framework there shall be three kind of parameters, GET-, POST- and URI-parameters.


And more about naming stuff. I previously named my framework "JSFramework". Well, it has obvious risk being confused as JavaScript framework when it in fact is a PHP framework. A colleague of mine wrote that writing my own framework rather than using existing "proves my hubris". After googling I found out that hubris meas extreme pride and arrogance. Being one of the three virtues of a programmer, I take it as compliment.

In Finland we have this saing "Siitä se ajatus sitten lähti", roughly "That's where the idea began". How does Hubris Framework sound like?

And the CMS? To be honest, would You use content management system named "Keijo" (traditional finnish male name). Today I came up with another name: "Cimbic". "Cms I Made Because I Can". It also appears to be a name - apperently lastname and name of a company. But I doupth naming my CMS that would in any way be a problem.



- Joona

Sunday, July 8, 2012

Couple of all-nighters

Quite tired right now... Haven't got much sleep recently, but quite a lot of code and tests.

At the start I kind of dumped Zend Framework. I don't know hot it works and I want to know how the code I use works. So made my own framework, at least version 0.0.1.

So now I have two projects going on at the same time, Framework (JSFramework) and CMS (keijoCM). I'll try to put everything CMS specific into the CMS and other, re-usable stuff into the Framework.

I got the code coverage of Unit tests of JSFramework to about 73 %, target being 100 %. I ran into multiple unit testing related problems like how to mock PHP's native functions or mysqli-object, or how to mock a class wich is used inside the class under test. For example creating a new View-object in Controller's init() method. When testing the class Controller, I don't want to test/use the class View at all. If I made a stub of the class, I would get the same error as below.

Yet another problem with the tests was stub-classes when generating code coverage report. I made "wrapper" class for some native functions so I could mock those, for example the header() function. I don't want the class under test to put actual headers (will throw error), so I wrapped it to NativeFunctions::header(). And for the test I rewrote the NativeFuctions so that header() would just return "true". Everything went ok, tests run, all green but when the PHPUnit starts making code coverage report I got PHP Fatal about redeclaring NativeFunctions-class. The only doable solution I found was to exclude the NativeFunctions from the code coverage report with:


    <filter>
        <whitelist>
            <directory suffix=".php">../Source</directory>
            <exclude>
                <file>../Source/NativeFunctions.php</file>
                <file>../Source/autoloader.php</file>
            </exclude>
        </whitelist>
    </filter>


But I got the JSFramework somewhat tested and started the keijoCM today. Basically what it does at the moment is determinate from the url what controller and method to use and parses extra GET-parameters from url. Normally parameters are given like "...?name=value&another=somethingElse", but keijoCM accepts like ".../name:value/another:somethingElse" and can be (as far as I know) then indexed by search engines (for example Google).

Great... now I found a bug... If You mix those two ways, the url parsing doesn't work as expected. Well, next steps are to create a test that catches the bug and then eliminate it. Search and destroy.

Friday, July 6, 2012

And so it begins

My first blog text - ever.

This week I applied for membership for Kapsi internet-käyttäjät ry, who gave me little bit homepage space and a mysql database at my disposal. Now I'll start making my own homepage. Not the first one, but it'll be best one so far.

Someone ones told me that every programmer should make their own content management system. So that's what I'll do. I first thought of making my own framework for it too, but no. I'll use Zend Framework - which I've never used before - in order to lear it, in case i bump into it later on.

Some requirements that I set for the upcoming CMS:
* MVC architect
* Pages must have hierarchy and that hierarchy can be changed
* "Easy to use" - rather abstract requirement, but I'll give a thought to the user interface
* Theme-able - well just see how easy that'll be... I might use Smarty
* Open source - I will put all code on GitHub

We will see how much time I'm going to have on this. Being a working family man one doesn't have too much free time. But everyone should have a hobby, right?