2010.1 – The foundations of a new architecture
Développement, english, Security, XNova:Legacies, XNova:Next-Gen 24 mars 2010Today I’m writing an entry for the the developers, an opportunity for me to introduce the new architecture for XNova:Legacies and explain its differences with what may have existed so far on the project. It is worth remembering that the biggest evolutions of the upcoming version comes from a brand new source code written in PHP 5.2, this version becomes though a dependency to make XNova:Legacies work on your system, but don’t worry, this PHP verison exists since 2006 and is therefore widely deployed on PHP hosting providers since a long time.
To return to what we are all here, everything has been redesigned to facilitate simple and rapid modification of the functionnalities of the game without the need of applying neither 1 line of the original source code. Everything is built upon the configuration, if a functionality in the base source code does not work like you wanted : replace it! it is as simple as that.
Accessing to data from the database has never been as simple and safe : get an ID, and load your model, woithout any risk of possible SQL injection. But how do we update, create or delete a database record? Just a line! For the preview 2010-alpha0, the user module will be the first module launched. It is relatively simple and will therefore serve both standard and benchmark for what will follow: 90% of this new source will be shared by an overwhelming majority of functionality or future refactoring.
But all that makes many words and few examples, so here are some previews (may be subject to modification in the final version):
Loading and modifying data of a player from the database:
To load data from a player which, for example, have the ID 8 in the database, the following is enough:
$user = Nova::getModel('user/user')->load(8);
And next? take your newly created variable (here, $user) and use it as like an array, just like you did until now… almost. Yes, because now it is no longer an array, it’s an object. Whath’s the difference? well is that my $ user has now gained virtual accessors and mutators and it even knows how to directly save its data by itself in the database!
$user
->setEmail('player@example.com'); // Updating the field 'email'
->setUsername('Player') // Updating the field 'username'
->save();
Yes, It’s all well and good, but I like it like it was before!
No panic! our $user keeps up appearances and can still be used just like we did before:
echo $user['username'];
But it does not stop with a simple syntax change!
Yes, rather than having functions everywhere, and asking where a particular feature would be, why not combine everything in one place? Well, we do it now! For example: to manage the connection of a player, why not create an automated mechanism?
$user = Nova::getModel('user/user');
if ($user->login($_POST['username'], $_POST['password'])) {
// Our user has submitted the good password, he is now logged in
} else {
// A problem hapened, maybe a passord error?
}
Oh, but how could we retrieve the current user from anywhere now? Simple! Easy! The sessions comes to help us and have also been improved:
$user = Nova::getSingleton('user/session')->getUser();
We now got back our $user, which have logged in in the previous example.
And it goes even further!
Develop and debug your old mods or develop modules for Legacies by enabling debug mode and Deprecation mode and use the source code profiler, simple tools and methods to optimize your code.
In your .htaccess, add the following to enable the two methods mentioned above:
SetEnv DEBUG On
SetEnv DEPRECATION On
The source code profiler is used to count the time taken by a particular treatment, it will return the number of times that it was executed, and various statistics of execution time. It is used with both static methods Nova::profilerStart() and Nova::profilerStop(), respectively, to start a counter and stop t. It both take a single argument that identifies the time counter:
Nova::profilerStart('NOVA.EXAMPLE');
// The treatment to analyze starts from here
for ($i = 0; $i < 200000; $i++) {
echo 'Hello world';
}
// and ends here
Nova::profilerStop('NOVA.EXAMPLE');
Note that the profiler results will only appear in debug mode.

4 avril 2010 à 8 h 49 min
oh. Nice, It Well Be as simple as 123.
Good Work
12 avril 2010 à 15 h 47 min
Simple and complete !
Any Beta or RC version on site ?
What’s the official release date ?
Can’t wait !
^^
12 avril 2010 à 20 h 52 min
This is an alpha release announcement, and therefore it seems obvious that there is no beta or RC
14 avril 2010 à 17 h 44 min
Thought so.. Despite the announcement it’s worth asking ^^
)
( we never know what’s going on in the backstage
8 juillet 2010 à 13 h 51 min
Wow. this is an amazing system.
20 août 2010 à 6 h 32 min
Basing your ORM on Magento is a bad idea. Better to look at the Doctrine project. Using the Magento model you can, and will, end up with multiple copies of the same data object. Each copy will keep the data separate and changes are not shared. Having worked deeply on both Magento and Doctrine code, I would HIGHLY suggest using Doctrine instead.
22 août 2010 à 10 h 56 min
It is not actually using Magento’s source code, just code notation concepts and some parts of the ORM architecture concepts. There will be no EAV-based database. In some way, it is not far from Doctrine notations, but Doctrine is too heavy for this type of application.
25 août 2010 à 0 h 30 min
Then perhaps making a design decision that decouples the loading from the model object is best. This would allow better object tracking.
Instead of:
Nova::getModel(‘user/user’)->load(123);
Use:
Nova::loadModel(‘user/user’, 123);
28 août 2010 à 13 h 47 min
Your exaple is a multiton design, this is not always desired and may expose you to undesirable features, cache and data access will indeed be managed by lower layers.