Wednesday, January 21. 2009Installing the XP- Framework
As a follow- up to Introducing the XP- Framework, I finally got around to writing this, I wanted to blog about it for ages.
Installing the XP- Framework on Linux- The easy method First of all, there are a couple of ways to install the XP- Framework, the first one I'll describe in this article is the one I found "feels like installing all other frameworks". I hope to cover more advanced methods in a future post, this is the "quick,simple and straight forward" method.
Some requirements: subversion and a working copy of php5-cli should be installed. In coming articles, you will also need apache, mysql/postgres and some other stuff. Let's get an svn checkout of the Framework. This will allow you to browse through the framework code, something I find useful. For simplicity we'll use a directory called ~/repos. mkdir ~/repos cd ~/repos svn co svn://xp-framework.net/xp xp After this, you'll need to add ~/repos/xp to your php.ini (for your CLI version, Ubuntu stores PHP configuration in /etc/php5/cli/). Edit php.ini or add a file to conf.d/ and modify the include_path variable to contain: [path to]/repos/xp/trunk/skeleton And... there you are! For a first start, that's all you need to do. Let's have a run and test things, change to the ~/repos directory and create a file called "installtest.php" containing the following code. I hope the code comments are enough to explain what is happening. // Initialize the Frameworks core require('lang.base.php'); xp::sapi('cli'); // uses() is used to load XP- Classes, here we load util.DateUtil uses('util.DateUtil'); // Create some new Date- Objects, one from a known // date and one for "now". Please note that "Date" is // a XP- Class loaded by DateUtil! $mybirthday = new Date('1978-07-26'); $now = Date::now(); // Calculate the difference and store in yet another $days = DateUtil::timespanBetween($mybirthday, $now)->getDays(); // Finally, we use normal PHP code for output echo "Hello World, Tom is " . $days . " days old!\n"; Running this with php installtest.php should output something similar to this: Hello World, Tom is 11137 days old! Congratulations, you have successfully installed the Framework! Leave a comment if you run into any trouble, and I'll try to help you fix it. As you can see, you can use XP- Code at any point after the "require('lang.base.php')" by calling the uses() function to load the classes you wish to use. This makes migrating towards the XP- Framework easy, as you can change your code step by step, for example by first using the Date- Classes, then replacing SQL or Logging- Code and so on. There is a lot to explore within the Framework, for example, have a look at the files in ~/repos/xp/trunk/skeleton/util/DateUtil.class.php. This is the file that is actually loaded in the above script by calling uses(). Note that it again contains call to uses() that loads "Date" and "TimeSpan". Please also note that we are initializing a sapi with xp::sapi('cli'). You don't explicitly need this in the beginning, but later on this will show to be a very powerful command, when adding 'strict' for example, try the following code (save it in installtest2.php): // Initialize the Frameworks core require('lang.base.php'); xp::sapi('strict'); $name = "Tom Geiger"; echo $Name . "\n"; So, this Script would normally only echo a Newline, because $Name is NOT the same as $name. When using the 'strict' sapi, though... it will produce a Fatal Error and tell you that $Name is not initialized. It will do so by installing its own error handling routine. Note that this will work on a wide range of scripts, you don't have to actually use this for XP- Code only! Well, this is it for now, more explanations, code snippets and tutorials are to come. Leave comments if you have any questions, found bugs or ran into any trouble. |
CategoriesSyndicate This BlogMisc. Stuff |


And here comes the next part about the XP- Framework. Installing the XP- Framework Toolset on Linux You might wish to read this before if you haven't so far: 1. Introducing the XP- Framework 2. Installing the XP- Framework on Linix The XP- Fr
Tracked: Jan 22, 16:13